GetLifetimeService() private method

private GetLifetimeService ( ) : Object
return Object
 public bool Register(MarshalByRefObject obj)
 {
     ILease lifetimeService = (ILease) obj.GetLifetimeService();
     if (lifetimeService == null)
     {
         return false;
     }
     lifetimeService.Register(this);
     lock (this.sponsorTable)
     {
         this.sponsorTable[obj] = lifetimeService;
     }
     return true;
 }
Example #2
0
        [System.Security.SecurityCritical]  // auto-generated
        public bool Register(MarshalByRefObject obj) 
        {
            BCLDebug.Trace("REMOTE", "ClientSponsor Register "+obj);
            ILease lease = (ILease)obj.GetLifetimeService();
            if (lease == null) 
                return false;
 
            lease.Register(this); 
            lock(sponsorTable)
            { 
                sponsorTable[obj] = lease;
            }
            return true;
        } 
Example #3
0
 static int GetLifetimeService(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.MarshalByRefObject obj = (System.MarshalByRefObject)ToLua.CheckObject(L, 1, typeof(System.MarshalByRefObject));
         object o = obj.GetLifetimeService();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 public void Register(MarshalByRefObject obj)
 {
     Func<KeyValuePair<ILease, WeakReference>, bool> predicate = null;
     if (obj == null)
     {
         throw new ArgumentNullException();
     }
     ILease Lease = (ILease) obj.GetLifetimeService();
     lock (this.LeaseObjectList)
     {
         if (predicate == null)
         {
             predicate = delegate (KeyValuePair<ILease, WeakReference> x) {
                 return object.ReferenceEquals(x, Lease);
             };
         }
         if (!this.LeaseObjectList.Any<KeyValuePair<ILease, WeakReference>>(predicate))
         {
             this.LeaseObjectList.AddFirst(new KeyValuePair<ILease, WeakReference>(Lease, new WeakReference(obj)));
             Lease.Register(this);
         }
     }
 }
Example #5
0
        [System.Security.SecurityCritical]  // auto-generated 
        internal static ObjRef MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, bool updateChannelData) 
        {
            BCLDebug.Trace("REMOTE", "Entered Marshal for URI" +  ObjURI + "\n"); 

            if (null == Obj)
                return null;
 
            ObjRef objectRef = null;
            Identity idObj = null; 
 
            idObj = GetOrCreateIdentity(Obj, ObjURI);
            if (RequestedType != null) 
            {
                ServerIdentity srvIdObj = idObj as ServerIdentity;
                if (srvIdObj != null)
                { 
                    // If more than one thread, marshals with different types the
                    // results would be non-deterministic, so we just let the last 
                    // call win (also allows type to be marshalled a second time 
                    // to change the exposed type).
                    srvIdObj.ServerType = RequestedType; 
                    srvIdObj.MarshaledAsSpecificType = true;
                }
            }
 
            // If there is no objref associated with the identity then go ahead
            // and create one and stick it back into the identity object 
 
#if _DEBUG
            idObj.AssertValid(); 
#endif

            Contract.Assert(null != idObj.ObjURI,"null != idObj.ObjURI");
 
            Message.DebugOut("RemotingServices::Marshal: trying to create objref\n");
 
            // We should definitely have an identity object at this point of time 
            Contract.Assert(null != idObj,"null != idObj");
 
            // Extract the objref from the identity
            objectRef = idObj.ObjectRef;
            if (null == objectRef)
            { 
                Message.DebugOut("RemotingServices::Marshal: really trying to create objref\n");
 
                if (IsTransparentProxy(Obj)) 
                {
                    RealProxy realProxy = GetRealProxy(Obj); 
                    Contract.Assert(null != realProxy,"null != realProxy");
                    objectRef = realProxy.CreateObjRef(RequestedType);
                }
                else 
                {
                    // Create a new object ref which contains the default information 
                    objectRef = Obj.CreateObjRef(RequestedType); 
                }
 
                Message.DebugOut("RemotingServices::Marshal: created objref\n");
                if (idObj == null || objectRef == null)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMarshalByRefObject"), "Obj");
 
                // The ObjectRef property setter will take care of ----s
                objectRef = idObj.RaceSetObjRef(objectRef); 
            } 

 
            // Retime lease on every marshal on the server side
            // and extend lease on every marshal on the client side <EMAIL>- GopalK</EMAIL>
            ServerIdentity srvId = idObj as ServerIdentity;
            if (srvId != null) 
            {
                // Ensure that the lease is started soon as the object is 
                // marshaled. 
                MarshalByRefObject obj = null;
                // This call forces creation of the lifetime lease sink. 
                srvId.GetServerObjectChain(out obj);

                // Server side ... object being marshaled => give it another
                // full lease 
                Lease lease = idObj.Lease;
                if (lease != null) 
                { 
                    // We always make Identity reference our own Lease though
                    // the actual object implements its own ILease object. 
                    // This seems completely broken. Further, ILease interface
                    // should have the activate method.  <EMAIL>- GopalK</EMAIL>

                    // This lock ensures coordination with the lifetime service 
                    // which might have decided to Disconnect the object about
                    // the same time as it is being marshaled 
                    lock (lease) 
                    {
                        if (lease.CurrentState == LeaseState.Expired) 
                        {
                            // Lease.Renew is a no-op if LeaseState==Expired
                            // So we do a full ActivateLease
                            lease.ActivateLease(); 
                        }
                        else 
                        { 
                            // Lease is still around. Just increase the time
                            lease.RenewInternal(idObj.Lease.InitialLeaseTime); 
                        }
                    }
                }
 
                // Every marshal should also ensure that the channel data
                // being carried in the objRef reflects the latest data from 
                // regisetered channels 
                // <
                if (updateChannelData && objectRef.ChannelInfo != null) 
                {
                    // Create the channel info
                    Object[] channelData = ChannelServices.CurrentChannelData;
                    // Make sure the channelInfo only has x-appdomain data since the objref is agile while other 
                    // channelData might not be and regardless this data is useless for an appdomain proxy
                    if (!(Obj is AppDomain)) 
                        objectRef.ChannelInfo.ChannelData = channelData; 
                    else
                    { 
                        int channelDataLength = channelData.Length;
                        Object[] newChannelData = new Object[channelDataLength];
                        // Clone the data so that we dont [....] the current appdomain data which is stored
                        // as a static 
                        Array.Copy(channelData, newChannelData, channelDataLength);
                        for (int i = 0; i < channelDataLength; i++) 
                        { 
                            if (!(newChannelData[i] is CrossAppDomainData))
                                newChannelData[i] = null; 
                        }
                        objectRef.ChannelInfo.ChannelData = newChannelData;
                    }
                } 
            }
            else 
            { 
#if false
                /* 



*/ 
                ILease lease = idObj.Lease;
                if (lease == null) 
                { 
                    lease = (ILease)Obj.GetLifetimeService();
                } 
                if (lease != null)
                {
                    lease.Renew(lease.RenewOnCallTime);
                } 
#endif
            } 
 
            // Notify TrackingServices that an object has been marshaled
            // NOTE: This call also keeps the object alive otherwise GC 
            // can report it as dead anytime inside this call when it thinks
            // that the object will no longer be referenced, either inside
            // this call or outside.
            /* < 
*/
 
            TrackingServices.MarshaledObject(Obj, objectRef); 
            return objectRef;
        } 
