[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Life
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Lifetime ClientSponsor.cs, 1.2, 1.3 LifetimeServices.cs, 1.2, 1.3 |
Date: |
Thu, 11 Sep 2003 21:01:07 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Lifetime
In directory
subversions:/tmp/cvs-serv15202/runtime/System/Runtime/Remoting/Lifetime
Modified Files:
ClientSponsor.cs LifetimeServices.cs
Log Message:
Missing functionality in "System.Runtime.Remoting".
Index: ClientSponsor.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Lifetime/ClientSponsor.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ClientSponsor.cs 23 Apr 2003 05:39:50 -0000 1.2
--- ClientSponsor.cs 12 Sep 2003 01:01:05 -0000 1.3
***************
*** 25,31 ****
--- 25,34 ----
#if CONFIG_REMOTING
+ using System.Collections;
+
public class ClientSponsor : MarshalByRefObject, ISponsor
{
// Internal state.
+ private Hashtable sponsoredObjects;
private TimeSpan renewalTime;
***************
*** 34,37 ****
--- 37,41 ----
public ClientSponsor(TimeSpan renewalTime)
{
+ this.sponsoredObjects = new Hashtable();
this.renewalTime = renewalTime;
}
***************
*** 57,64 ****
// Empty the registration list.
- [TODO]
public void Close()
{
! // TODO
}
--- 61,75 ----
// Empty the registration list.
public void Close()
{
! lock(this)
! {
! IDictionaryEnumerator e =
sponsoredObjects.GetEnumerator();
! while(e.MoveNext())
! {
!
((ILease)(e.Value)).Unregister(this);
! }
! sponsoredObjects.Clear();
! }
}
***************
*** 71,94 ****
// Register an object for sponsorship.
- [TODO]
public bool Register(MarshalByRefObject obj)
{
! // TODO
! return false;
}
// Request renewal of a lease.
- [TODO]
public TimeSpan Renewal(ILease lease)
{
! // TODO
! return new TimeSpan(0);
}
// Unregister an object from the sponsorship list.
- [TODO]
public void Unregister(MarshalByRefObject obj)
{
! // TODO
}
--- 82,125 ----
// Register an object for sponsorship.
public bool Register(MarshalByRefObject obj)
{
! // If there is no lease on the object, then
bail out.
! ILease lease =
(ILease)(obj.GetLifetimeService());
! if(lease == null)
! {
! return false;
! }
!
! // Inform the lease about the registered
sponsor.
! lease.Register(this);
!
! // Add the lease to the sponsor table.
! lock(this)
! {
! sponsoredObjects[obj] = lease;
! }
! return true;
}
// Request renewal of a lease.
public TimeSpan Renewal(ILease lease)
{
! return renewalTime;
}
// Unregister an object from the sponsorship list.
public void Unregister(MarshalByRefObject obj)
{
! ILease lease;
! lock(this)
! {
! ILease lease =
(ILease)(sponsoredObjects[obj]);
! if(lease == null)
! {
! return;
! }
! sponsoredObjects.Remove(obj);
! }
! lease.Unregister(this);
}
Index: LifetimeServices.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Lifetime/LifetimeServices.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LifetimeServices.cs 23 Aug 2003 00:35:59 -0000 1.2
--- LifetimeServices.cs 12 Sep 2003 01:01:05 -0000 1.3
***************
*** 26,39 ****
using System.Security.Permissions;
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.Infrastructure)]
public sealed class LifetimeServices
{
// Internal state.
! private static TimeSpan leaseManagerPollTime;
! private static TimeSpan leaseTime;
! private static TimeSpan renewOnCallTime;
! private static TimeSpan sponsorshipTimeout;
// Get or set the global lease manager poll time setting.
--- 26,42 ----
using System.Security.Permissions;
+ using System.Collections;
+ using System.Threading;
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.Infrastructure)]
+ [TODO]
public sealed class LifetimeServices
{
// Internal state.
! private static TimeSpan leaseManagerPollTime = new TimeSpan(0, 10, 0);
! private static TimeSpan leaseTime = new TimeSpan(0, 5, 0);
! private static TimeSpan renewOnCallTime = new TimeSpan(0, 2, 0);
! private static TimeSpan sponsorshipTimeout = new TimeSpan(0, 2, 0);
// Get or set the global lease manager poll time setting.
***************
*** 46,50 ****
set
{
! leaseManagerPollTime = value;
}
}
--- 49,61 ----
set
{
! lock(typeof(LifetimeServices))
! {
! leaseManagerPollTime = value;
! AppDomain current =
AppDomain.CurrentDomain;
! if(current.lifetimeManager !=
null)
! {
!
current.lifetimeManager.PollTime = value;
! }
! }
}
}
***************
*** 89,107 ****
}
// Get the default lifetime service object for a marshal-by-ref object.
- [TODO]
internal static Object GetLifetimeService(MarshalByRefObject obj)
{
! // TODO
! return null;
}
// Initialize a lifetime service object for a marshal-by-ref object.
- [TODO]
internal static Object InitializeLifetimeService(MarshalByRefObject obj)
{
! // TODO
! return null;
}
}; // class LifetimeServices
--- 100,305 ----
}
+ // Get the lifetime manager for the current application domain.
+ private static Manager GetLifetimeManager()
+ {
+ lock(typeof(LifetimeServices))
+ {
+ AppDomain current =
AppDomain.CurrentDomain;
+ if(current.lifetimeManager == null)
+ {
+ current.lifetimeManager = new
Manager
+ (leaseManagerPollTime);
+ }
+ return current.lifetimeManager;
+ }
+ }
+
// Get the default lifetime service object for a marshal-by-ref object.
internal static Object GetLifetimeService(MarshalByRefObject obj)
{
! return
GetLifetimeManager().GetLeaseForObject(obj);
}
// Initialize a lifetime service object for a marshal-by-ref object.
internal static Object InitializeLifetimeService(MarshalByRefObject obj)
{
! Manager manager = GetLifetimeManager();
! ILease lease = manager.GetLeaseForObject(obj);
! if(lease != null)
! {
! return lease;
! }
! return new Lease(obj, LeaseTime,
RenewOnCallTime,
!
SponsorshipTimeout);
}
+
+ // Lifetime lease manager for an application domain.
+ internal class Manager
+ {
+ // Internal state.
+ private TimeSpan pollTime;
+ private Hashtable leases;
+ private Timer timer;
+
+ // Constructor.
+ public Manager(TimeSpan pollTime)
+ {
+ this.pollTime = pollTime;
+ this.leases = new Hashtable();
+ this.timer = new Timer
+ (new TimerCallback(Callback),
null,
+ pollTime, pollTime);
+ }
+
+ // Get or set the poll time.
+ public TimeSpan PollTime
+ {
+ get
+ {
+ lock(this)
+ {
+ return pollTime;
+ }
+ }
+ set
+ {
+ lock(this)
+ {
+ pollTime = value;
+ timer.Change(pollTime,
pollTime);
+ }
+ }
+ }
+
+ // Get an active lease for an object.
+ public ILease GetLeaseForObject(MarshalByRefObject obj)
+ {
+ // TODO
+ return null;
+ }
+
+ // Callback for processing lease timeouts.
+ private void Callback(Object state)
+ {
+ // TODO
+ }
+
+ }; // class Manager
+
+ // Lease control object.
+ private class Lease : MarshalByRefObject, ILease
+ {
+ // Internal state.
+ private MarshalByRefObject obj;
+ private DateTime leaseTimeout;
+ private TimeSpan initialLeaseTime;
+ private TimeSpan renewOnCallTime;
+ private TimeSpan sponsorshipTimeout;
+ private LeaseState state;
+
+ // Constructor.
+ public Lease(MarshalByRefObject obj, TimeSpan leaseTime,
+ TimeSpan renewOnCallTime, TimeSpan
sponsorshipTimeout)
+ {
+ this.obj = obj;
+ this.initialLeaseTime = leaseTime;
+ this.renewOnCallTime = renewOnCallTime;
+ this.sponsorshipTimeout =
sponsorshipTimeout;
+ this.state = LeaseState.Initial;
+ }
+
+ // Cannot have a lease for a lease!
+ public override Object InitializeLifetimeService()
+ {
+ return null;
+ }
+
+ // Implement the ILease interface.
+ public TimeSpan CurrentLeaseTime
+ {
+ get
+ {
+ return leaseTimeout -
DateTime.UtcNow;
+ }
+ }
+ public LeaseState CurrentState
+ {
+ get
+ {
+ return state;
+ }
+ }
+ public TimeSpan InitialLeaseTime
+ {
+ get
+ {
+ return initialLeaseTime;
+ }
+ set
+ {
+ if(state != LeaseState.Initial)
+ {
+ throw new
RemotingException
+
(_("Invalid_ModifyLease"));
+ }
+ initialLeaseTime = value;
+ if(value <= TimeSpan.Zero)
+ {
+ // Disable the lease.
+ state = LeaseState.Null;
+ }
+ }
+ }
+ public TimeSpan RenewOnCallTime
+ {
+ get
+ {
+ return renewOnCallTime;
+ }
+ set
+ {
+ if(state != LeaseState.Initial)
+ {
+ throw new
RemotingException
+
(_("Invalid_ModifyLease"));
+ }
+ renewOnCallTime = value;
+ }
+ }
+ public TimeSpan SponsorshipTimeout
+ {
+ get
+ {
+ return renewOnCallTime;
+ }
+ set
+ {
+ if(state != LeaseState.Initial)
+ {
+ throw new
RemotingException
+
(_("Invalid_ModifyLease"));
+ }
+ renewOnCallTime = value;
+ }
+ }
+ public void Register(ISponsor obj)
+ {
+ Register(obj, new TimeSpan(0));
+ }
+ public void Register(ISponsor obj, TimeSpan renewalTime)
+ {
+ // TODO
+ }
+ public TimeSpan Renew(TimeSpan renewalTime)
+ {
+ // TODO
+ return renewalTime;
+ }
+ public void Unregister(ISponsor obj)
+ {
+ // TODO
+ }
+
+ }; // class Lease
}; // class LifetimeServices
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Lifetime ClientSponsor.cs, 1.2, 1.3 LifetimeServices.cs, 1.2, 1.3,
Rhys Weatherley <address@hidden> <=