simple.util.lease
Interface Lease


public interface Lease

The Lease object is used to keep a named resource active. This provides a very simple lease that can be used to track the activity of a resource or system. Keeping track of activity allows resources to be maintained until such time that they are no longer required, allowing the server to clean up any allocated memory, file descriptors, or other such data.

Author:
Niall Gallagher

Method Summary
 void cancel()
          This will cancel the lease and release the resource.
 long getExpiry()
          Determines the duration remaining before the lease expires.
 void renew(long duration)
          This ensures that the leased resource is maintained for the specified duration.
 java.lang.String toString()
          Provides the name of the resource that this lease represents.
 

Method Detail

renew

void renew(long duration)
           throws LeaseException
This ensures that the leased resource is maintained for the specified duration. The duration is in milliseconds so the actual expiry time is the System time plus the duration. The accuracy of this method should be exact.

Parameters:
duration - this is the length of time to renew for
Throws:
LeaseException - if the expiry has been passed

cancel

void cancel()
            throws LeaseException
This will cancel the lease and release the resource. This has the same effect as the renew method with a zero length duration. Once this has been called the Cleaner used should be notified immediately. If the lease has already expired this throws an exception.

Throws:
LeaseException - if the expiry has been passed

getExpiry

long getExpiry()
               throws LeaseException
Determines the duration remaining before the lease expires. The expiry is given as the number of milliseconds remaining before the lease expires. If this value is negative it should be assumed that the lease has already expired.

Returns:
the number of milliseconds remaining in the lease
Throws:
LeaseException - if the lease expiry has passed

toString

java.lang.String toString()
Provides the name of the resource that this lease represents. This can be used to identify the resource should the need arise. Also, this provides a convenient means of identifying leases when using or storing it as an Object.

Overrides:
toString in class java.lang.Object
Returns:
this returns the name of the resource represented