class RaftNode[A] extends RaftMessageHandler[A] with TimerCallback[RaftNodeResult[A]] with AutoCloseable
The place where the different pieces which represent a Raft Node come together -- the glue code.
I've looked at this a few different ways, but ultimately found this abstraction here to be the most readable, and follows most closely what's laid out in the raft spec.
It's not too generic/abstracted, but quite openly just orchestrates the pieces/interactions of the inputs into a raft node.
- Self Type
- RaftNode[A]
- Alphabetic
- By Inheritance
- RaftNode
- AutoCloseable
- TimerCallback
- RaftMessageHandler
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new RaftNode(persistentState: PersistentState, log: RaftLog[A], timers: Timers, cluster: RaftCluster, initialState: NodeState, maxAppendSize: Int, initialTimerCallback: TimerCallback[_] = null, roleCallback: RoleCallback = RoleCallback.NoOp)
Type Members
-
type
Result = RaftNodeResult[A]
- Definition Classes
- RaftMessageHandler
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
appendIfLeader(data: Array[A]): NodeAppendResult[A]
Exposes this as a means for generating an AddressedRequest of messages together with the append result from the leader's log
Exposes this as a means for generating an AddressedRequest of messages together with the append result from the leader's log
- data
the data to append
- returns
the append result coupled w/ the append request to send if this node is the leader
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def cancelReceiveHeartbeat(): Unit
- def cancelSendHeartbeat(): Unit
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
close(): Unit
- Definition Classes
- RaftNode → AutoCloseable
- val cluster: RaftCluster
- final def createAppendFor(data: A, theRest: A*)(implicit tag: ClassTag[A]): Result
- def currentTerm(): Term
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
handleMessage(from: NodeId, msg: RequestOrResponse[A]): Result
Applies requests and responses coming to the node state and replies w/ any resulting messages
Applies requests and responses coming to the node state and replies w/ any resulting messages
- from
the node from which this message is received
- msg
the Raft message
- returns
and resulting messages (requests or responses)
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val log: RaftLog[A]
- val maxAppendSize: Int
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nodeId: NodeId
- returns
the ID of this node in the cluster
- Definition Classes
- RaftNode → RaftMessageHandler
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def onAppendData[P[_]](request: AppendData[A, P]): NodeAppendResult[A]
- def onAppendEntries(from: NodeId, append: AppendEntries[A]): AppendEntriesResponse
-
def
onAppendEntriesResponse(from: NodeId, appendResponse: AppendEntriesResponse): LeaderCommittedResult[A]
We're either the leader and should update our peer view/commit log, or aren't and should ignore it
We're either the leader and should update our peer view/commit log, or aren't and should ignore it
- returns
the committed log coords resulting from having applied this response and the state output (either a no-op or a subsequent AppendEntries request)
- def onBecomeCandidateOrLeader(): AddressedRequest[A]
- def onBecomeFollower(newLeader: Option[NodeId], newTerm: Term): Unit
- def onBecomeLeader(): AddressedRequest[A]
-
def
onMessage(input: RaftMessage[A]): Result
- returns
the response
- Definition Classes
- RaftNode → RaftMessageHandler
-
def
onReceiveHeartbeatTimeout(): AddressedRequest[A]
- Definition Classes
- RaftNode → TimerCallback
- def onRequest(from: NodeId, request: RaftRequest[A]): RaftResponse
-
def
onRequestVote(from: NodeId, forRequest: RequestVote): RequestVoteResponse
Create a reply to the given vote request.
Create a reply to the given vote request.
NOTE: Whatever the actual node 'A' is, it is expected that, upon a successful reply, it updates it's own term and writes down (remembers) that it voted in this term so as not to double-vote should this node crash.
- forRequest
the data from the vote request
- returns
the RequestVoteResponse
- def onRequestVoteResponse(from: NodeId, voteResponse: RequestVoteResponse): Result
-
def
onResponse(from: NodeId, reply: RaftResponse): Result
Handle a response coming from 'from'
Handle a response coming from 'from'
- from
the originating node
- reply
the response
- returns
any messages resulting from having processed this response
-
def
onSendHeartbeatTimeout(): Result
- Definition Classes
- RaftNode → TimerCallback
- def onTimerMessage(timeout: TimerMessage): Result
- val persistentState: PersistentState
-
def
resetReceiveHeartbeat(): CancelT
This is NOT intended to be called directly, but is managed internally
This is NOT intended to be called directly, but is managed internally
- returns
the cancellable timer result.
- val roleCallback: RoleCallback
- def state(): NodeState
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- val timerCallback: TimerCallback[_1] forSome {type _1 >: _$1 with RaftNodeResult[A], type _$1}
- val timers: Timers
-
def
toString(): String
- Definition Classes
- RaftNode → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withCluster(newCluster: RaftCluster): RaftNode[A]
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
a convenience builder method to create a new raft node w/ the given cluster
- returns
a new node state
-
def
withLog(newLog: RaftLog[A]): RaftNode[A]
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
a convenience builder method to create a new raft node w/ the given raft log
- returns
a new node state
-
def
withRoleCallback(newRoleCallback: RoleCallback): RaftNode[A]
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
Adds the given callback to this node to be invoked whenever a RoleEvent takes place
- returns
a new RaftNode w/ the given callback added
-
def
withRoleCallback(f: (RoleEvent) ⇒ Unit): RaftNode[A]
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
A convenience method for exposing 'withRoleCallback' with a function instead of a RoleCallback, so users can invoke via:
val initial : RaftNode[T] = ... initial.withRoleCallback { event => // do something w/ the event here println(event) }
- f
the callback function
- returns
a new RaftNode w/ the given callback added
-
def
withTimerCallback(newTimerCallback: TimerCallback[_]): RaftNode[A]
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
As this function returns a new node, care should be taken that it is used correctly in setting up the raft cluster; 'correctly' meaning that the returned instance is the one used to to communicate w/ the other nodes, as opposed to an old reference.
- newTimerCallback
the timer callback
- returns
a copy of thew RaftNode which uses the given timer callback