Interface LeaderElection


@Beta public interface LeaderElection
Leader-Election for Synapse services.
  • Method Details

    • runIfLeader

      void runIfLeader(String lockName, Runnable runnable)
      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 election
      runnable - the runnable that is executed by the leader
    • supplyIfLeader

      <T> T supplyIfLeader(String lockName, Supplier<T> supplier)
      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 election
      supplier - 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

      CompletableFuture<Void> runAsyncIfLeader(String lockName, Runnable runnable)
      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 election
      runnable - the runnable that is executed by the leader
      Returns:
      CompletableFuture<Void> that can be used to CompletableFuture.join() or further process the result.
    • runAsyncIfLeader

      CompletableFuture<Void> 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.
      Parameters:
      lockName - the name of the distributed lock used for leader election
      runnable - the runnable that is executed by the leader
      executor - the Executor used to asynchronously run the Runnable
      Returns:
      CompletableFuture<Void> that can be used to CompletableFuture.join() or further process the result.
    • supplyAsyncIfLeader

      <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.
      Type Parameters:
      T - the type of the object returned by the supplier
      Parameters:
      lockName - the name of the distributed lock used for leader election
      supplier - 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 election
      supplier - the supplier that is executed by the leader
      executor - 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