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
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 Details
-
Constructor Details
-
Method Details
-
run
public void run()Starts the leader election loop -
isLeader
-
canBecomeLeader
-
loop
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
-
jitter
Returns aDurationbetween the provided duration and (duration + maxFactor*duration)- Parameters:
duration- to apply jitter tomaxFactor- for jitter- Returns:
- the jittered duration
-