previous chapter table of contents next chapter

Renewing Leases

Jini supplies a LeaseRenewalManager class that looks after the process of calling renew() at suitable times.

 package net.jini.lease; public class LeaseRenewalManager {     public LeaseRenewalManager();     public LeaseRenewalManager(Lease lease,                                long expiration,                                LeaseListener listener);     public void renewFor(Lease lease,                          long duration,                          LeaseListener listener);     public void renewUntil(Lease lease,                            long expiration,                            LeaseListener listener); 

In Jini 1.0, this class was in package com.sun.jini ; in Jini 1.1 it is now in package net.jini.lease .

The LeaseRenewalManager manages a set of leases, which may be set by a constructor or added later by renewFor() or renewUntil() . The time requested in these methods is in milliseconds . The expiration time is measured since the epoch , whereas the duration time is measured from now.

Generally leases will be renewed and the manager will function quietly . However, the lookup service may decide not to renew a lease and will cause an exception to be thrown. This will be caught by the renewal manager and will cause the listener's notify() method to be called with a LeaseRenewalEvent as parameter, which will allow the application to take corrective action if its lease is denied . If the listener is null , then no notification will take place.

If you are using Jini 1.0, you have to be careful about setting the duration in renewFor() due to a bug that has since been fixed. If you want the service to be registered forever, it is tempting to use Lease.FOREVER . However, the Jini 1.0 implementation just adds this to System.currentTimeMillis() , which overflows to a negative value that is not checked. As a result, it never does any renewals. You need to check

 duration + System.currentTimeMillis() > 0 

before calling renewFor() . This is fixed in Jini 1.1. The renewUntil() method can use Lease.FOREVER with no problems.


A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net