public class EloquentRaftNode
extends java.lang.Object
implements java.lang.AutoCloseable
RaftAlgorithm (purely functional with no actual transport logic)
with an RaftTransport (pure transport logic)
to produce a functioning node in the cluster.| Modifier and Type | Field and Description |
|---|---|
RaftAlgorithm |
algorithm
The Raft algorithm.
|
RaftLifecycle |
lifecycle
The RaftLifecycle object that this Raft node is tied to.
|
RaftTransport |
transport
The Raft transport logic.
|
| Constructor and Description |
|---|
EloquentRaftNode(RaftAlgorithm algorithm,
RaftTransport transport,
RaftLifecycle lifecycle)
The straightforward constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addErrorListener(RaftErrorListener errorListener)
Keeps track of an additional
RaftErrorListener in this class |
boolean |
bootstrap(boolean force)
Bootstrap this node of the cluster.
|
protected void |
clearErrorListeners()
Clears all the
RaftErrorListeners attached to this class. |
void |
close() |
void |
close(boolean allowClusterDeath)
This does an orderly shutdown of this member of the Raft cluster, stopping its heartbeats and removing it
from the cluster.
|
java.util.List<java.lang.String> |
errors()
Return any errors Raft has encountered.
|
boolean |
isAlive()
Returns true if we're currently alive, false if we've closed.
|
void |
registerFailsafe(RaftFailsafe failsafe)
Register a new failsafe to run occasionally on this node.
|
void |
registerShutdownHook(java.lang.Runnable shutdownHook)
This adds a hook to run before we shutdown this RaftNode.
|
protected void |
removeErrorListener(RaftErrorListener errorListener)
Stop listening from a specific
RaftErrorListener |
void |
start()
This begins the process of discovering and joining the Raft cluster as a member.
|
java.util.concurrent.CompletableFuture<java.lang.Boolean> |
submitTransition(byte[] transition)
Submit a transition to Raft.
|
public final RaftAlgorithm algorithm
public final RaftTransport transport
public final RaftLifecycle lifecycle
public EloquentRaftNode(RaftAlgorithm algorithm, RaftTransport transport, RaftLifecycle lifecycle)
protected void addErrorListener(RaftErrorListener errorListener)
RaftErrorListener in this classerrorListener - protected void removeErrorListener(RaftErrorListener errorListener)
RaftErrorListenererrorListener - The error listener to be removedprotected void clearErrorListeners()
RaftErrorListeners attached to this class.public void registerShutdownHook(java.lang.Runnable shutdownHook)
shutdownHook - The hook to run on shutdownpublic void start()
public boolean bootstrap(boolean force)
public java.util.concurrent.CompletableFuture<java.lang.Boolean> submitTransition(byte[] transition)
transition - The transition we are submitting.public java.util.List<java.lang.String> errors()
public boolean isAlive()
public void close(boolean allowClusterDeath)
WARNING: once closed, this cannot be reopened
allowClusterDeath - If true, allow the cluster to lose state and completely shut down.
Otherwise, we wait for another live node to show up before shutting
down (the default).public void close()
close in interface java.lang.AutoCloseableclose(boolean)public void registerFailsafe(RaftFailsafe failsafe)
failsafe - the one to register