Interface ElectionCandidate

All Known Implementing Classes:
ElectionCandidate.Null, ElectionCandidateImpl

public interface ElectionCandidate
Object to access etcd v3 Election API. ElectionCandidate objects are a one-shot attempt to run an election campaign. The campaign is run in the constructor, which blocks until the campaign attempt returns. If the constructor returns, it means the object holds leadership in the election. If the campaign fails for any reason, the constructor will throw. Once its constructor returns, an ElectionCandidate object holds leadership, and a listener to observe the election and notify in case leadership is lost has been setup. Note that the API for observe in etcd 3.5 does not provide for a way to indicate the required leader option, which is necessary to guarantee that the watcher won't go silent if the etcd server it is talking to is not the etcd master and it has been isolated form the etcd master; if that happens, we will depend on the lease renewal failing to know leadership has been lost.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ElectionCandidate
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close this object.
    io.deephaven.shadow.jetcd.io.etcd.jetcd.ByteSequence
    Get the leadership opaque key associated to us having leadership, or null if we are not the leader.
    boolean
     
    boolean
    register(DhService service, int port)
    Register our address in DH Resolver.
    void
    Resign from this election and remove any DH Resolver registration.
    void
    setLostLeadershipCb(Runnable lostLeadershipCb)
    Set a new lost leadership callback, replacing the previously assigned one during construction.
  • Field Details

  • Method Details

    • setLostLeadershipCb

      void setLostLeadershipCb(Runnable lostLeadershipCb)
      Set a new lost leadership callback, replacing the previously assigned one during construction. Note that if at the time this call is made leadership is already lost, the callback will be invoked from inside this method activation.
      Parameters:
      lostLeadershipCb - a callback to run when leadership is lost.
    • register

      boolean register(DhService service, int port)
      Register our address in DH Resolver. The registration is done as an etcd transaction conditional on our leadership key
      Parameters:
      service - the service for the registration
      port - the port for the registration
      Returns:
      true if the registration succeeded in etcd, false otherwise, which implies leadership was lost.
    • isLeader

      boolean isLeader()
      Returns:
      true if we are still the leader.
    • getLeadershipKey

      io.deephaven.shadow.jetcd.io.etcd.jetcd.ByteSequence getLeadershipKey()
      Get the leadership opaque key associated to us having leadership, or null if we are not the leader. This key can be used transactionally to do other operations conditional on us still being the leader.
      Returns:
      the leadership key
    • resign

      void resign()
      Resign from this election and remove any DH Resolver registration.
    • close

      void close()
      Close this object. Implies resigning if already leader.