CHAPTER 18 596 THE .NET REMOTING LAYER (Free php web host)

CHAPTER 18 596 THE .NET REMOTING LAYER Client-Side Lease Adjustment On an additional ILease-related note, it is possible for the client s application domain to adjust the current lease properties for a CAO/WKO-singleton type it is communicating with across the wire. To do so, the client makes use of the static RemotingServices.GetLifetimeService() method. As a parameter to this member, the client passes in the reference to the remote type as follows: // Client-side lease adjustment. CarProvider cp = new CarProvider(cars); ILease itfLeaseInfo = (ILease)RemotingServices.GetLifetimeService(cp); if(itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 10.0) itfLeaseInfo.Renew(TimeSpan.FromMinutes(1000)); This approach can be helpful if the client s application domain is about to enter a lengthy process on the same thread of execution that is using the remote type. For example, if a single-threaded application is about to print out a 100-page document, the chances are quite good that a remote CAO/WKOsingleton type may time out during the process. The other (more elegant) solution, of course, is to spawn a secondary thread of execution, but I think you get the general idea. Server-Side (and Client-Side) Lease Sponsorship The final topic regarding the lease-based lifetime of a CAO/WKO-singleton object to consider is the notion of lease sponsorship. As you have just seen, every CAO/WKO-singleton entity has a default lease, which may be altered in a number of ways on both the server side as well as the client side. Now, regardless of the type s lease configuration, eventually an MBR object s time will be up. At this point, the runtime will garbage-collect the entity . . . well, almost. The truth of the matter is that before an expired type is truly marked for garbage collection, the runtime will check to see if the MBR object in question has any registered lease sponsors. Simply put, a sponsor is a type that implements the ISponsor interface, which is defined as follows: public interface System.Runtime.Remoting.Lifetime.ISponsor { TimeSpan Renewal(ILease lease); } If the runtime detects that an MBR object has a sponsor, it will not garbage-collect the type, but rather call the Renewal() method of the sponsor object to (once again) add time to the current lease. On the other hand, if the MBR has no sponsor, the object s time is truly up. Assuming that you have created a custom class that implements ISponsor, and thus implements Renewal() to return a specific unit of time (via the TimeSpan type), the next question is how exactly to associate the type to a given remote object. Again, this operation may be performed by either the server s application domain or the client s application domain. To do so, the interested party obtains an ILease reference (via the inherited GetLifetimeService() method on the server or using the static RemotingServices.GetLifetimeService() method on the client) and calls Register(): // Server-side sponsor registration. CarSponsor mySponsor = new CarSponsor(); ILease itfLeaseInfo = (ILease)this.GetLifetimeService(); itfLeaseInfo.Register(mySponsor); // Client-side sponsor registration. CarSponsor mySponsor = new CarSponsor(); CarProvider cp = new CarProvider(cars); ILease itfLeaseInfo = (ILease)RemotingServices.GetLifetimeService(cp); itfLeaseInfo.Register(mySponsor);
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply