Class DefaultCandidate

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

public class DefaultCandidate extends AbstractCandidate
Simple Candidate for leadership. This implementation simply logs when it is elected and when its leadership is revoked.
Since:
4.2
Author:
Janne Valkealahti, Artem Bilan
  • Constructor Details

    • DefaultCandidate

      public DefaultCandidate()
      Instantiate a default candidate.
    • DefaultCandidate

      public DefaultCandidate(String id, String role)
      Instantiate a default candidate.
      Parameters:
      id - the identifier
      role - the role
  • Method Details

    • onGranted

      public void onGranted(Context ctx)
      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
      Specified by:
      onGranted in class AbstractCandidate
      Parameters:
      ctx - leadership context
    • onRevoked

      public 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
      Specified by:
      onRevoked in class AbstractCandidate
      Parameters:
      ctx - leadership context
    • yieldLeadership

      public void yieldLeadership()
      Voluntarily yield leadership if held. If leader context is not yet known this method does nothing. Leader context becomes available only after onGranted(Context) method is called by the leader initiator.
    • toString

      public String toString()
      Overrides:
      toString in class Object