public interface Coordinator
extends java.io.Closeable
Modifier and Type | Interface and Description |
---|---|
static interface |
Coordinator.Builder
Builder for
Coordinator instances. |
Modifier and Type | Method and Description |
---|---|
Role |
acquireRole(java.lang.String role,
java.time.Duration timeout)
Try to acquire the given role within the supplied time.
|
java.util.Set<java.lang.String> |
getMembers()
Return the current set of members in this coordinator.
|
java.util.Optional<java.lang.String> |
holder(java.lang.String role)
Return the name of the current holder of a given role.
|
java.util.Optional<Role> |
tryAcquireRole(java.lang.String role)
Try to acquire the given role.
|
java.util.Set<java.lang.String> getMembers()
java.util.Optional<java.lang.String> holder(java.lang.String role)
role
- role of interestjava.util.Optional<Role> tryAcquireRole(java.lang.String 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.
role
- role to be acquiredOptional
Role acquireRole(java.lang.String role, java.time.Duration timeout) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
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.
role
- role to be acquiredtimeout
- time available to acquire the role; if Duration.ZERO
, acquires the role
if, and only if, it is immediately availablejava.util.concurrent.TimeoutException
- if the role cannot be acquired before timeoutjava.lang.InterruptedException
- if the thread is interrupted on entry or while acquiring the role