Interface Role
- All Superinterfaces:
AutoCloseable
A representation of a role.
A role, once acquired, is retained until:
- explicitly relinquished by calling
Role.close
- another member takes the role by calling
Coordinator.tryAcquireRole(java.lang.String)
orCoordinator.acquireRole(java.lang.String, java.time.Duration)
while this client is disconnected
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Voluntarily relinquish role.default void
Execute the given runnable as the rightful holder of this role.<R> R
Execute the given callable as the rightful holder of this role.
-
Method Details
-
execute
<R> R execute(Callable<R> callable, Duration duration) throws RoleViolationException, ExecutionException Execute the given callable as the rightful holder of this role.If the role is no longer validly held when invoking this method then a
RoleViolationException
will be thrown prior to executing the callable. If the role is validly held then the role will be guaranteed for the supplied time while the callable is executed. Upon completion of the callable the server will be contacted to release the guarantee. If upon reaching the server the role has been lost then the operation will throw aRoleViolationException
.- Type Parameters:
R
- callable return type- Parameters:
callable
- task to performduration
- role lease time- Returns:
- the result of the callable
- Throws:
ExecutionException
- wrapping any throwable from the callableRoleViolationException
- if the role is not held or is lost during execution
-
execute
default void execute(Runnable runnable, Duration duration) throws RoleViolationException, ExecutionException Execute the given runnable as the rightful holder of this role.- Parameters:
runnable
- task to performduration
- role lease time- Throws:
ExecutionException
- wrapping any throwable from the runnableRoleViolationException
- if the role is not held or is lost during execution- See Also:
-
close
void close()Voluntarily relinquish role.- Specified by:
close
in interfaceAutoCloseable
-