Class LeaderInitiator

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

public class LeaderInitiator
extends java.lang.Object
implements org.springframework.context.SmartLifecycle
Bootstrap leadership candidates with ZooKeeper/Curator. Upon construction, start() must be invoked to register the candidate for leadership election.
Since:
4.2
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    protected class  LeaderInitiator.LeaderListener
    Implementation of Curator leadership election listener.
  • Field Summary

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor Description
    LeaderInitiator​(org.apache.curator.framework.CuratorFramework client, org.springframework.integration.leader.Candidate candidate)
    Construct a LeaderInitiator.
    LeaderInitiator​(org.apache.curator.framework.CuratorFramework client, org.springframework.integration.leader.Candidate candidate, java.lang.String namespace)
    Construct a LeaderInitiator.
  • Method Summary

    Modifier and Type Method Description
    org.springframework.integration.leader.Context getContext()
    The context of the initiator.
    int getPhase()  
    boolean isAutoStartup()  
    boolean isRunning()  
    void setAutoStartup​(boolean autoStartup)  
    void setLeaderEventPublisher​(org.springframework.integration.leader.event.LeaderEventPublisher leaderEventPublisher)
    Sets the LeaderEventPublisher.
    void setPhase​(int phase)  
    void start()
    Start the registration of the candidate for leader election.
    void stop()
    Stop the registration of the candidate for leader election.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.SmartLifecycle

    stop
  • Constructor Details

    • LeaderInitiator

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

      public LeaderInitiator​(org.apache.curator.framework.CuratorFramework client, org.springframework.integration.leader.Candidate candidate, java.lang.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 org.springframework.context.Lifecycle
      Returns:
      true if leadership election for this candidate is running
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • setPhase

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

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • setAutoStartup

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

      public void start()
      Start the registration of the candidate for leader election.
      Specified by:
      start in interface org.springframework.context.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 org.springframework.context.Lifecycle
    • setLeaderEventPublisher

      public void setLeaderEventPublisher​(org.springframework.integration.leader.event.LeaderEventPublisher leaderEventPublisher)
      Sets the LeaderEventPublisher.
      Parameters:
      leaderEventPublisher - the event publisher
    • getContext

      public org.springframework.integration.leader.Context getContext()
      The context of the initiator.
      Returns:
      the context.
      Since:
      5.0