Package org.simpleframework.common.lease
Interface Contract<T>
-
- All Superinterfaces:
java.lang.Comparable<java.util.concurrent.Delayed>
,java.util.concurrent.Delayed
- All Known Implementing Classes:
Expiration
interface Contract<T> extends java.util.concurrent.Delayed
AContract
is used to represent the contract a lease has been issued. This contains all relevant information regarding the lease, such as the keyed resource that has been leased and the duration of the lease. Delays for the contract can be measured in anyTimeUnit
for convinienct.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
getDelay(java.util.concurrent.TimeUnit unit)
This method will return the number ofTimeUnit
seconds that remain in the contract.T
getKey()
This returns the key for the resource this represents.void
setDelay(long delay, java.util.concurrent.TimeUnit unit)
This method is used to set the number ofTimeUnit
seconds that should remain within the contract.java.lang.String
toString()
This is used to provide a description of the contract that the instance represents.
-
-
-
Method Detail
-
getKey
T getKey()
This returns the key for the resource this represents. This is used when the contract has expired to clean resources associated with the lease. It is passed in to the cleaner as an parameter to the callback. The cleaner is then responsible for cleaning any resources associated with the lease.- Returns:
- returns the resource key that this represents
-
getDelay
long getDelay(java.util.concurrent.TimeUnit unit)
This method will return the number ofTimeUnit
seconds that remain in the contract. If the value returned is less than or equal to zero then it should be assumed that the lease has expired, if greater than zero the lease is active.- Specified by:
getDelay
in interfacejava.util.concurrent.Delayed
- Returns:
- returns the duration in time unit remaining
-
setDelay
void setDelay(long delay, java.util.concurrent.TimeUnit unit)
This method is used to set the number ofTimeUnit
seconds that should remain within the contract. This is used when the contract is to be reissued. Once a new duration has been set the contract for the lease has been changed and the previous expiry time is ignores, so only one clean is called.- Parameters:
delay
- this is the delay to be used for this contractunit
- this is the time unit measurment for the delay
-
toString
java.lang.String toString()
This is used to provide a description of the contract that the instance represents. A description well contain the key owned by the contract as well as the expiry time expected for it. This is used to provide descriptive messages in the exceptions.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a descriptive message describing the contract object
-
-