[System.Security.SecurityCritical] // auto-generated_required public override Object InitializeLifetimeService() { BCLDebug.Trace("REMOTE", "ObjectHandle.InitializeLifetimeService"); // // If the wrapped object has implemented InitializeLifetimeService to return null, // we don't want to go to the base class (which will result in a lease being // requested from the MarshalByRefObject, which starts up the LeaseManager, // which starts up the ThreadPool, adding three threads to the process. // We check if the wrapped object is a MarshalByRef object, and call InitializeLifetimeServices on it // and if it returns null, we return null. Otherwise we fall back to the old behavior. // MarshalByRefObject mbr = WrappedObject as MarshalByRefObject; if (mbr != null) { Object o = mbr.InitializeLifetimeService(); if (o == null) { return(null); } } ILease lease = (ILease)base.InitializeLifetimeService(); return(lease); }
public new virtual object InitializeLifetimeService() { createInstance(); object InitializeLifetimeService = BaseMashalByRef.InitializeLifetimeService(); tr.Dispose(); return(InitializeLifetimeService); }
internal static ClientActivatedIdentity CreateClientActivatedServerIdentity(MarshalByRefObject realObject, Type objectType, string objectUri) { ClientActivatedIdentity identity = new ClientActivatedIdentity(objectUri, objectType); identity.AttachServerObject(realObject, Context.DefaultContext); RegisterServerIdentity(identity); identity.StartTrackingLifetime((ILease)realObject.InitializeLifetimeService()); return(identity); }
public override object InitializeLifetimeService() { MarshalByRefObject wrappedObject = this.WrappedObject as MarshalByRefObject; if ((wrappedObject != null) && (wrappedObject.InitializeLifetimeService() == null)) { return(null); } return((ILease)base.InitializeLifetimeService()); }
public override object InitializeLifetimeService() { MarshalByRefObject marshalByRefObject = this.WrappedObject as MarshalByRefObject; if (marshalByRefObject != null && marshalByRefObject.InitializeLifetimeService() == null) { return((object)null); } return((object)(ILease)base.InitializeLifetimeService()); }
public void CreateRemoteObjectWithLeaseInfo() { RemoteObjectFactory factory = new RemoteObjectFactory(); factory.Target = new SimpleCounter(); factory.Infinite = false; factory.InitialLeaseTime = TimeSpan.FromMilliseconds(10000); factory.RenewOnCallTime = TimeSpan.FromMilliseconds(1000); factory.SponsorshipTimeout = TimeSpan.FromMilliseconds(100); MarshalByRefObject remoteObject = (MarshalByRefObject)factory.GetObject(); ILease lease = (ILease)remoteObject.InitializeLifetimeService(); Assert.AreEqual(TimeSpan.FromMilliseconds(10000), lease.InitialLeaseTime, "InitialLeaseTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(1000), lease.RenewOnCallTime, "RenewOnCallTime"); Assert.AreEqual(TimeSpan.FromMilliseconds(100), lease.SponsorshipTimeout, "SponsorshipTimeout"); }
public MarshalByRefObject GetServerObject() { if (this._serverObject != null) { return(this._serverObject); } lock (this) { if (this._serverObject == null) { MarshalByRefObject marshalByRefObject = (MarshalByRefObject)Activator.CreateInstance(this._objectType, true); base.AttachServerObject(marshalByRefObject, Context.DefaultContext); base.StartTrackingLifetime((ILease)marshalByRefObject.InitializeLifetimeService()); } } return(this._serverObject); }
public MarshalByRefObject GetServerObject() { if (_serverObject != null) { return(_serverObject); } lock (this) { if (_serverObject == null) { MarshalByRefObject server = (MarshalByRefObject)Activator.CreateInstance(_objectType, true); AttachServerObject(server, Context.DefaultContext); StartTrackingLifetime((ILease)server.InitializeLifetimeService()); } } return(_serverObject); }
public static ObjRef Marshal(MarshalByRefObject Obj, string ObjURI, Type RequestedType) { if (IsTransparentProxy(Obj)) { RealProxy proxy = RemotingServices.GetRealProxy(Obj); Identity identity = proxy.ObjectIdentity; if (identity != null) { if (proxy.GetProxiedType().IsContextful&& !identity.IsConnected) { // Unregistered local contextbound object. Register now. ClientActivatedIdentity cboundIdentity = (ClientActivatedIdentity)identity; if (ObjURI == null) { ObjURI = NewUri(); } cboundIdentity.ObjectUri = ObjURI; RegisterServerIdentity(cboundIdentity); cboundIdentity.StartTrackingLifetime((ILease)Obj.InitializeLifetimeService()); return(cboundIdentity.CreateObjRef(RequestedType)); } else if (ObjURI != null) { throw new RemotingException("It is not possible marshal a proxy of a remote object."); } ObjRef or = proxy.ObjectIdentity.CreateObjRef(RequestedType); TrackingServices.NotifyMarshaledObject(Obj, or); return(or); } } if (RequestedType == null) { RequestedType = Obj.GetType(); } if (ObjURI == null) { if (Obj.ObjectIdentity == null) { ObjURI = NewUri(); CreateClientActivatedServerIdentity(Obj, RequestedType, ObjURI); } } else { ClientActivatedIdentity identity = GetIdentityForUri("/" + ObjURI) as ClientActivatedIdentity; if (identity == null || Obj != identity.GetServerObject()) { CreateClientActivatedServerIdentity(Obj, RequestedType, ObjURI); } } ObjRef oref; if (IsTransparentProxy(Obj)) { oref = RemotingServices.GetRealProxy(Obj).ObjectIdentity.CreateObjRef(RequestedType); } else { oref = Obj.CreateObjRef(RequestedType); } TrackingServices.NotifyMarshaledObject(Obj, oref); return(oref); }
internal static ClientActivatedIdentity CreateClientActivatedServerIdentity(MarshalByRefObject realObject, Type objectType, string objectUri) { ClientActivatedIdentity identity = new ClientActivatedIdentity (objectUri, objectType); identity.AttachServerObject (realObject, Context.DefaultContext); RegisterServerIdentity (identity); identity.StartTrackingLifetime ((ILease)realObject.InitializeLifetimeService ()); return identity; }
public static ObjRef Marshal (MarshalByRefObject Obj, string ObjURI, Type RequestedType) { if (IsTransparentProxy (Obj)) { RealProxy proxy = RemotingServices.GetRealProxy (Obj); Identity identity = proxy.ObjectIdentity; if (identity != null) { if (proxy.GetProxiedType().IsContextful && !identity.IsConnected) { // Unregistered local contextbound object. Register now. ClientActivatedIdentity cboundIdentity = (ClientActivatedIdentity)identity; if (ObjURI == null) ObjURI = NewUri(); cboundIdentity.ObjectUri = ObjURI; RegisterServerIdentity (cboundIdentity); cboundIdentity.StartTrackingLifetime ((ILease)Obj.InitializeLifetimeService()); return cboundIdentity.CreateObjRef (RequestedType); } else if (ObjURI != null) throw new RemotingException ("It is not possible marshal a proxy of a remote object."); ObjRef or = proxy.ObjectIdentity.CreateObjRef (RequestedType); TrackingServices.NotifyMarshaledObject (Obj, or); return or; } } if (RequestedType == null) RequestedType = Obj.GetType (); if (ObjURI == null) { if (Obj.ObjectIdentity == null) { ObjURI = NewUri(); CreateClientActivatedServerIdentity (Obj, RequestedType, ObjURI); } } else { ClientActivatedIdentity identity = GetIdentityForUri ("/" + ObjURI) as ClientActivatedIdentity; if (identity == null || Obj != identity.GetServerObject()) CreateClientActivatedServerIdentity (Obj, RequestedType, ObjURI); } ObjRef oref; if (IsTransparentProxy (Obj)) oref = RemotingServices.GetRealProxy (Obj).ObjectIdentity.CreateObjRef (RequestedType); else oref = Obj.CreateObjRef (RequestedType); TrackingServices.NotifyMarshaledObject (Obj, oref); return oref; }
// 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); } }
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); }
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); }