Class DefaultCandidate
java.lang.Object
org.springframework.integration.leader.AbstractCandidate
org.springframework.integration.leader.DefaultCandidate
- All Implemented Interfaces:
Candidate
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 Summary
ConstructorDescriptionInstantiate a default candidate.DefaultCandidate
(String id, String role) Instantiate a default candidate. -
Method Summary
Methods inherited from class org.springframework.integration.leader.AbstractCandidate
getId, getRole
-
Constructor Details
-
DefaultCandidate
public DefaultCandidate()Instantiate a default candidate. -
DefaultCandidate
Instantiate a default candidate.- Parameters:
id
- the identifierrole
- the role
-
-
Method Details
-
onGranted
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 throwingInterruptedException
. When the thread is interrupted, this indicates that this candidate is no longer leader.- Specified by:
onGranted
in interfaceCandidate
- Specified by:
onGranted
in classAbstractCandidate
- Parameters:
ctx
- leadership context
-
onRevoked
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 interfaceCandidate
- Specified by:
onRevoked
in classAbstractCandidate
- 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 afteronGranted(Context)
method is called by the leader initiator. -
toString
-