org.exolab.jms.lease
Class LeaseManager

java.lang.Object
  |
  +--org.exolab.core.service.Service
        |
        +--org.exolab.core.service.BasicService
              |
              +--org.exolab.jms.lease.LeaseManager
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable, org.exolab.core.service.Serviceable

public class LeaseManager
extends org.exolab.core.service.BasicService

The LeaseManager is responsible for creating and managing the lease objects. The Leasemanager is a singleton. When a BaseLease object is created it is added to the queue according to the duration (i.e. leases with shorter durations are placed at the top of the queue.

When the lease expires the LeeaseManager calls the leasee's associated listener(s).

We need to cater for persistence and non-persistent leases

Version:
$Revision: 1.22 $ $Date: 2003/10/29 04:58:32 $
Author:
Jim Alateras
See Also:
Serialized Form

Constructor Summary
protected LeaseManager()
          Create a new sorted tree set using the lease comparator as the sorting functor.
 
Method Summary
protected  void addLease(BaseLease lease)
          Add a lease
 BaseLease createLease(java.lang.Object object, long duration, LeaseEventListenerIfc listener)
          Create a lease on any object for the specified duration.
 MessageLease createMessageLease(MessageHandle handle, long duration, LeaseEventListenerIfc listener)
          Create a message lease with the specified duration and the nominated listener.
protected  void expire()
          Expires active leases
 int getLeaseCount()
          Returns the number of active leases
static LeaseManager instance()
          Return the singleton instance of the LeaseManager
 void removeAll()
          Remove all the leases from the queue.
 boolean removeLease(BaseLease lease)
          Remove the specified lease.
 BaseLease renewLease(BaseLease lease, long duration)
          Renew the lease on the specified object
 void run()
          The run method will search for expired leases, remove them from the list and notify listeners
 void stop()
          Stop the service.
 
Methods inherited from class org.exolab.core.service.BasicService
start, toString
 
Methods inherited from class org.exolab.core.service.Service
getName, getState, restart, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LeaseManager

protected LeaseManager()
Create a new sorted tree set using the lease comparator as the sorting functor.
Method Detail

instance

public static LeaseManager instance()
Return the singleton instance of the LeaseManager
Returns:
LeaseManager

createMessageLease

public MessageLease createMessageLease(MessageHandle handle,
                                       long duration,
                                       LeaseEventListenerIfc listener)
Create a message lease with the specified duration and the nominated listener. The listener does not to be specified but is merely a convenience argument.

The object must be non-null and the duration must be greater than zero.

Parameters:
handle - message handle
duration - lease duration
listener - object that implements the LeaseEvent- ListenerIfc
Returns:
MessageLease creared lease object or null if no lease is created

createLease

public BaseLease createLease(java.lang.Object object,
                             long duration,
                             LeaseEventListenerIfc listener)
Create a lease on any object for the specified duration. If a listener is also provided then add it to the lease. Insert the lease in the queue and return an instance of the created lease.

The object must be non-null and the duration must be greater than zero.

Parameters:
object - leased object
duration - lease duration
listener - object that implements the LeaseEvent- ListenerIfc
Returns:
BaseLease creared lease object or null if no lease is created

removeLease

public boolean removeLease(BaseLease lease)
Remove the specified lease.
Parameters:
lease - lease to remove
Returns:
boolean true if successful; false otherwise

renewLease

public BaseLease renewLease(BaseLease lease,
                            long duration)
Renew the lease on the specified object
Parameters:
object - object's whose lease we want to renew
duration - the new duration of the lease in ms

removeAll

public void removeAll()
Remove all the leases from the queue. Do not expire any of them

getLeaseCount

public int getLeaseCount()
Returns the number of active leases
Returns:
the number of leases

run

public void run()
The run method will search for expired leases, remove them from the list and notify listeners
Overrides:
run in class org.exolab.core.service.BasicService

stop

public void stop()
          throws org.exolab.core.service.ServiceException
Stop the service.
Overrides:
stop in class org.exolab.core.service.BasicService
Throws:
org.exolab.core.service.ServiceException - if the service fails to stop

expire

protected void expire()
Expires active leases

addLease

protected void addLease(BaseLease lease)
Add a lease
Parameters:
lease - the lease to add


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.