in src/main/java/com/amazonaws/services/dynamodbv2/AmazonDynamoDBLockClient.java [952:975]
public Optional<LockItem> getLock(final String key, final Optional<String> sortKey) {
Objects.requireNonNull(sortKey, "Sort Key must not be null (can be Optional.empty())");
final LockItem localLock = this.locks.get(key + sortKey.orElse(""));
if (localLock != null) {
return Optional.of(localLock);
}
final Optional<LockItem> lockItem =
this.getLockFromDynamoDB(new GetLockOptions.GetLockOptionsBuilder(key).withSortKey(sortKey.orElse(null)).withDeleteLockOnRelease(false).build());
if (lockItem.isPresent()) {
if (lockItem.get().isReleased()) {
// Return empty if a lock was released but still left in the table
return Optional.empty();
} else {
/*
* Clear out the record version number so that the caller cannot accidentally perform updates on this lock (since
* the caller has not acquired the lock)
*/
lockItem.get().updateRecordVersionNumber("", 0, lockItem.get().getLeaseDuration());
}
}
return lockItem;
}