locksByUniqueId = new HashMap<String, CurrentLock>();
locksByToken = new HashMap<String, CurrentLock>();
}
public synchronized LockResult lock( LockTimeout timeout, LockInfo lockInfo, LockableResource r ) {
LockToken currentLock = currentLock( r );
if( currentLock != null ) {
return LockResult.failed( LockResult.FailureReason.ALREADY_LOCKED );
}
LockToken newToken = new LockToken( UUID.randomUUID().toString(), lockInfo, timeout );
CurrentLock newLock = new CurrentLock( r.getUniqueId(), newToken, lockInfo.lockedByUser );
locksByUniqueId.put( r.getUniqueId(), newLock );
locksByToken.put( newToken.tokenId, newLock );
return LockResult.success( newToken );
}