Inheritance: System.MarshalByRefObject, ILease
 internal void ChangedLeaseTime(Lease lease, DateTime newTime)
 {
     lock (this.leaseToTimeTable)
     {
         this.leaseToTimeTable[lease] = newTime;
     }
 }
 internal void DeleteLease(Lease lease)
 {
     lock (this.leaseToTimeTable)
     {
         this.leaseToTimeTable.Remove(lease);
     }
 }
 internal void ActivateLease(Lease lease)
 {
     lock (this.leaseToTimeTable)
     {
         this.leaseToTimeTable[lease] = lease.leaseTime;
     }
 }
		public void StartTrackingLifetime (ILease lease)
		{
			// Adds this identity to the LeaseManager. 
			// _serverObject must be set.

			if (lease != null && lease.CurrentState == LeaseState.Null) lease = null;

			if (lease != null) 
			{
				if (! (lease is Lease)) lease = new Lease();  // This seems to be MS behavior
				_lease = (Lease) lease;
				LifetimeServices.TrackLifetime (this);
			}
		}
        // Initiates the creation of a lease

        // Creates a sink for invoking a renew on call when an object is created.

        public IMessageSink GetObjectSink(MarshalByRefObject obj,
                                          IMessageSink nextSink)

        {
            bool           fServer;
            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out fServer);

            BCLDebug.Assert(identity != null, "[LifetimeServices.GetObjectSink] identity != null");

            // NOTE: Single Call objects do not have a lease associated with it because they last
            // only for the duration of the call.
            // Singleton objects on the other hand do have leases associated with them and they can
            // be garbage collected.
            if (identity.IsSingleCall())
            {
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease SingleCall", obj, ", NextSink " + nextSink);
                return(nextSink);
            }



            // Create lease. InitializeLifetimeService is a virtual method which can be overridded so that a lease with
            // object specific properties can be created.
            Object leaseObj = obj.InitializeLifetimeService();


            BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, return from InitializeLifetimeService obj ", obj, ", lease ", leaseObj);


            // InitializeLifetimeService can return a lease in one of conditions:
            // 1) the lease has a null state which specifies that no lease is to be created.
            // 2) the lease has an initial state which specifies that InitializeLifeTimeService has created a new lease.
            // 3) the lease has another state which indicates that the lease has already been created and registered.


            if (leaseObj == null)
            {
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease ", obj, ", NextSink " + nextSink);
                return(nextSink);
            }

            if (!(leaseObj is System.Runtime.Remoting.Lifetime.ILease))
            {
                throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_Lifetime_ILeaseReturn"), leaseObj));
            }

            ILease ilease = (ILease)leaseObj;

            if (ilease.InitialLeaseTime.CompareTo(TimeSpan.Zero) <= 0)
            {
                // No lease
                {
                    BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease because InitialLeaseTime is Zero ", obj);
                    if (ilease is System.Runtime.Remoting.Lifetime.Lease)
                    {
                        ((Lease)ilease).Remove();
                    }
                    return(nextSink);
                }
            }


            Lease lease = null;

            lock (identity)
            {
                if (identity.Lease != null)
                {
                    // Lease already exists for object, object is being marsalled again
                    BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, Lease already exists for object ", obj);
                    lease = (Lease)identity.Lease;
                    lease.Renew(lease.InitialLeaseTime);         // Reset initial lease time
                }
                else
                {
                    // New lease
                    if (!(ilease is System.Runtime.Remoting.Lifetime.Lease))
                    {
                        // InitializeLifetimeService created its own ILease object
                        // Need to create a System.Runtime.Remoting.Lease object
                        BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, New Lease, lease not of type Lease  ", obj);
                        lease = (Lease)LifetimeServices.GetLeaseInitial(obj);
                        if (lease.CurrentState == LeaseState.Initial)
                        {
                            lease.InitialLeaseTime   = ilease.InitialLeaseTime;
                            lease.RenewOnCallTime    = ilease.RenewOnCallTime;
                            lease.SponsorshipTimeout = ilease.SponsorshipTimeout;
                        }
                    }
                    else
                    {
                        // An object of Type Lease was created
                        BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, New Lease, lease is type Lease  ", obj);
                        lease = (Lease)ilease;
                    }

                    // Put lease in active state
                    // Creation phase of lease is over, properties can no longer be set on lease.
                    identity.Lease = lease;         // Place lease into identity for object
                    // If the object has been marshaled activate
                    // the lease
                    if (identity.ObjectRef != null)
                    {
                        lease.ActivateLease();
                    }
                }
            }


            if (lease.RenewOnCallTime > TimeSpan.Zero)
            {
                // RenewOnCall create sink
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, lease created ", obj);
                return(new LeaseSink(lease, nextSink));
            }
            else
            {
                // No RenewOnCall so no sink created
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, No RenewOnCall so no sink created ", obj);
                return(nextSink);
            }
        }
