Class AbstractCandidate

java.lang.Object
org.springframework.integration.leader.AbstractCandidate
All Implemented Interfaces:
Candidate
Direct Known Subclasses:
DefaultCandidate

public abstract class AbstractCandidate
extends java.lang.Object
implements Candidate
Base implementation of a Candidate.
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractCandidate()
    Instantiate a abstract candidate.
    AbstractCandidate​(java.lang.String id, java.lang.String role)
    Instantiate a abstract candidate.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getId()
    Gets the identifier.
    java.lang.String getRole()
    Gets the role.
    abstract void onGranted​(Context ctx)
    Callback method invoked when this candidate is elected leader.
    abstract void onRevoked​(Context ctx)
    Callback method invoked when this candidate is no longer leader.

    Methods inherited from class java.lang.Object

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

    • AbstractCandidate

      public AbstractCandidate()
      Instantiate a abstract candidate.
    • AbstractCandidate

      public AbstractCandidate​(@Nullable java.lang.String id, @Nullable java.lang.String role)
      Instantiate a abstract candidate.
      Parameters:
      id - the identifier
      role - the role
  • Method Details

    • getRole

      public java.lang.String getRole()
      Description copied from interface: Candidate
      Gets the role.
      Specified by:
      getRole in interface Candidate
      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

      public java.lang.String getId()
      Description copied from interface: Candidate
      Gets the identifier.
      Specified by:
      getId in interface Candidate
      Returns:
      a unique ID for this candidate; no other candidate for leader election should return the same id
    • onGranted

      public abstract void onGranted​(Context ctx) throws java.lang.InterruptedException
      Description copied from interface: Candidate
      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.
      Specified by:
      onGranted in interface Candidate
      Parameters:
      ctx - leadership context
      Throws:
      java.lang.InterruptedException - when this candidate is no longer leader
    • onRevoked

      public abstract void onRevoked​(Context ctx)
      Description copied from interface: Candidate
      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.
      Specified by:
      onRevoked in interface Candidate
      Parameters:
      ctx - leadership context