public class DefaultCandidate extends AbstractCandidate
Candidate
for leadership.
This implementation simply logs when it is elected and when its leadership is revoked.Constructor and Description |
---|
DefaultCandidate()
Instantiate a default candidate.
|
DefaultCandidate(String id,
String role)
Instantiate a default candidate.
|
Modifier and Type | Method and 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.
|
String |
toString() |
void |
yieldLeadership()
Voluntarily yield leadership if held.
|
getId, getRole
public void onGranted(Context ctx)
Candidate
InterruptedException
. When the thread
is interrupted, this indicates that this candidate is no
longer leader.onGranted
in interface Candidate
onGranted
in class AbstractCandidate
ctx
- leadership contextpublic void onRevoked(Context ctx)
Candidate
onRevoked
in interface Candidate
onRevoked
in class AbstractCandidate
ctx
- leadership contextpublic void yieldLeadership()
onGranted(Context)
method is called by the
leader initiator.