Class LeaderElector

java.lang.Object
io.kubernetes.client.extended.leaderelection.LeaderElector
All Implemented Interfaces:
AutoCloseable

public class LeaderElector extends Object implements AutoCloseable
  • Constructor Details

  • Method Details

    • run

      public void run(Runnable startLeadingHook, Runnable stopLeadingHook)
      Runs the leader election in foreground. The process will enter an acquisition loop trying to get a lease of the lock object set in configuration. The acquisition loop stops in either of these scenarios:

      1) An error occurs that prevents us from aquiring a lease.

      2) The LeaderElector successfully acquires leadership. At this point, we will enter a renewal loop where we will continuously renew the lease following the provided configuration.

      Note that in both cases the LeaderElector will NOT return to the acquisition loop. This is most relevant when a leader instance loses leadership as the LeaderElector will not try to re-acquire leadership. To do this, the caller is responsible for explicitly invoking the "run" method again.

      Parameters:
      startLeadingHook - called when a LeaderElector client starts leading
      stopLeadingHook - called when a LeaderElector client stops leading
    • run

      public void run(Runnable startLeadingHook, Runnable stopLeadingHook, Consumer<String> onNewLeaderHook)
      Runs the leader election in foreground. The process will enter an acquisition loop trying to get a lease of the lock object set in configuration. The acquisition loop stops in either of these scenarios:

      1) An error occurs that prevents us from aquiring a lease.

      2) The LeaderElector successfully acquires leadership. At this point, we will enter a renewal loop where we will continuously renew the lease following the provided configuration.

      Note that in both cases the LeaderElector will NOT return to the acquisition loop. This is most relevant when a leader instance loses leadership as the LeaderElector will not try to re-acquire leadership. To do this, the caller is responsible for explicitly invoking the "run" method again.

      Parameters:
      startLeadingHook - called when a LeaderElector client starts leading
      stopLeadingHook - called when a LeaderElector client stops leading
      onNewLeaderHook - called when the client observes a leader that is not the previously observed leader. This includes the first observed leader when the client starts.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable