public class DefaultDistributedLock extends Synchronous<AsyncDistributedLock> implements DistributedLock
DistributedLock
backed by a AsyncDistributedLock
.DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS, DEFAULT_OPERTATION_TIMEOUT_MILLIS
Constructor and Description |
---|
DefaultDistributedLock(AsyncDistributedLock asyncLock,
long operationTimeoutMillis) |
Modifier and Type | Method and Description |
---|---|
Version |
lock()
Acquires the lock, blocking until it's available.
|
Optional<Version> |
tryLock()
Attempts to acquire the lock.
|
Optional<Version> |
tryLock(Duration timeout)
Attempts to acquire the lock for a specified amount of time.
|
void |
unlock()
Unlocks the lock.
|
destroy, name, primitiveType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
primitiveType
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
public DefaultDistributedLock(AsyncDistributedLock asyncLock, long operationTimeoutMillis)
public Version lock()
DistributedLock
lock
in interface DistributedLock
public Optional<Version> tryLock()
DistributedLock
tryLock
in interface DistributedLock
public Optional<Version> tryLock(Duration timeout)
DistributedLock
tryLock
in interface DistributedLock
timeout
- the timeout after which to give up attempting to acquire the lockpublic void unlock()
DistributedLock
unlock
in interface DistributedLock