- All Known Implementing Classes:
LockExecutorImpl
@ClassVersion(sourceVersion="$Id: LockExecutor.java 1097 2024-02-06 20:10:12Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public sealed interface LockExecutor
permits LockExecutorImpl
Allows to execute an operation with an obtained lock.
Use this class like below:
…
final var lock = new ReentrantLock();
final var executor = LockExecutor.of( lock );
…
executor.execute( () -> doSomething() );
…
- Note:
-
- If your program is using
AutoLock
, you should use the corresponding methods from there.
- If your program is using
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: LockExecutor.java 1097 2024-02-06 20:10:12Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.lang.LockExecutor"
-
Method Summary
Modifier and TypeMethodDescriptionboolean
evaluate
(Constraint constraint) Evaluates the given condition.void
Executes the given action.<R> Optional
<R> Executes the given operation.static LockExecutor
Creates a newLockExecutor
from the givenLock
instance.static LockExecutor
Creates a newLockExecutor
from the givenAutoLock
instance.
-
Method Details
-
evaluate
Evaluates the given condition.- Parameters:
constraint
- The constraint.- Returns:
- The result of the evaluation of the condition.
- Throws:
AutoLock.ExecutionFailedException
- The evaluation failed for some reason.
-
execute
Executes the given action.- Parameters:
action
- The action.- Throws:
AutoLock.ExecutionFailedException
- The action failed for some reason.
-
execute
Executes the given operation.- Type Parameters:
R
- The type of the operation's result.- Parameters:
operation
- The operation.- Returns:
- An instance of
Optional
that holds the result of the operation. - Throws:
AutoLock.ExecutionFailedException
- The operation failed for some reason.
-
of
Creates a newLockExecutor
from the givenLock
instance.- Parameters:
lock
- The lock.- Returns:
- The new
LockExecutor
.
-
of
Creates a newLockExecutor
from the givenAutoLock
instance.- Parameters:
lock
- The lock.- Returns:
- The new
LockExecutor
.
-