org.exolab.jms.lease
Class BaseLease

java.lang.Object
  |
  +--org.exolab.jms.lease.BaseLease
All Implemented Interfaces:
java.lang.Comparable, LeaseIfc

public class BaseLease
extends java.lang.Object
implements LeaseIfc, java.lang.Comparable

Generic lease implementation, which may be used to lease any object.

Version:
$Revision: 1.2 $ $Date: 2005/03/18 03:47:30 $
Author:
Jim Alateras, Tim Anderson

Field Summary
protected  long _duration
          The duration of the lease in milliseconds.
protected  long _expiryTime
          This is the time that the lease will expire.
protected  java.lang.Object _leasedObject
          This is the object that is leased.
protected  LeaseEventListenerIfc _listener
          The listener that will be notified when the lease expires.
 
Constructor Summary
BaseLease(java.lang.Object object, long duration, LeaseEventListenerIfc listener)
          Construct a new BaseLease.
 
Method Summary
 int compareTo(java.lang.Object object)
          Compares this object with the specified object.
 long getDuration()
          Returns the duration of the lease.
 long getExpiryTime()
          Return the absolute expiry time of this lease.
 java.lang.Object getLeasedObject()
          Returns the leased object.
 LeaseEventListenerIfc getLeaseEventListener()
          Returns the listener to notify of lease events.
 long getRemainingTime()
          Returns the time remaining on the lease.
protected  void notifyLeaseExpired()
          Notify the listeners that this lease has expird.
 void setDuration(long duration)
          Change the duration of the lease.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_leasedObject

protected final java.lang.Object _leasedObject
This is the object that is leased.

_duration

protected long _duration
The duration of the lease in milliseconds.

_expiryTime

protected long _expiryTime
This is the time that the lease will expire.

_listener

protected LeaseEventListenerIfc _listener
The listener that will be notified when the lease expires.
Constructor Detail

BaseLease

public BaseLease(java.lang.Object object,
                 long duration,
                 LeaseEventListenerIfc listener)
Construct a new BaseLease.
Parameters:
object - the leased object
duration - the duration of lease, in milliseconds
listener - the listener to notify of lease events
Method Detail

getExpiryTime

public long getExpiryTime()
Return the absolute expiry time of this lease.
Specified by:
getExpiryTime in interface LeaseIfc
Returns:
the expiry time of the lease, in milliseconds

getDuration

public long getDuration()
Returns the duration of the lease.
Specified by:
getDuration in interface LeaseIfc
Returns:
the duration of the lease, in milliseconds

setDuration

public void setDuration(long duration)
Change the duration of the lease.
Parameters:
duration - the new lease duration, in milliseconds

getRemainingTime

public long getRemainingTime()
Returns the time remaining on the lease.
Specified by:
getRemainingTime in interface LeaseIfc
Returns:
the time remaining, in milliseconds

getLeasedObject

public java.lang.Object getLeasedObject()
Returns the leased object.
Specified by:
getLeasedObject in interface LeaseIfc
Returns:
the leased object

getLeaseEventListener

public LeaseEventListenerIfc getLeaseEventListener()
Returns the listener to notify of lease events.
Returns:
the listener to notify of lease events

compareTo

public int compareTo(java.lang.Object object)
Compares this object with the specified object. It returns a negative integer is this object is less than the specified object; zero if this object is equal to the specified object or a positive integer if this object is greater than the specified object

The comparison is based on the expiration time.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Returns a string representation of this object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this

notifyLeaseExpired

protected void notifyLeaseExpired()
Notify the listeners that this lease has expird. This method has package level scope.


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