Class AbstractCandidate

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

public abstract class AbstractCandidate extends Object implements Candidate
Base implementation of a Candidate.
Author:
Janne Valkealahti, Gary Russell
  • Constructor Details

    • AbstractCandidate

      public AbstractCandidate()
      Instantiate a abstract candidate.
    • AbstractCandidate

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

    • getRole

      public 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 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 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:
      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