Interface Coordinator

All Superinterfaces:
AutoCloseable, Closeable

public interface Coordinator extends Closeable
Simple tooling for coordination across a Terracotta cluster.
  • Method Details

    • getMembers

      Set<String> getMembers()
      Return the current set of members in this coordinator.
      Returns:
      the coordinator members
    • holder

      Optional<String> holder(String role)
      Return the name of the current holder of a given role.
      Parameters:
      role - role of interest
      Returns:
      the current role holder
    • tryAcquireRole

      Optional<Role> tryAcquireRole(String role)
      Try to acquire the given role.

      If the role is acquired then tasks can be run as the role holder using the returned Role object. If the role cannot be acquired then an empty Optional will be returned.

      Parameters:
      role - role to be acquired
      Returns:
      a handle representing the role, or an empty Optional
    • acquireRole

      Role acquireRole(String role, Duration timeout) throws TimeoutException, InterruptedException
      Try to acquire the given role within the supplied time.

      If the role is acquired then tasks can be run as the role holder using the returned Role object. If the role cannot be acquired within the given time than a TimeoutException is thrown.

      Parameters:
      role - role to be acquired
      timeout - time available to acquire the role; if Duration.ZERO, acquires the role if, and only if, it is immediately available
      Returns:
      a handle representing the role
      Throws:
      TimeoutException - if the role cannot be acquired before timeout
      InterruptedException - if the thread is interrupted on entry or while acquiring the role