public interface Role
extends java.lang.AutoCloseable
A role, once acquired, is retained until:
Role.close
Coordinator.tryAcquireRole(java.lang.String)
or Coordinator.acquireRole(java.lang.String, java.time.Duration)
while this client is disconnectedModifier and Type | Method and Description |
---|---|
void |
close()
Voluntarily relinquish role.
|
<R> R |
execute(java.util.concurrent.Callable<R> callable,
java.time.Duration duration)
Execute the given callable as the rightful holder of this role.
|
default void |
execute(java.lang.Runnable runnable,
java.time.Duration duration)
Execute the given runnable as the rightful holder of this role.
|
<R> R execute(java.util.concurrent.Callable<R> callable, java.time.Duration duration) throws RoleViolationException, java.util.concurrent.ExecutionException
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 a RoleViolationException
.
R
- callable return typecallable
- task to performduration
- role lease timejava.util.concurrent.ExecutionException
- wrapping any throwable from the callableRoleViolationException
- if the role is not held or is lost during executiondefault void execute(java.lang.Runnable runnable, java.time.Duration duration) throws RoleViolationException, java.util.concurrent.ExecutionException
runnable
- task to performduration
- role lease timejava.util.concurrent.ExecutionException
- wrapping any throwable from the runnableRoleViolationException
- if the role is not held or is lost during executionexecute(Callable, Duration)
void close()
close
in interface java.lang.AutoCloseable