org.mbari.siam.distributed.leasing
Class LeaseManager

java.lang.Object
  extended by org.mbari.siam.distributed.leasing.LeaseManager

public class LeaseManager
extends java.lang.Object

LeaseManager was written to manage an intermittent communication link, though it could be used to manage other resources that fit the paradigm. The paradigm consists of two types of "clients". Lessees are clients who want to keep the resource (link) open, and do so by calling establish(), renew() and terminate(). LeaseManager can manage multiple such clients simultaneously, and keeps them in a vector. LeaseListeners are clients who actually perform the resource management based on whether there are any outstanding lessees. In the current implementation, there is just one LeaseListener, who simply turns on/off the RF power to the link. But in principle there can also be multiple listeners, who presumably perform different functions based on the lease state. NOTE: It is important that the callbacks implemented by LeaseListeners execute in a timely manner, so that the remote client is not blocked for an excessive amount of time.

Author:
Tom O'Reilly Modified by Bob Herlien

Nested Class Summary
 class LeaseManager.Lessee
          A Lessee is constructed and put on the _lessees list for every LeaseManager.establish().
 
Field Summary
static long UNKNOWN_TIME
          Constant which indicates an indeterminate time.
 
Constructor Summary
LeaseManager()
          Constructor.
 
Method Summary
 void addListener(LeaseListener listener)
          Add a lease listener.
protected  void debugPrint(java.lang.String message)
          Print debug message.
 int establish(long leaseMillisec, long nextEstablishTime, java.lang.String clientNote)
          Called to establish the communications link.
 int establish(long leaseMillisec, java.lang.String clientNote)
          Called to establish the communications link.
 LeaseManager.Lessee getLessee(int leaseID)
          Get the Lessee that has a given LeaseID
 java.util.Vector getLessees()
          Return vector of lessess.
 int nLessees()
          Return number of lessees
 void renew(int leaseID, long leaseDurationMsec)
          Called when lease is being renewed.
 void terminate(int leaseID, long nextConnectTime)
          Called when communications link is being disconnected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_TIME

public static final long UNKNOWN_TIME
Constant which indicates an indeterminate time.

See Also:
Constant Field Values
Constructor Detail

LeaseManager

public LeaseManager()
Constructor. connect/disconnect occurs.

Method Detail

addListener

public void addListener(LeaseListener listener)
Add a lease listener.


establish

public int establish(long leaseMillisec,
                     long nextEstablishTime,
                     java.lang.String clientNote)
              throws LeaseRefused
Called to establish the communications link.

Parameters:
leaseMillisec - lease period in milliseconds
nextEstablishTime - Estimated time that this task expects to call establish() again.
clientNote - note about connection
Returns:
leaseID to use with renew(), terminate(). Will be >= 1.
Throws:
LeaseRefused

establish

public int establish(long leaseMillisec,
                     java.lang.String clientNote)
              throws LeaseRefused
Called to establish the communications link.

Parameters:
leaseMillisec - lease period in milliseconds
Returns:
leaseID to use with renew(), terminate(). Will be >= 1.
Throws:
LeaseRefused

getLessee

public LeaseManager.Lessee getLessee(int leaseID)
Get the Lessee that has a given LeaseID


nLessees

public int nLessees()
Return number of lessees


getLessees

public java.util.Vector getLessees()
Return vector of lessess.


renew

public void renew(int leaseID,
                  long leaseDurationMsec)
           throws LeaseRefused
Called when lease is being renewed.

Parameters:
leaseID - lease identifier
leaseDurationMsec - lease period in milliseconds
Throws:
LeaseRefused

terminate

public void terminate(int leaseID,
                      long nextConnectTime)
               throws LeaseRefused
Called when communications link is being disconnected.

Parameters:
nextConnectTime - next scheduled connection time (millisec from epoch)
Throws:
LeaseRefused

debugPrint

protected void debugPrint(java.lang.String message)
Print debug message.



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.