Beispiel #6
0
        private void LeaseTimeAnalyzer(object state)
        {
            DateTime utcNow = DateTime.UtcNow;

            lock (this.leaseToTimeTable)
            {
                IDictionaryEnumerator enumerator = this.leaseToTimeTable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    DateTime time2 = (DateTime)enumerator.Value;
                    Lease    key   = (Lease)enumerator.Key;
                    if (time2.CompareTo(utcNow) < 0)
                    {
                        this.tempObjects.Add(key);
                    }
                }
                for (int k = 0; k < this.tempObjects.Count; k++)
                {
                    Lease lease2 = (Lease)this.tempObjects[k];
                    this.leaseToTimeTable.Remove(lease2);
                }
            }
            for (int i = 0; i < this.tempObjects.Count; i++)
            {
                Lease lease3 = (Lease)this.tempObjects[i];
                if (lease3 != null)
                {
                    lease3.LeaseExpired(utcNow);
                }
            }
            this.tempObjects.Clear();
            lock (this.sponsorTable)
            {
                IDictionaryEnumerator enumerator2 = this.sponsorTable.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    object      obj1 = enumerator2.Key;
                    SponsorInfo info = (SponsorInfo)enumerator2.Value;
                    if (info.sponsorWaitTime.CompareTo(utcNow) < 0)
                    {
                        this.tempObjects.Add(info);
                    }
                }
                for (int m = 0; m < this.tempObjects.Count; m++)
                {
                    SponsorInfo info2 = (SponsorInfo)this.tempObjects[m];
                    this.sponsorTable.Remove(info2.sponsorId);
                }
            }
            for (int j = 0; j < this.tempObjects.Count; j++)
            {
                SponsorInfo info3 = (SponsorInfo)this.tempObjects[j];
                if ((info3 != null) && (info3.lease != null))
                {
                    info3.lease.SponsorTimeout(info3.sponsorId);
                    this.tempObjects[j] = null;
                }
            }
            this.tempObjects.Clear();
            this.leaseTimer.Change((int)this.pollTime.TotalMilliseconds, -1);
        }
Beispiel #7
0
        public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
        {
            bool           fServer;
            ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out fServer);

            if (serverIdentity.IsSingleCall())
            {
                return(nextSink);
            }
            object obj1 = obj.InitializeLifetimeService();

            if (obj1 == null)
            {
                return(nextSink);
            }
            if (!(obj1 is ILease))
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_Lifetime_ILeaseReturn", obj1));
            }
            ILease lease1 = (ILease)obj1;

            if (lease1.InitialLeaseTime.CompareTo(TimeSpan.Zero) <= 0)
            {
                if (lease1 is Lease)
                {
                    ((Lease)lease1).Remove();
                }
                return(nextSink);
            }
            Lease lease2 = (Lease)null;

            lock (serverIdentity)
            {
                if (serverIdentity.Lease != null)
                {
                    lease2 = serverIdentity.Lease;
                    Lease    temp_62 = lease2;
                    TimeSpan temp_63 = temp_62.InitialLeaseTime;
                    temp_62.Renew(temp_63);
                }
                else
                {
                    if (!(lease1 is Lease))
                    {
                        lease2 = (Lease)LifetimeServices.GetLeaseInitial(obj);
                        if (lease2.CurrentState == LeaseState.Initial)
                        {
                            lease2.InitialLeaseTime   = lease1.InitialLeaseTime;
                            lease2.RenewOnCallTime    = lease1.RenewOnCallTime;
                            lease2.SponsorshipTimeout = lease1.SponsorshipTimeout;
                        }
                    }
                    else
                    {
                        lease2 = (Lease)lease1;
                    }
                    serverIdentity.Lease = lease2;
                    if (serverIdentity.ObjectRef != null)
                    {
                        lease2.ActivateLease();
                    }
                }
            }
            if (lease2.RenewOnCallTime > TimeSpan.Zero)
            {
                return((IMessageSink) new LeaseSink(lease2, nextSink));
            }
            return(nextSink);
        }
