Class LeaderInitiator

java.lang.Object
org.springframework.integration.hazelcast.leader.LeaderInitiator
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class LeaderInitiator extends Object implements org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationEventPublisherAware
Bootstrap leadership candidates with Hazelcast. Upon construction, start() must be invoked to register the candidate for leadership election.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
    Implementation of leadership context backed by Hazelcast.
    protected class 
    Callable that manages the acquisition of Hazelcast locks for leadership election.
  • Field Summary

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    LeaderInitiator(com.hazelcast.core.HazelcastInstance client)
    Construct a LeaderInitiator with a default candidate.
    LeaderInitiator(com.hazelcast.core.HazelcastInstance client, org.springframework.integration.leader.Candidate candidate)
    Construct a LeaderInitiator.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    org.springframework.integration.leader.Context
    The context of the initiator or null if not running.
    int
     
    boolean
     
    boolean
    true if leadership election for this candidate is running.
    void
    setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
     
    void
    setAutoStartup(boolean autoStartup)
     
    void
    setBusyWaitMillis(long busyWaitMillis)
    Time in milliseconds to wait in between attempts to acquire the lock, if it is not held.
    void
    setHeartBeatMillis(long heartBeatMillis)
    Time in milliseconds to wait in between attempts to re-acquire the lock, once it is held.
    void
    setLeaderEventPublisher(org.springframework.integration.leader.event.LeaderEventPublisher leaderEventPublisher)
    Sets the LeaderEventPublisher.
    void
    setPhase(int phase)
     
    void
    Start the registration of the candidate for leader election.
    void
    Stop the registration of the candidate for leader election.
    void
    stop(Runnable callback)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LeaderInitiator

      public LeaderInitiator(com.hazelcast.core.HazelcastInstance client)
      Construct a LeaderInitiator with a default candidate.
      Parameters:
      client - Hazelcast client
    • LeaderInitiator

      public LeaderInitiator(com.hazelcast.core.HazelcastInstance client, org.springframework.integration.leader.Candidate candidate)
      Construct a LeaderInitiator.
      Parameters:
      client - Hazelcast client
      candidate - leadership election candidate
  • Method Details

    • setLeaderEventPublisher

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

      public void setHeartBeatMillis(long heartBeatMillis)
      Time in milliseconds to wait in between attempts to re-acquire the lock, once it is held. The heartbeat time has to be less than the remote lock expiry period, if there is one, otherwise other nodes can steal the lock while we are sleeping here.
      Parameters:
      heartBeatMillis - the heart-beat timeout in milliseconds. Defaults to LockRegistryLeaderInitiator.DEFAULT_HEART_BEAT_TIME
      Since:
      1.0.1
    • setBusyWaitMillis

      public void setBusyWaitMillis(long busyWaitMillis)
      Time in milliseconds to wait in between attempts to acquire the lock, if it is not held. The longer this is, the longer the system can be leaderless, if the leader dies. If a leader dies without releasing its lock, the system might still have to wait for the old lock to expire, but after that it should not have to wait longer than the busy wait time to get a new leader.
      Parameters:
      busyWaitMillis - the busy-wait timeout in milliseconds Defaults to LockRegistryLeaderInitiator.DEFAULT_BUSY_WAIT_TIME
      Since:
      1.0.1
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • setAutoStartup

      public void setAutoStartup(boolean autoStartup)
    • isAutoStartup

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

      public void setPhase(int phase)
    • getPhase

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

      public org.springframework.integration.leader.Context getContext()
      The context of the initiator or null if not running.
      Returns:
      the context (or null if not running)
    • 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(Runnable callback)
      Specified by:
      stop in interface org.springframework.context.SmartLifecycle
    • 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
    • isRunning

      public boolean isRunning()
      true if leadership election for this candidate is running.
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Returns:
      true if leadership election for this candidate is running
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean