Class LockRepository
java.lang.Object
com.plotsquared.core.synchronization.LockRepository
A repository for keyed
locks-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull LockGet the lock corresponding to the given lock key@NonNull LockRepository.LockAccessWait for a lock to be available, lock it and return anAutoCloseableinstance that locks the key.voidWait for the lock to become available, and run the given runnable, then unlock the lock.voidConsume a lock
-
Constructor Details
-
LockRepository
public LockRepository()
-
-
Method Details
-
getLock
Get the lock corresponding to the given lock key- Parameters:
key- Lock key- Returns:
- Lock
-
useLock
Consume a lock- Parameters:
key- Lock keyconsumer- Lock consumer
-
useLock
Wait for the lock to become available, and run the given runnable, then unlock the lock. This is a blocking method.- Parameters:
key- Lock keyrunnable- Action to run when the lock is available
-
lock
Wait for a lock to be available, lock it and return anAutoCloseableinstance that locks the key.This is meant to be used with try-with-resources, like such:
try (final LockAccess lockAccess = lockRepository.lock(LockKey.of("your.key"))) { // use lock }- Parameters:
key- Lock key- Returns:
- Lock access. Must be closed.
-