Interface Role

All Superinterfaces:
AutoCloseable

public interface Role extends AutoCloseable
A representation of a role.

A role, once acquired, is retained until:

  1. explicitly relinquished by calling Role.close
  2. another member takes the role by calling Coordinator.tryAcquireRole(java.lang.String) or Coordinator.acquireRole(java.lang.String, java.time.Duration) while this client is disconnected
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Voluntarily relinquish role.
    default void
    execute(Runnable runnable, Duration duration)
    Execute the given runnable as the rightful holder of this role.
    <R> R
    execute(Callable<R> callable, Duration duration)
    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 a RoleViolationException.

      Type Parameters:
      R - callable return type
      Parameters:
      callable - task to perform
      duration - role lease time
      Returns:
      the result of the callable
      Throws:
      ExecutionException - wrapping any throwable from the callable
      RoleViolationException - 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 perform
      duration - role lease time
      Throws:
      ExecutionException - wrapping any throwable from the runnable
      RoleViolationException - if the role is not held or is lost during execution
      See Also:
    • close

      void close()
      Voluntarily relinquish role.
      Specified by:
      close in interface AutoCloseable