org.zodic.kubernetes.leader.LeaderContext Maven / Gradle / Ivy
package org.zodic.kubernetes.leader;
import org.springframework.integration.leader.Candidate;
import org.springframework.integration.leader.Context;
public class LeaderContext implements Context {
private final Candidate candidate;
private final LeadershipController leadershipController;
public LeaderContext(Candidate candidate, LeadershipController leadershipController) {
this.candidate = candidate;
this.leadershipController = leadershipController;
}
@Override
public boolean isLeader() {
return this.leadershipController.getLocalLeader().filter(l -> l.isCandidate(this.candidate)).isPresent();
}
@Override
public void yield() {
this.leadershipController.revoke();
}
}