Package de.otto.synapse.leaderelection
Interface LeaderElection
@Beta
public interface LeaderElection
Leader-Election for Synapse services.
-
Method Summary
Modifier and TypeMethodDescriptionrunAsyncIfLeader(String lockName, Runnable runnable) Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.runAsyncIfLeader(String lockName, Runnable runnable, Executor executor) Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.voidrunIfLeader(String lockName, Runnable runnable) Synchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.<T> CompletableFuture<T>supplyAsyncIfLeader(String lockName, Supplier<T> supplier) Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.<T> CompletableFuture<T>supplyAsyncIfLeader(String lockName, Supplier<T> supplier, Executor executor) Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.<T> TsupplyIfLeader(String lockName, Supplier<T> supplier) Synchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.
-
Method Details
-
runIfLeader
Synchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.- Parameters:
lockName- the name of the distributed lock used for leader electionrunnable- the runnable that is executed by the leader
-
supplyIfLeader
Synchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.- Type Parameters:
T- the type of the object returned by the supplier- Parameters:
lockName- the name of the distributed lock used for leader electionsupplier- the supplier that is executed by the leader- Returns:
- CompletableFuture of the object returned by the supplier, or CompletableFuture with value null, if the current thread is not the leader
-
runAsyncIfLeader
Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.- Parameters:
lockName- the name of the distributed lock used for leader electionrunnable- the runnable that is executed by the leader- Returns:
- CompletableFuture<Void> that can be used to
CompletableFuture.join()or further process the result.
-
runAsyncIfLeader
Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.- Parameters:
lockName- the name of the distributed lock used for leader electionrunnable- the runnable that is executed by the leaderexecutor- the Executor used to asynchronously run the Runnable- Returns:
- CompletableFuture<Void> that can be used to
CompletableFuture.join()or further process the result.
-
supplyAsyncIfLeader
Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.- Type Parameters:
T- the type of the object returned by the supplier- Parameters:
lockName- the name of the distributed lock used for leader electionsupplier- the supplier that is executed by the leader- Returns:
- CompletableFuture of the object returned by the supplier, or CompletableFuture with value null, if the current thread is not the leader
-
supplyAsyncIfLeader
<T> CompletableFuture<T> supplyAsyncIfLeader(String lockName, Supplier<T> supplier, Executor executor) Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.- Type Parameters:
T- the type of the object returned by the supplier- Parameters:
lockName- the name of the distributed lock used for leader electionsupplier- the supplier that is executed by the leaderexecutor- the Executor used to asynchronously supply the response- Returns:
- CompletableFuture of the object returned by the supplier, or CompletableFuture with value null, if the current thread is not the leader
-