Beispiel #8
0
 internal void ActivateLease(Lease lease)
 {
     BCLDebug.Trace("REMOTE","LeaseManager AddLease ",lease.id," ",lease.managedObject);
     lock(leaseToTimeTable)
     {
         leaseToTimeTable[lease] = lease.leaseTime;
     }
 }       
Beispiel #9
0
 internal SponsorInfo(Lease lease, Object sponsorId, DateTime sponsorWaitTime)
 {
     this.lease = lease;
     this.sponsorId = sponsorId;
     this.sponsorWaitTime = sponsorWaitTime;
 }
Beispiel #10
0
 internal void DumpLeases(Lease[] leases)
 {
     for (int i=0; i<leases.Length; i++)
     {
         BCLDebug.Trace("REMOTE","LeaseManager DumpLease ",leases[i].managedObject);                                         
     }
 }
Beispiel #11
0
 internal void DeleteLease(Lease lease)
 {
     BCLDebug.Trace("REMOTE","LeaseManager DeleteLease ",lease.id);
     lock(leaseToTimeTable)
     {
         leaseToTimeTable.Remove(lease);
     }
 }
Beispiel #12
0
 public LeaseSink(Lease lease, IMessageSink nextSink)
 {
     this.lease = lease;
     this.nextSink = nextSink;
 }
 internal void DumpLeases(Lease[] leases)
 {
     for (int i = 0; i < leases.Length; i++)
     {
     }
 }
 internal void RegisterSponsorCall(Lease lease, object sponsorId, TimeSpan sponsorshipTimeOut)
 {
     lock (this.sponsorTable)
     {
         DateTime sponsorWaitTime = DateTime.UtcNow.Add(sponsorshipTimeOut);
         this.sponsorTable[sponsorId] = new SponsorInfo(lease, sponsorId, sponsorWaitTime);
     }
 }
        public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
        {
            bool           flag;
            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out flag);

            if (!identity.IsSingleCall())
            {
                object obj2 = obj.InitializeLifetimeService();
                if (obj2 == null)
                {
                    return(nextSink);
                }
                if (!(obj2 is ILease))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_Lifetime_ILeaseReturn", new object[] { obj2 }));
                }
                ILease lease = (ILease)obj2;
                if (lease.InitialLeaseTime.CompareTo(TimeSpan.Zero) <= 0)
                {
                    if (lease is Lease)
                    {
                        ((Lease)lease).Remove();
                    }
                    return(nextSink);
                }
                Lease leaseInitial = null;
                lock (identity)
                {
                    if (identity.Lease != null)
                    {
                        leaseInitial = identity.Lease;
                        leaseInitial.Renew(leaseInitial.InitialLeaseTime);
                    }
                    else
                    {
                        if (lease is Lease)
                        {
                            leaseInitial = (Lease)lease;
                        }
                        else
                        {
                            leaseInitial = (Lease)LifetimeServices.GetLeaseInitial(obj);
                            if (leaseInitial.CurrentState == LeaseState.Initial)
                            {
                                leaseInitial.InitialLeaseTime   = lease.InitialLeaseTime;
                                leaseInitial.RenewOnCallTime    = lease.RenewOnCallTime;
                                leaseInitial.SponsorshipTimeout = lease.SponsorshipTimeout;
                            }
                        }
                        identity.Lease = leaseInitial;
                        if (identity.ObjectRef != null)
                        {
                            leaseInitial.ActivateLease();
                        }
                    }
                }
                if (leaseInitial.RenewOnCallTime > TimeSpan.Zero)
                {
                    return(new LeaseSink(leaseInitial, nextSink));
                }
            }
            return(nextSink);
        }
