Interface Candidate

All Known Implementing Classes:
AbstractCandidate, DefaultCandidate

public interface Candidate
Interface that defines the contract for candidates to participate in a leader election. The callback methods onGranted(Context) and onRevoked(Context) are invoked when leadership is granted and revoked.
Author:
Patrick Peralta, Janne Valkealahti
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the identifier.
    Gets the role.
    void
    Callback method invoked when this candidate is elected leader.
    void
    Callback method invoked when this candidate is no longer leader.
  • Method Details

    • getRole

      String getRole()
      Gets the role.
      Returns:
      a string indicating the name of the leadership role this candidate is participating in; other candidates present in the system with the same name will contend for leadership
    • getId

      String getId()
      Gets the identifier.
      Returns:
      a unique ID for this candidate; no other candidate for leader election should return the same id
    • onGranted

      void onGranted(Context ctx) throws InterruptedException
      Callback method invoked when this candidate is elected leader. Implementations may chose to launch a background thread to perform leadership roles and return immediately. Another option is for implementations to perform all leadership work in the thread invoking this method. In the latter case, the method must respond to thread interrupts by throwing InterruptedException. When the thread is interrupted, this indicates that this candidate is no longer leader.
      Parameters:
      ctx - leadership context
      Throws:
      InterruptedException - when this candidate is no longer leader
    • onRevoked

      void onRevoked(Context ctx)
      Callback method invoked when this candidate is no longer leader. Implementations should use this to shut down any resources (threads, network connections, etc) used to perform leadership work.
      Parameters:
      ctx - leadership context