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 DoubleJITTER_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 booleancanBecomeLeader(LeaderElectionRecord leaderElectionRecord)protected booleanisLeader(LeaderElectionRecord leaderElectionRecord)protected static Durationjitter(Duration duration, double maxFactor)Returns aDurationbetween the provided duration and (duration + maxFactor*duration)protected static booleanloop(Consumer<CountDownLatch> consumer, long periodInMillis)Periodically (every provided period) runs the providedConsumerin a separate thread causing the current thread to wait until the suppliedCountDownLatchis decremented by 1 unit.protected static ZonedDateTimenow()voidrun()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 providedConsumerin a separate thread causing the current thread to wait until the suppliedCountDownLatchis 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()
-
-