Package org.simpleframework.common.lease
Class Expiration<T>
java.lang.Object
org.simpleframework.common.lease.Expiration<T>
- All Implemented Interfaces:
Comparable<Delayed>
,Delayed
,Contract<T>
A
Expiration
is used to represent the expiration
for a lease. This contains all relevant information for the
the lease, such as the keyed resource that has been leased and
the duration of the lease. Durations for the contract can be
measured in any TimeUnit
for convenience.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionExpiration
(T key, long lease, TimeUnit scale) Constructor for theExpiration
object. -
Method Summary
Modifier and TypeMethodDescriptionint
This is used to compare the specified delay to this delay.private int
compareTo
(Expiration value) This is used to compare the specified delay to this delay.long
This method will return the number ofTimeUnit
seconds that remain in the contract.getKey()
This returns the key for the resource this represents.private long
getTime()
This method returns the current time in nanoseconds.void
This method is used to set the number ofTimeUnit
seconds that should remain within the contract.toString()
This is used to provide a description of the contract that the instance represents.
-
Field Details
-
time
private volatile long timeThis is the expiration time in nanoseconds for this. -
key
This is the key representing the resource being lease.
-
-
Constructor Details
-
Expiration
Constructor for theExpiration
object. This is used to create a contract with an initial expiry period. Once this is created the time is taken and the contract can be issued.- Parameters:
key
- this is the key that this contract representslease
- this is the initial lease duration to be usedscale
- this is the time unit scale that is to be used
-
-
Method Details
-
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. -
getDelay
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. -
setDelay
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. -
getTime
private long getTime()This method returns the current time in nanoseconds. This is used to allow the duration of the lease to be calculated with any given time unit which allows flexibility in setting and getting the current delay for the contract.- Returns:
- returns the current time in nanoseconds remaining
-
compareTo
This is used to compare the specified delay to this delay. The result of this operation is used to prioritize contracts in order of first to expire. Contracts that expire first reach the top of the contract queue and are taken off for cleaning.- Specified by:
compareTo
in interfaceComparable<T>
- Parameters:
other
- this is the delay to be compared with this- Returns:
- this returns zero if equal otherwise the difference
-
compareTo
This is used to compare the specified delay to this delay. The result of this operation is used to prioritize contracts in order of first to expire. Contracts that expire first reach the top of the contract queue and are taken off for cleaning.- Parameters:
value
- this is the expiration to be compared with this- Returns:
- this returns zero if equal otherwise the difference
-
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.
-