Beispiel #16
0
 internal SponsorInfo(Lease lease, Object sponsorId, DateTime sponsorWaitTime)
 {
     this.lease           = lease;
     this.sponsorId       = sponsorId;
     this.sponsorWaitTime = sponsorWaitTime;
 }
Beispiel #17
0
        // Thread Loop
        private void LeaseTimeAnalyzer(Object state)
        {
            //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer Entry ",state);

            // Find expired leases
            DateTime now = DateTime.Now;

            lock (leaseToTimeTable)
            {
                IDictionaryEnumerator e = leaseToTimeTable.GetEnumerator();

                while (e.MoveNext())
                {
                    DateTime time  = (DateTime)e.Value;
                    Lease    lease = (Lease)e.Key;
                    //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer lease ",lease.id, " lease time ", time, " now ", now);
                    if (time.CompareTo(now) < 0)
                    {
                        // lease expired
                        tempObjects.Add(lease);
                    }
                }
                for (int i = 0; i < tempObjects.Count; i++)
                {
                    Lease lease = (Lease)tempObjects[i];
                    //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer lease Expired remove from leaseToTimeTable ",lease.id);
                    leaseToTimeTable.Remove(lease);
                }
            }

            // Need to run this without lock on leaseToTimeTable to avoid deadlock
            for (int i = 0; i < tempObjects.Count; i++)
            {
                Lease lease = (Lease)tempObjects[i];
                //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer lease Expired ",lease.id);
                if (lease != null) // Lease could be deleted if there is more then one reference to the lease
                {
                    lease.LeaseExpired(now);
                }
            }

            tempObjects.Clear();

            lock (sponsorTable)
            {
                IDictionaryEnumerator e = sponsorTable.GetEnumerator();

                while (e.MoveNext())
                {
                    // Check for SponshipTimeOuts
                    Object      sponsorId   = e.Key;
                    SponsorInfo sponsorInfo = (SponsorInfo)e.Value;
                    //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer sponsor time ", sponsorInfo.sponsorWaitTime, " now ", now);
                    if (sponsorInfo.sponsorWaitTime.CompareTo(now) < 0)
                    {
                        // Sponsortimeout expired expired
                        tempObjects.Add(sponsorInfo);
                    }
                }

                // Process the timed out sponsors
                for (int i = 0; i < tempObjects.Count; i++)
                {
                    SponsorInfo sponsorInfo = (SponsorInfo)tempObjects[i];
                    //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer sponsor Expired remove from spansorTable", sponsorInfo.sponsorId);
                    sponsorTable.Remove(sponsorInfo.sponsorId);
                }
            }

            // Process the timed out sponsors
            // Need to run this without lock on sponsorTable to avoid deadlock
            for (int i = 0; i < tempObjects.Count; i++)
            {
                SponsorInfo sponsorInfo = (SponsorInfo)tempObjects[i];
                //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer sponsor Expired ", sponsorInfo.sponsorId);
                if (sponsorInfo != null && sponsorInfo.lease != null)
                {
                    sponsorInfo.lease.SponsorTimeout(sponsorInfo.sponsorId);
                }
            }

            tempObjects.Clear();
            leaseTimer.Change((int)pollTime.TotalMilliseconds, Timeout.Infinite);

            //BCLDebug.Trace("REMOTE","LeaseManager LeaseTimeAnalyzer Exit");
        }
 internal SponsorStateInfo(TimeSpan renewalTime, Lease.SponsorState sponsorState)
 {
     this.renewalTime = renewalTime;
     this.sponsorState = sponsorState;
 }
Beispiel #19
0
 // We won't get all the leases, only the ones which haven't expired.
 internal Lease[] GetLeases()
 {
     Lease[] leases = new Lease[leaseToTimeTable.Count];         
     lock(leaseToTimeTable)
     {
         IDictionaryEnumerator e = leaseToTimeTable.GetEnumerator();
         for (int i=0; e.MoveNext(); i++)
         {
             leases[i] = (Lease)e.Key;
         }
     }
     DumpLeases(leases);                         
     return leases;
 }