Example #6
0
 [System.Security.SecuritySafeCritical]  // auto-generated 
 public static Object GetLifetimeService(MarshalByRefObject obj)
 { 
     if(null != obj)
     {
         return obj.GetLifetimeService();
     } 
     else
     { 
         return null; 
     }
 } 
Example #7
0
		public void Unregister (MarshalByRefObject obj)
		{
			if (!registered_objects.ContainsKey (obj)) return;
			ILease lease = obj.GetLifetimeService () as ILease;
			lease.Unregister (this);
			registered_objects.Remove (obj);
		}
Example #8
0
		public bool Register (MarshalByRefObject obj)
		{
			if (registered_objects.ContainsKey (obj)) return false;
			ILease lease = obj.GetLifetimeService () as ILease;
			if (lease == null) return false;
			lease.Register (this);
			registered_objects.Add (obj,obj);
			return true;
		}
 public static object GetLifetimeService(MarshalByRefObject obj)
 {
     if (obj != null)
     {
         return obj.GetLifetimeService();
     }
     return null;
 }
Example #10
0
 internal void RegisterLifetimeService(MarshalByRefObject obj)
 {
     ILease lease = (ILease)obj.GetLifetimeService();
     if (lease != null)
         lease.Register(RemotingClientSponsor);
 }
 public bool Unregister(MarshalByRefObject obj)
 {
     Predicate<KeyValuePair<ILease, WeakReference>> match = null;
     if (obj == null)
     {
         throw new ArgumentNullException();
     }
     ILease Lease = (ILease) obj.GetLifetimeService();
     lock (this.LeaseObjectList)
     {
         if (match == null)
         {
             match = delegate (KeyValuePair<ILease, WeakReference> x) {
                 return object.ReferenceEquals(x, Lease);
             };
         }
         if (this.LeaseObjectList.RemoveAll(match) > 0)
         {
             Lease.Unregister(this);
             return true;
         }
     }
     return false;
 }