CHAPTER 18 THE .NET REMOTING LAYER 595 Notice how the leaseTime and renewOnCallTime properties have been marked with the M suffix, which as you might guess stands for the number of minutes to set for each lease-centric unit of time. If you wish, your
element may also suffix the numerical values with MS (milliseconds), S (seconds), H (hours), or even D (days). Now recall that when you update the server s *.config file, you have effectively changed the leasing characteristics for each CAO/WKO-singleton object hosted by the server. As an alternative, you may choose to programmatically override the InitializeLifetime() method in a specific remote type: public class CarProvider : MarshalByRefObject { public override object InitializeLifetimeService() { // Obtain the current lease info. ILease itfLeaseInfo = (ILease) base.InitializeLifetimeService(); // Adjust settings. itfLeaseInfo.InitialLeaseTime = TimeSpan.FromMinutes(50); itfLeaseInfo.RenewOnCallTime = TimeSpan.FromMinutes(10); return itfLeaseInfo; } … } Here, the CarProvider has altered its InitialLeaseTime value to 50 minutes and its RenewOn- CallTime value to 10. Again, the benefit of overriding InitializeLifetimeServices() is the fact that you can configure each remote type individually. Finally, on an odd note, if you wish to disable lease-based lifetime for a given CAO/WKO-singleton object type, you may override InitializeLifetimeServices() and simply return null. If you do so, you have basically configured an MBR type that will never die as long as the hosting server application is alive and kicking. Server-Side Lease Adjustment As you have just seen, when an MBR type overrides InitializeLifetimeServices(), it is able to change its default leasing behavior at the time of activation. However, for the sake of argument, what if a remote type desires to change its current lease after its activation cycle? For example, assume the CarProvider has a new method whose implementation requires a lengthy operation (such as connecting to a remote database and reading a large set of records). Before beginning the task, you may programmatically adjust your lease such that if you have less than one minute, you renew the lease time to ten minutes. To do so, you can make use of the inherited MarshalByRefObject.GetLifetimeService() and ILease.Renew() methods as follows: // Server-side lease adjustment. // Assume this new method is of the CarProvider type. public void DoLengthyOperation() { ILease itfLeaseInfo = (ILease)this.GetLifetimeService(); if(itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 1.0) itfLeaseInfo.Renew(TimeSpan.FromMinutes(10)); // Do lengthy task... }
You want to have a cheap webhost for your apache application, then check apache web hosting services.
This entry was posted
on Friday, April 25th, 2008 at 5:03 am and is filed under A1.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.