public interface Lease<T>
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.Modifier and Type | Method and Description |
---|---|
void |
cancel()
This will cancel the lease and release the resource.
|
long |
getExpiry(TimeUnit unit)
Determines the duration remaining before the lease expires.
|
T |
getKey()
Provides the key for the resource that this lease represents.
|
void |
renew(long duration,
TimeUnit unit)
This ensures that the leased resource is maintained for the
specified number of
TimeUnit seconds. |
long getExpiry(TimeUnit unit) throws LeaseException
TimeUnit
seconds remaining before the lease expires. If this value is
negative it should be assumed that the lease has expired.unit
- this is the time unit used for the durationException
- if the expiry could not be acquiredLeaseException
void renew(long duration, TimeUnit unit) throws LeaseException
TimeUnit
seconds. 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.duration
- this is the length of time to renew forunit
- this is the time unit used for the durationException
- if the lease could not be renewedLeaseException
void cancel() throws LeaseException
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.Exception
- if the expiry has been passedLeaseException
T getKey()
Object
.Copyright © 2018. All rights reserved.