public class LeaderElector<C extends Namespaceable<C> & KubernetesClient> extends Object
Modifier and Type | Field and Description |
---|---|
protected static Double |
JITTER_FACTOR |
Constructor and Description |
---|
LeaderElector(C kubernetesClient,
LeaderElectionConfig leaderElectionConfig) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canBecomeLeader(LeaderElectionRecord leaderElectionRecord) |
protected boolean |
isLeader(LeaderElectionRecord leaderElectionRecord) |
protected static Duration |
jitter(Duration duration,
double maxFactor)
Returns a
Duration between the provided duration and (duration + maxFactor*duration) |
protected static boolean |
loop(Consumer<CountDownLatch> consumer,
long periodInMillis)
Periodically (every provided period) runs the provided
Consumer in a separate thread causing the current
thread to wait until the supplied CountDownLatch is decremented by 1 unit. |
protected static ZonedDateTime |
now() |
void |
run()
Starts the leader election loop
|
protected static final Double JITTER_FACTOR
public LeaderElector(C kubernetesClient, LeaderElectionConfig leaderElectionConfig)
public void run()
protected final boolean isLeader(LeaderElectionRecord leaderElectionRecord)
protected final boolean canBecomeLeader(LeaderElectionRecord leaderElectionRecord)
protected static boolean loop(Consumer<CountDownLatch> consumer, long periodInMillis)
Consumer
in a separate thread causing the current
thread to wait until the supplied CountDownLatch
is decremented by 1 unit.consumer
- function to run in a separate threadperiodInMillis
- to schedule the run of the provided consumerprotected static ZonedDateTime now()
Copyright © 2015–2020 Red Hat. All rights reserved.