public abstract class AbstractRaftActorBehavior extends Object implements RaftActorBehavior
Modifier and Type | Field and Description |
---|---|
protected RaftActorContext |
context
Information about the RaftActor whose behavior this class represents.
|
protected org.slf4j.Logger |
log
Used for message logging.
|
Modifier and Type | Method and Description |
---|---|
protected akka.actor.ActorRef |
actor()
Returns the actor associated with this behavior.
|
protected RaftActorBehavior |
appendEntries(akka.actor.ActorRef sender,
AppendEntries appendEntries)
Handles the common logic for the AppendEntries message and delegates handling to the derived class.
|
protected void |
applyLogToStateMachine(long index)
Applies the log entries up to the specified index that is known to be committed to the state machine.
|
protected boolean |
canGrantVote(RequestVote requestVote) |
protected boolean |
canStartElection() |
static RaftActorBehavior |
createBehavior(RaftActorContext context,
RaftState state) |
protected long |
currentTerm()
Returns the current election term.
|
protected scala.concurrent.duration.FiniteDuration |
electionDuration()
Returns a duration for election with an additional variance for randomness.
|
protected String |
getId() |
protected long |
getLogEntryIndex(long index)
Returns the actual index of the entry in replicated log for the given index or -1 if not found.
|
protected long |
getLogEntryOrSnapshotTerm(long index)
Returns the actual term of the entry in the replicated log for the given index or, if not present, returns the
snapshot term if the given index is in the snapshot or -1 otherwise.
|
protected long |
getLogEntryTerm(long index)
Returns the actual term of the entry in the replicated log for the given index or -1 if not found.
|
protected int |
getMajorityVoteCount(int numPeers) |
long |
getReplicatedToAllIndex()
Returns the index of the last log entry that has been replicated to all peers.
|
protected abstract RaftActorBehavior |
handleAppendEntries(akka.actor.ActorRef sender,
AppendEntries appendEntries)
Derived classes should not directly handle AppendEntries messages it
should let the base class handle it first.
|
protected abstract RaftActorBehavior |
handleAppendEntriesReply(akka.actor.ActorRef sender,
AppendEntriesReply appendEntriesReply)
Derived classes should not directly handle AppendEntriesReply messages it
should let the base class handle it first.
|
RaftActorBehavior |
handleMessage(akka.actor.ActorRef sender,
Object message)
Handle a message.
|
protected abstract RaftActorBehavior |
handleRequestVoteReply(akka.actor.ActorRef sender,
RequestVoteReply requestVoteReply)
Derived classes should not directly handle RequestVoteReply messages it
should let the base class handle it first.
|
protected RaftActorBehavior |
internalSwitchBehavior(RaftActorBehavior newBehavior) |
protected RaftActorBehavior |
internalSwitchBehavior(RaftState newState) |
protected long |
lastIndex()
Returns the index of the last entry in the log.
|
protected long |
lastTerm()
Returns the term of the last entry in the log.
|
protected String |
logName() |
protected void |
performSnapshotWithoutCapture(long snapshotCapturedIndex)
Performs a snapshot with no capture on the replicated log.
|
protected ClientRequestTracker |
removeClientRequestTracker(long logIndex)
Removes and returns the ClientRequestTracker for the specified log index.
|
protected RaftActorBehavior |
requestVote(akka.actor.ActorRef sender,
RequestVote requestVote)
Handles the logic for the RequestVote message that is common for all behaviors.
|
protected void |
scheduleElection(scala.concurrent.duration.FiniteDuration interval)
Schedule a new election.
|
void |
setReplicatedToAllIndex(long replicatedToAllIndex)
Sets the index of the last log entry that has been replicated to all peers.
|
RaftState |
state()
Returns the state associated with this behavior.
|
protected void |
stopElection()
Stops the currently scheduled election.
|
RaftActorBehavior |
switchBehavior(RaftActorBehavior behavior)
Closes the current behavior and switches to the specified behavior, if possible.
|
protected String |
votedFor()
Returns the id of the candidate that this server voted for in current term.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, getLeaderId, getLeaderPayloadVersion
protected final RaftActorContext context
protected final org.slf4j.Logger log
public static RaftActorBehavior createBehavior(RaftActorContext context, RaftState state)
public final RaftState state()
RaftActorBehavior
state
in interface RaftActorBehavior
protected final String logName()
public void setReplicatedToAllIndex(long replicatedToAllIndex)
RaftActorBehavior
setReplicatedToAllIndex
in interface RaftActorBehavior
replicatedToAllIndex
- the indexpublic long getReplicatedToAllIndex()
RaftActorBehavior
getReplicatedToAllIndex
in interface RaftActorBehavior
protected abstract RaftActorBehavior handleAppendEntries(akka.actor.ActorRef sender, AppendEntries appendEntries)
sender
- The actor that sent this messageappendEntries
- The AppendEntries messageprotected RaftActorBehavior appendEntries(akka.actor.ActorRef sender, AppendEntries appendEntries)
sender
- the ActorRef that sent the messageappendEntries
- the messageprotected abstract RaftActorBehavior handleAppendEntriesReply(akka.actor.ActorRef sender, AppendEntriesReply appendEntriesReply)
sender
- The actor that sent this messageappendEntriesReply
- The AppendEntriesReply messageprotected RaftActorBehavior requestVote(akka.actor.ActorRef sender, RequestVote requestVote)
sender
- the ActorRef that sent the messagerequestVote
- the messageprotected boolean canGrantVote(RequestVote requestVote)
protected abstract RaftActorBehavior handleRequestVoteReply(akka.actor.ActorRef sender, RequestVoteReply requestVoteReply)
sender
- The actor that sent this messagerequestVoteReply
- The RequestVoteReply messageprotected scala.concurrent.duration.FiniteDuration electionDuration()
protected void stopElection()
protected boolean canStartElection()
protected void scheduleElection(scala.concurrent.duration.FiniteDuration interval)
interval
- the duration after which we should trigger a new electionprotected long currentTerm()
protected String votedFor()
protected akka.actor.ActorRef actor()
protected long lastTerm()
protected long lastIndex()
protected ClientRequestTracker removeClientRequestTracker(long logIndex)
logIndex
- the log indexprotected long getLogEntryIndex(long index)
protected long getLogEntryTerm(long index)
protected long getLogEntryOrSnapshotTerm(long index)
protected void applyLogToStateMachine(long index)
index
- the log indexpublic RaftActorBehavior handleMessage(akka.actor.ActorRef sender, Object message)
RaftActorBehavior
handleMessage
in interface RaftActorBehavior
sender
- The sender of the messagemessage
- A message that needs to be processedpublic RaftActorBehavior switchBehavior(RaftActorBehavior behavior)
RaftActorBehavior
switchBehavior
in interface RaftActorBehavior
behavior
- the new behavior to switch toprotected RaftActorBehavior internalSwitchBehavior(RaftState newState)
protected RaftActorBehavior internalSwitchBehavior(RaftActorBehavior newBehavior)
protected int getMajorityVoteCount(int numPeers)
protected void performSnapshotWithoutCapture(long snapshotCapturedIndex)
snapshotCapturedIndex
- the index from which to clearprotected String getId()
Copyright © 2019 OpenDaylight. All rights reserved.