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
  • Constructor Summary

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

    Modifier and Type Method Description
    void onGranted​(Context ctx)
    Callback method invoked when this candidate is elected leader.
    void onRevoked​(Context ctx)
    Callback method invoked when this candidate is no longer leader.
    java.lang.String toString()  
    void yieldLeadership()
    Voluntarily yield leadership if held.

    Methods inherited from class org.springframework.integration.leader.AbstractCandidate

    getId, getRole

    Methods inherited from class java.lang.Object

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

    • DefaultCandidate

      public DefaultCandidate()
      Instantiate a default candidate.
    • DefaultCandidate

      public DefaultCandidate​(java.lang.String id, java.lang.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 java.lang.String toString()
      Overrides:
      toString in class java.lang.Object