Interface Lease<T>
public interface Lease<T>
The
Lease object is used to keep a keyed 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
Modifier and TypeMethodDescriptionvoidcancel()This will cancel the lease and release the resource.longDetermines the duration remaining before the lease expires.getKey()Provides the key for the resource that this lease represents.voidThis ensures that the leased resource is maintained for the specified number ofTimeUnitseconds.
-
Method Details
-
getExpiry
Determines the duration remaining before the lease expires. The expiry is given as the number ofTimeUnitseconds remaining before the lease expires. If this value is negative it should be assumed that the lease has expired.- Parameters:
unit- this is the time unit used for the duration- Returns:
- the duration remaining within this lease instance
- Throws:
Exception- if the expiry could not be acquiredLeaseException
-
renew
This ensures that the leased resource is maintained for the specified number ofTimeUnitseconds. Allowing the duration unit to be specified enables the lease system to maintain a resource with a high degree of accuracy. The accuracy of the leasing system is dependent on how long it takes to clean the resource associated with the lease.- Parameters:
duration- this is the length of time to renew forunit- this is the time unit used for the duration- Throws:
Exception- if the lease could not be renewedLeaseException
-
cancel
This will cancel the lease and release the resource. This has the same effect as therenewmethod with a zero length duration. Once this has been called theCleanerused should be notified immediately. If the lease has already expired this throws an exception.- Throws:
Exception- if the expiry has been passedLeaseException
-
getKey
T getKey()Provides the key for 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 anObject.- Returns:
- this returns the key for the resource represented
-