public class LockItem
extends java.lang.Object
implements java.io.Closeable
| Modifier and Type | Method and Description |
|---|---|
boolean |
amIAboutToExpire()
Returns whether or not the lock is entering the "danger zone" time
period.
|
void |
close()
Releases the lock for others to use.
|
void |
ensure(long leaseDurationToEnsure,
java.util.concurrent.TimeUnit timeUnit)
Ensures that this owner has the lock for a specified period of time.
|
boolean |
equals(java.lang.Object other)
Returns if two locks have the same (key, ownerName)
|
java.util.Map<java.lang.String,AttributeValue> |
getAdditionalAttributes()
Returns the additional attributes that can optionally be stored alongside the lock.
|
java.util.Optional<java.nio.ByteBuffer> |
getData() |
boolean |
getDeleteLockItemOnClose()
Returns a boolean indicating whether the lock should be deleted from DynamoDB after release.
|
long |
getLeaseDuration()
Returns the amount of time that the client has this lock for, which can be kept up to date by calling
sendHeartbeat. |
long |
getLookupTime()
Returns the last time this lock was updated.
|
java.lang.String |
getOwnerName()
Returns the name of the owner that owns this lock.
|
java.lang.String |
getPartitionKey()
Returns the key associated with this lock, which is unique for every lock (unless the lock has a sort key, in which case
key + sortKey is unique.)
|
java.lang.String |
getRecordVersionNumber()
Returns the current record version number of the lock in DynamoDB.
|
java.util.Optional<java.lang.String> |
getSortKey()
Returns the sort key associated with the lock, if there is one.
|
int |
hashCode()
Hash code of just the (key, ownerName) as that is what uniquely identifies this lock.
|
boolean |
isExpired()
Returns whether or not the lock is expired, based on the lease duration and when the last heartbeat was sent.
|
void |
sendHeartBeat()
Sends a heartbeat to indicate that the given lock is still being worked on.
|
java.lang.String |
toString()
Returns a string representation of this lock.
|
public java.lang.String getPartitionKey()
public java.util.Optional<java.lang.String> getSortKey()
public java.util.Optional<java.nio.ByteBuffer> getData()
public java.util.Map<java.lang.String,AttributeValue> getAdditionalAttributes()
public java.lang.String getOwnerName()
public long getLookupTime()
public java.lang.String getRecordVersionNumber()
public long getLeaseDuration()
sendHeartbeat.public boolean getDeleteLockItemOnClose()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic boolean isExpired()
public void sendHeartBeat()
createHeartbeatBackgroundThread=true when setting up this object, then this method is unnecessary, because the
background thread will be periodically calling it and sending heartbeats. However, if
createHeartbeatBackgroundThread=false, then this method must be called to instruct DynamoDB that the lock should
not be expired.
This is equivalent to calling lockClient.sendHeartbeat(lockItem)
public void ensure(long leaseDurationToEnsure,
java.util.concurrent.TimeUnit timeUnit)
Ensures that this owner has the lock for a specified period of time. If the lock will expire in less than the amount of
time passed in, then this method will do nothing. Otherwise, it will set the leaseDuration to that value and send a
heartbeat, such that the lock will expire no sooner than after leaseDuration elapses.
This method is not required if using heartbeats, because the client could simply call isExpired before every
operation to ensure that it still has the lock. However, it is possible for the client to instead call this method before
executing every operation if they all require different lengths of time, and the client wants to ensure it always has
enough time.
This method will throw a LockNotGrantedException if it does not currently hold the lock.
leaseDurationToEnsure - The amount of time to ensure that the lease is granted fortimeUnit - The time unit for the leaseDurationpublic boolean amIAboutToExpire()
true if the lock has been released or the lock's
lease has entered the "danger zone" * false if the
lock has not been released and the lock has not yet entered the
"danger zone"SessionMonitorNotSetException - when the SessionMonitor is not setjava.lang.IllegalStateException - when the lock is already released