Interface LeaderElection


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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncIfLeader​(java.lang.String lockName, java.lang.Runnable runnable)
      Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.
      java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncIfLeader​(java.lang.String lockName, java.lang.Runnable runnable, java.util.concurrent.Executor executor)
      Asynchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.
      void runIfLeader​(java.lang.String lockName, java.lang.Runnable runnable)
      Synchronously executes the runnable, if the current thread is able to become the leader by optaining the specified lock.
      <T> java.util.concurrent.CompletableFuture<T> supplyAsyncIfLeader​(java.lang.String lockName, java.util.function.Supplier<T> supplier)
      Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.
      <T> java.util.concurrent.CompletableFuture<T> supplyAsyncIfLeader​(java.lang.String lockName, java.util.function.Supplier<T> supplier, java.util.concurrent.Executor executor)
      Asynchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.
      <T> T supplyIfLeader​(java.lang.String lockName, java.util.function.Supplier<T> supplier)
      Synchronously executes the supplier, if the current thread is able to become the leader by optaining the specified lock.
    • Method Detail

      • runIfLeader

        void runIfLeader​(java.lang.String lockName,
                         java.lang.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​(java.lang.String lockName,
                             java.util.function.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

        java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncIfLeader​(java.lang.String lockName,
                                                                                java.lang.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

        java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncIfLeader​(java.lang.String lockName,
                                                                                java.lang.Runnable runnable,
                                                                                java.util.concurrent.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> java.util.concurrent.CompletableFuture<T> supplyAsyncIfLeader​(java.lang.String lockName,
                                                                          java.util.function.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> java.util.concurrent.CompletableFuture<T> supplyAsyncIfLeader​(java.lang.String lockName,
                                                                          java.util.function.Supplier<T> supplier,
                                                                          java.util.concurrent.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