Package org.simpleframework.common.lease
Class Expiration<T>
- java.lang.Object
-
- org.simpleframework.common.lease.Expiration<T>
-
- All Implemented Interfaces:
java.lang.Comparable<java.util.concurrent.Delayed>
,java.util.concurrent.Delayed
,Contract<T>
class Expiration<T> extends java.lang.Object implements Contract<T>
AExpiration
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 anyTimeUnit
for convenience.
-
-
Constructor Summary
Constructors Constructor Description Expiration(T key, long lease, java.util.concurrent.TimeUnit scale)
Constructor for theExpiration
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(java.util.concurrent.Delayed other)
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
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.private long
getTime()
This method returns the current time in nanoseconds.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.
-
-
-
Field Detail
-
time
private volatile long time
This is the expiration time in nanoseconds for this.
-
key
private T key
This is the key representing the resource being lease.
-
-
Constructor Detail
-
Expiration
public Expiration(T key, long lease, java.util.concurrent.TimeUnit scale)
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 Detail
-
getKey
public 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.
-
getDelay
public 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.
-
setDelay
public 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.
-
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
public int compareTo(java.util.concurrent.Delayed other)
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 interfacejava.lang.Comparable<T>
- Parameters:
other
- this is the delay to be compared with this- Returns:
- this returns zero if equal otherwise the difference
-
compareTo
private int compareTo(Expiration value)
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
public 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.
-
-