Package org.simpleframework.common.lease
Class LeaseManager<T>
- java.lang.Object
-
- org.simpleframework.common.lease.LeaseManager<T>
-
- All Implemented Interfaces:
LeaseProvider<T>
public class LeaseManager<T> extends java.lang.Object implements LeaseProvider<T>
TheLeaseManageris 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 aLeasesimplifies the interface to the notification and also enables other objects to manage the lease without any knowledge of the resource it represents.
-
-
Field Summary
Fields Modifier and Type Field Description private ContractController<T>handlerThis is the controller used to handle lease operations.
-
Constructor Summary
Constructors Constructor Description LeaseManager(Cleaner<T> cleaner)Constructor for theLeaseManagerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the lease provider such that all of the outstanding leases are canceled.Lease<T>lease(T key, long duration, java.util.concurrent.TimeUnit unit)This method will issue aLeaseobject that can be used to manage the release of a keyed resource.
-
-
-
Field Detail
-
handler
private ContractController<T> handler
This is the controller used to handle lease operations.
-
-
Constructor Detail
-
LeaseManager
public LeaseManager(Cleaner<T> cleaner)
Constructor for theLeaseManagerobject. This instance is created using a specified notification handler. The specifiedCleanerwill be notified when the lease for a named resource expires, which will allow the cleaner object to perform a clean up for that resource.- Parameters:
cleaner- the cleaner object receiving notifications
-
-
Method Detail
-
lease
public Lease<T> lease(T key, long duration, java.util.concurrent.TimeUnit unit)
This method will issue aLeaseobject 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 aCleanerimplementation, to signify that the resource should be recovered. The issued lease can also be canceled.- Specified by:
leasein interfaceLeaseProvider<T>- Parameters:
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 with- Returns:
- a lease that can be used to manage notification
-
close
public void close()
This is used to close the lease provider such that all of the outstanding leases are canceled. This also ensures the provider can no longer be used to issue new leases, such that further invocations of theleasemethod will result in null leases. Once the provider has been closes all threads and other such resources are released.- Specified by:
closein interfaceLeaseProvider<T>
-
-