public class LeaseManager<T> extends Object implements LeaseProvider<T>
LeaseManager
is used to issue a lease for a
named resource. This is effectively used to issue a request
for a keyed resource to be released when a lease has expired.
The use of a Lease
simplifies the interface to
the notification and also enables other objects to manage the
lease without any knowledge of the resource it represents.Constructor and Description |
---|
LeaseManager(Cleaner<T> cleaner)
Constructor for the
LeaseManager object. |
Modifier and Type | Method and Description |
---|---|
void |
close()
This is used to close the lease provider such that all of
the outstanding leases are canceled.
|
Lease<T> |
lease(T key,
long duration,
TimeUnit unit)
This method will issue a
Lease object that
can be used to manage the release of a keyed resource. |
public LeaseManager(Cleaner<T> cleaner)
LeaseManager
object. This
instance is created using a specified notification handler.
The specified Cleaner
will be notified when
the lease for a named resource expires, which will allow
the cleaner object to perform a clean up for that resource.cleaner
- the cleaner object receiving notificationspublic Lease<T> lease(T key, long duration, TimeUnit unit)
Lease
object that
can be used to manage the release of a keyed resource. If
the lease duration expires before it is renewed then the
notification is sent, typically to a Cleaner
implementation, to signify that the resource should be
recovered. The issued lease can also be canceled.lease
in interface LeaseProvider<T>
key
- this is the key for the leased resourceduration
- this is the duration of the issued leaseunit
- this is the time unit to issue the lease withpublic void close()
lease
method
will result in null leases. Once the provider has been
closes all threads and other such resources are released.close
in interface LeaseProvider<T>
Copyright © 2024. All rights reserved.