public class LeaderElector extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static Double |
JITTER_FACTOR |
| Constructor and Description |
|---|
LeaderElector(KubernetesClient kubernetesClient,
LeaderElectionConfig leaderElectionConfig,
Executor executor) |
| 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 CompletableFuture<Void> |
loop(Consumer<CompletableFuture<?>> consumer,
LongSupplier delaySupplier,
Executor executor)
Periodically (every provided period) runs the provided
Consumer in a separate thread
until the supplied CompletableFuture is completed. |
protected static ZonedDateTime |
now() |
boolean |
release()
Release the leadership if currently held.
|
void |
run()
Starts the leader election loop
|
CompletableFuture<?> |
start()
Start a leader elector.
|
protected static final Double JITTER_FACTOR
public LeaderElector(KubernetesClient kubernetesClient, LeaderElectionConfig leaderElectionConfig, Executor executor)
public void run()
start() is preferred as it does not hold a thread.
public CompletableFuture<?> start()
public boolean release()
protected final boolean isLeader(LeaderElectionRecord leaderElectionRecord)
protected final boolean canBecomeLeader(LeaderElectionRecord leaderElectionRecord)
protected static CompletableFuture<Void> loop(Consumer<CompletableFuture<?>> consumer, LongSupplier delaySupplier, Executor executor)
Consumer in a separate thread
until the supplied CompletableFuture is completed.consumer - function to run in a separate threaddelaySupplier - to schedule the run of the provided consumerprotected static ZonedDateTime now()
Copyright © 2015–2024 Red Hat. All rights reserved.