Class LeaderInitiator

java.lang.Object
org.springframework.integration.zookeeper.leader.LeaderInitiator
All Implemented Interfaces:
Lifecycle, Phased, SmartLifecycle

public class LeaderInitiator extends Object implements SmartLifecycle
Bootstrap leadership candidates with ZooKeeper/Curator. Upon construction, start() must be invoked to register the candidate for leadership election.
Since:
4.2
Author:
Patrick Peralta, Janne Valkealahti, Gary Russell, Artem Bilan
  • Constructor Details

    • LeaderInitiator

      public LeaderInitiator(org.apache.curator.framework.CuratorFramework client, Candidate candidate)
      Construct a LeaderInitiator.
      Parameters:
      client - Curator client
      candidate - leadership election candidate
    • LeaderInitiator

      public LeaderInitiator(org.apache.curator.framework.CuratorFramework client, Candidate candidate, String namespace)
      Construct a LeaderInitiator.
      Parameters:
      client - Curator client
      candidate - leadership election candidate
      namespace - namespace base path in zookeeper
  • Method Details

    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
      Returns:
      true if leadership election for this candidate is running
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface Phased
      Specified by:
      getPhase in interface SmartLifecycle
    • setPhase

      public void setPhase(int phase)
      Parameters:
      phase - the phase
      See Also:
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface SmartLifecycle
    • setAutoStartup

      public void setAutoStartup(boolean autoStartup)
      Parameters:
      autoStartup - true to start automatically
      See Also:
    • start

      public void start()
      Start the registration of the candidate for leader election.
      Specified by:
      start in interface Lifecycle
    • stop

      public void stop()
      Stop the registration of the candidate for leader election. If the candidate is currently leader, its leadership will be revoked.
      Specified by:
      stop in interface Lifecycle
    • setLeaderEventPublisher

      public void setLeaderEventPublisher(LeaderEventPublisher leaderEventPublisher)
      Parameters:
      leaderEventPublisher - the event publisher
    • getContext

      public Context getContext()
      The context of the initiator.
      Returns:
      the context.
      Since:
      5.0