Class LeaderElector<C extends Namespaceable<C> & KubernetesClient>
- java.lang.Object
-
- io.fabric8.kubernetes.client.extended.leaderelection.LeaderElector<C>
-
public class LeaderElector<C extends Namespaceable<C> & KubernetesClient> extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static Double
JITTER_FACTOR
-
Constructor Summary
Constructors Constructor Description LeaderElector(C kubernetesClient, LeaderElectionConfig leaderElectionConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canBecomeLeader(LeaderElectionRecord leaderElectionRecord)
protected boolean
isLeader(LeaderElectionRecord leaderElectionRecord)
protected static Duration
jitter(Duration duration, double maxFactor)
Returns aDuration
between the provided duration and (duration + maxFactor*duration)protected static boolean
loop(Consumer<CountDownLatch> consumer, long periodInMillis)
Periodically (every provided period) runs the providedConsumer
in a separate thread causing the current thread to wait until the suppliedCountDownLatch
is decremented by 1 unit.protected static ZonedDateTime
now()
void
run()
Starts the leader election loop
-
-
-
Field Detail
-
JITTER_FACTOR
protected static final Double JITTER_FACTOR
-
-
Constructor Detail
-
LeaderElector
public LeaderElector(C kubernetesClient, LeaderElectionConfig leaderElectionConfig)
-
-
Method Detail
-
run
public void run()
Starts the leader election loop
-
isLeader
protected final boolean isLeader(LeaderElectionRecord leaderElectionRecord)
-
canBecomeLeader
protected final boolean canBecomeLeader(LeaderElectionRecord leaderElectionRecord)
-
loop
protected static boolean loop(Consumer<CountDownLatch> consumer, long periodInMillis)
Periodically (every provided period) runs the providedConsumer
in a separate thread causing the current thread to wait until the suppliedCountDownLatch
is decremented by 1 unit.- Parameters:
consumer
- function to run in a separate threadperiodInMillis
- to schedule the run of the provided consumer- Returns:
- true if the current thread was not interrupted, false otherwise
-
now
protected static ZonedDateTime now()
-
-