Package org.onosproject.store.primitives
Class DefaultDistributedLock
- java.lang.Object
-
- org.onosproject.store.service.Synchronous<AsyncDistributedLock>
-
- org.onosproject.store.primitives.DefaultDistributedLock
-
- All Implemented Interfaces:
DistributedLock,DistributedPrimitive
public class DefaultDistributedLock extends Synchronous<AsyncDistributedLock> implements DistributedLock
Default implementation for aDistributedLockbacked by aAsyncDistributedLock.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitive
DistributedPrimitive.Status, DistributedPrimitive.Type
-
-
Field Summary
-
Fields inherited from interface org.onosproject.store.service.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description DefaultDistributedLock(AsyncDistributedLock asyncLock, long operationTimeoutMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Versionlock()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.voidunlock()Unlocks the lock.-
Methods inherited from class org.onosproject.store.service.Synchronous
destroy, name, primitiveType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.onosproject.store.service.DistributedLock
primitiveType
-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Constructor Detail
-
DefaultDistributedLock
public DefaultDistributedLock(AsyncDistributedLock asyncLock, long operationTimeoutMillis)
-
-
Method Detail
-
lock
public Version lock()
Description copied from interface:DistributedLockAcquires the lock, blocking until it's available.- Specified by:
lockin interfaceDistributedLock- Returns:
- the acquired lock version
-
tryLock
public Optional<Version> tryLock()
Description copied from interface:DistributedLockAttempts to acquire the lock.- Specified by:
tryLockin interfaceDistributedLock- Returns:
- indicates whether the lock was acquired
-
tryLock
public Optional<Version> tryLock(Duration timeout)
Description copied from interface:DistributedLockAttempts to acquire the lock for a specified amount of time.- Specified by:
tryLockin interfaceDistributedLock- Parameters:
timeout- the timeout after which to give up attempting to acquire the lock- Returns:
- indicates whether the lock was acquired
-
unlock
public void unlock()
Description copied from interface:DistributedLockUnlocks the lock.- Specified by:
unlockin interfaceDistributedLock
-
-