Class StaticLeaderElectionService

java.lang.Object
com.google.common.util.concurrent.AbstractIdleService
org.graylog2.cluster.leader.StaticLeaderElectionService
All Implemented Interfaces:
com.google.common.util.concurrent.Service, LeaderElectionService

@Singleton public class StaticLeaderElectionService extends com.google.common.util.concurrent.AbstractIdleService implements LeaderElectionService
Leader election based on the static Configuration.isLeader() setting in the configuration file. After node startup, the leader status is static and will not change.

If the value of Configuration.isLeader() is false, the node will not be a leader, if the value is true, the node will be a leader, unless the node notices upon startup that there is another leader present in the cluster already. In that case the value will be set to false and the node will act as a follower.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

    com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if the current node is the leader of the cluster.
    protected void
     
    protected void
     

    Methods inherited from class com.google.common.util.concurrent.AbstractIdleService

    addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync, toString

    Methods inherited from class java.lang.Object

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

    • StaticLeaderElectionService

      @Inject public StaticLeaderElectionService(Configuration configuration)
  • Method Details

    • isLeader

      public boolean isLeader()
      Description copied from interface: LeaderElectionService
      Check if the current node is the leader of the cluster.

      This method might be called frequently. Implementations should be performant and resource-friendly.

      Specified by:
      isLeader in interface LeaderElectionService
      Returns:
      true if the current node is the leader, false if it is not
    • startUp

      protected void startUp() throws Exception
      Specified by:
      startUp in class com.google.common.util.concurrent.AbstractIdleService
      Throws:
      Exception
    • shutDown

      protected void shutDown() throws Exception
      Specified by:
      shutDown in class com.google.common.util.concurrent.AbstractIdleService
      Throws:
      Exception