Beispiel #20
0
 internal void ChangedLeaseTime(Lease lease, DateTime newTime)
 {
     lock (this.leaseToTimeTable)
         this.leaseToTimeTable[(object)lease] = (object)newTime;
 }
Beispiel #21
0
 internal void ChangedLeaseTime(Lease lease, DateTime newTime)
 {
     BCLDebug.Trace("REMOTE","LeaseManager ChangedLeaseTime ",lease.id," ",lease.managedObject," newTime ",newTime," currentTime ", DateTime.Now);
     lock(leaseToTimeTable)
     {
         leaseToTimeTable[lease] = newTime;
     }
 }
Beispiel #22
0
 internal void ActivateLease(Lease lease)
 {
     lock (this.leaseToTimeTable)
         this.leaseToTimeTable[(object)lease] = (object)lease.leaseTime;
 }
Beispiel #23
0
        internal void RegisterSponsorCall(Lease lease, Object sponsorId, TimeSpan sponsorshipTimeOut)
        {
            BCLDebug.Trace("REMOTE","LeaseManager RegisterSponsorCall Lease ",lease," sponsorshipTimeOut ",sponsorshipTimeOut);

            lock(sponsorTable)
            {
                DateTime sponsorWaitTime = DateTime.Now.Add(sponsorshipTimeOut);
                sponsorTable[sponsorId] = new SponsorInfo(lease, sponsorId, sponsorWaitTime);
            }
        }
Beispiel #24
0
 internal void DeleteLease(Lease lease)
 {
     lock (this.leaseToTimeTable)
         this.leaseToTimeTable.Remove((object)lease);
 }
Beispiel #25
0
 public LeaseSink(Lease lease, IMessageSink nextSink)
 {
     this.lease    = lease;
     this.nextSink = nextSink;
 }
        private void LeaseTimeAnalyzer(object state)
        {
            DateTime  utcNow = DateTime.UtcNow;
            Hashtable obj    = this.leaseToTimeTable;

            lock (obj)
            {
                IDictionaryEnumerator enumerator = this.leaseToTimeTable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    DateTime dateTime = (DateTime)enumerator.Value;
                    Lease    value    = (Lease)enumerator.Key;
                    if (dateTime.CompareTo(utcNow) < 0)
                    {
                        this.tempObjects.Add(value);
                    }
                }
                for (int i = 0; i < this.tempObjects.Count; i++)
                {
                    Lease key = (Lease)this.tempObjects[i];
                    this.leaseToTimeTable.Remove(key);
                }
            }
            for (int j = 0; j < this.tempObjects.Count; j++)
            {
                Lease lease = (Lease)this.tempObjects[j];
                if (lease != null)
                {
                    lease.LeaseExpired(utcNow);
                }
            }
            this.tempObjects.Clear();
            Hashtable obj2 = this.sponsorTable;

            lock (obj2)
            {
                IDictionaryEnumerator enumerator2 = this.sponsorTable.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    object key2 = enumerator2.Key;
                    LeaseManager.SponsorInfo sponsorInfo = (LeaseManager.SponsorInfo)enumerator2.Value;
                    if (sponsorInfo.sponsorWaitTime.CompareTo(utcNow) < 0)
                    {
                        this.tempObjects.Add(sponsorInfo);
                    }
                }
                for (int k = 0; k < this.tempObjects.Count; k++)
                {
                    LeaseManager.SponsorInfo sponsorInfo2 = (LeaseManager.SponsorInfo) this.tempObjects[k];
                    this.sponsorTable.Remove(sponsorInfo2.sponsorId);
                }
            }
            for (int l = 0; l < this.tempObjects.Count; l++)
            {
                LeaseManager.SponsorInfo sponsorInfo3 = (LeaseManager.SponsorInfo) this.tempObjects[l];
                if (sponsorInfo3 != null && sponsorInfo3.lease != null)
                {
                    sponsorInfo3.lease.SponsorTimeout(sponsorInfo3.sponsorId);
                    this.tempObjects[l] = null;
                }
            }
            this.tempObjects.Clear();
            this.leaseTimer.Change((int)this.pollTime.TotalMilliseconds, -1);
        }