Package org.simpleframework.common.lease
Class ContractLease<T>
- java.lang.Object
-
- org.simpleframework.common.lease.ContractLease<T>
-
- All Implemented Interfaces:
Lease<T>
class ContractLease<T> extends java.lang.Object implements Lease<T>
TheContractLease
is used to maintain contracts by using a controller object. This will invoke the controller with the contract when a lease operation is performed. A lease is renewed by changing the contract duration and passing that to the controller which will reestablish the expiry time for it.
-
-
Constructor Summary
Constructors Constructor Description ContractLease(ContractController<T> handler, Contract<T> contract)
Constructor for theContractLease
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
This will cancel the lease and release the resource.long
getExpiry(java.util.concurrent.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, java.util.concurrent.TimeUnit unit)
This ensures that the leased resource is maintained for the specified number ofTimeUnit
seconds.
-
-
-
Field Detail
-
handler
private final ContractController<T> handler
This is the controller object used to handle contracts.
-
-
Constructor Detail
-
ContractLease
public ContractLease(ContractController<T> handler, Contract<T> contract)
Constructor for theContractLease
object. This is used to create a lease which will maintain a contract using a controller object. Lease renewals are performed by changing the expiry duration on the contract and notifying the controller.- Parameters:
handler
- this is used to manage the contract expirationcontract
- this is the contract representing the lease
-
-
Method Detail
-
getExpiry
public long getExpiry(java.util.concurrent.TimeUnit unit) throws LeaseException
Determines the duration remaining before the lease expires. The expiry is given as the number ofTimeUnit
seconds remaining before the lease expires. If this value is negative it should be assumed that the lease has expired.- Specified by:
getExpiry
in interfaceLease<T>
- Parameters:
unit
- this is the time unit used for the duration- Returns:
- the duration remaining within this lease instance
- Throws:
LeaseException
- if the lease expiry has passed
-
renew
public void renew(long duration, java.util.concurrent.TimeUnit unit) throws LeaseException
This ensures that the leased resource is maintained for the specified number ofTimeUnit
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 dependant on how long it takes to clean the resource associated with the lease.- Specified by:
renew
in interfaceLease<T>
- Parameters:
duration
- this is the length of time to renew forunit
- this is the time unit used for the duration- Throws:
LeaseException
- if the expiry has been passed
-
cancel
public void cancel() throws LeaseException
This will cancel the lease and release the resource. This has the same effect as therenew
method with a zero length duration. Once this has been called theCleaner
used should be notified immediately. If the lease has already expired this throws an exception.- Specified by:
cancel
in interfaceLease<T>
- Throws:
LeaseException
- if the expiry has been passed
-
getKey
public 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
.
-
-