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 aDistributedLock
backed 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 Version
lock()
Acquires the lock, blocking until it's available.java.util.Optional<Version>
tryLock()
Attempts to acquire the lock.java.util.Optional<Version>
tryLock(java.time.Duration timeout)
Attempts to acquire the lock for a specified amount of time.void
unlock()
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:DistributedLock
Acquires the lock, blocking until it's available.- Specified by:
lock
in interfaceDistributedLock
- Returns:
- the acquired lock version
-
tryLock
public java.util.Optional<Version> tryLock()
Description copied from interface:DistributedLock
Attempts to acquire the lock.- Specified by:
tryLock
in interfaceDistributedLock
- Returns:
- indicates whether the lock was acquired
-
tryLock
public java.util.Optional<Version> tryLock(java.time.Duration timeout)
Description copied from interface:DistributedLock
Attempts to acquire the lock for a specified amount of time.- Specified by:
tryLock
in 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:DistributedLock
Unlocks the lock.- Specified by:
unlock
in interfaceDistributedLock
-
-