Package org.simpleframework.common.lease
Class ContractLease<T>
java.lang.Object
org.simpleframework.common.lease.ContractLease<T>
- All Implemented Interfaces:
Lease<T>
The
ContractLease
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.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionContractLease
(ContractController<T> handler, Contract<T> contract) Constructor for theContractLease
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
This will cancel the lease and release the resource.long
Determines the duration remaining before the lease expires.getKey()
Provides the key for the resource that this lease represents.void
This ensures that the leased resource is maintained for the specified number ofTimeUnit
seconds.
-
Field Details
-
handler
This is the controller object used to handle contracts. -
contract
This is the contract object representing the lease.
-
-
Constructor Details
-
ContractLease
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 Details
-
getExpiry
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
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
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
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
.
-