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(java.lang.String id,
java.lang.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.
|
java.lang.String |
toString() |
void |
yieldLeadership()
Voluntarily yield leadership if held.
|
getId, getRole
public DefaultCandidate()
public DefaultCandidate(java.lang.String id, java.lang.String role)
id
- the identifierrole
- the rolepublic 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.public java.lang.String toString()
toString
in class java.lang.Object