public class LockItem extends Object implements 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,
TimeUnit timeUnit)
Ensures that this owner has the lock for a specified period of time.
|
boolean |
equals(Object other)
Returns if two locks have the same (key, ownerName)
|
Map<String,com.amazonaws.services.dynamodbv2.model.AttributeValue> |
getAdditionalAttributes()
Returns the additional attributes that can optionally be stored alongside the lock.
|
Optional<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.
|
String |
getOwnerName()
Returns the name of the owner that owns this lock.
|
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.)
|
String |
getRecordVersionNumber()
Returns the current record version number of the lock in DynamoDB.
|
Optional<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.
|
String |
toString()
Returns a string representation of this lock.
|
void |
updateLookUpTime(long lastUpdateOfLock)
Updates the last updated time of the lock.
|
public String getPartitionKey()
public Optional<String> getSortKey()
public Optional<ByteBuffer> getData()
public Map<String,com.amazonaws.services.dynamodbv2.model.AttributeValue> getAdditionalAttributes()
public String getOwnerName()
public long getLookupTime()
public String getRecordVersionNumber()
public long getLeaseDuration()
sendHeartbeat.public boolean getDeleteLockItemOnClose()
public void close()
close in interface Closeableclose in interface AutoCloseablepublic String toString()
public int hashCode()
public boolean equals(Object other)
public 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,
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 void updateLookUpTime(long lastUpdateOfLock)
lastUpdateOfLock - - Time to update the lock withpublic 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 setIllegalStateException - when the lock is already releasedCopyright © 2013–2019. All rights reserved.