Self-Healing Networks


As demonstrated, one of the concepts introduced in Jini is the concept of resource leasing, or time-based resource allocation. Leasing of resources has direct implications on the programming model used, and the services that must be implemented to support a Jini network.

When a service registers with the LUS, it receives a lease from the LUS. More specifically, the ServiceRegistrar interface returns a ServiceRegistration object when the register method is invoked. The ServiceRegistration contains a getLease method that returns a Lease object.

Proper lease management requires that a service maintain and manage its lease in all service registrars it has registered with and has active residency.

If the service fails to renew the lease when it expires, the LUS will remove the service from its list of available services. The LUS assumes the service is having a problem that keeps it from performing satisfactorily. This is why the Jini network is often referred to as "self-healing." It proactively grooms the service environment without the need for human intervention.

The net.jini.lease package introduced with Jini 1.1 contains the classes related to lease management.

The LeaseRenewalManager is a utility class that can be used to ease the development required to manage leases. The class creates a thread that sleeps until it is time to renew the leases under its management. The LeaseRenewalManager is active as long as the virtual machine that activated the manager is active.

Recall that we have already used a LeaseRenewalManager (LRM), although we did not explicitly provide one when you instantiated a JoinManager in Chapter 14:

 JoinManager   joiner = new JoinManager(   this,                       // service object  entries,                    // service attributes  new SrvcIDListener(),       // ServiceIDListener  - internal helper class  lookupDiscMgr,              // DiscoveryManagement - default  null);                      // LeaseRenewalManager - default 

The last parameter to the JoinManager takes a renewal manager. If one is not supplied, the JoinManager instantiates one on your behalf. You can gain access to the LRM (see Listing 15.9) through the JoinManager's getLeaseRenewalManager method:

 public LeaseRenewalManager getLeaseRenewalManager()  

Using entities of the LRM delegates lease renewal management to the LRM. The LRM will renew leases as necessary. This can help minimize the development requirements of services and clients joining a Jini community. Errors encountered during the lease renewal process can optionally be directed to a lease listener supplied by the using entity.

Listing 15.9 The LeaseRenewalManager Class as Defined by Sun Microsystems
 public class LeaseRenewalManager    LeaseRenewalManager()    LeaseRenewalManager(Lease lease, long desiredExpiration,         LeaseListener listener)    public void cancel(Lease lease)    public void clear()    public long getExpiration(Lease lease)    public void remove(Lease lease)    public void renewFor(Lease lease, long desiredDuration,         LeaseListener listener)    public void renewFor(Lease lease, long desiredDuration, long renewDuration,         LeaseListener listener)    public void renewUntil(Lease lease, long desiredExpiration,         LeaseListener listener)    public void renewUntil(Lease lease, long desiredExpiration,         long renewDuration, LeaseListener listener)    public void setExpiration(Lease lease, long expiration) } 


JavaT P2P Unleashed
JavaT P2P Unleashed
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 209

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