本文整理汇总了Java中org.opendaylight.controller.cluster.raft.messages.RaftRPC.getTerm方法的典型用法代码示例。如果您正苦于以下问题:Java RaftRPC.getTerm方法的具体用法?Java RaftRPC.getTerm怎么用?Java RaftRPC.getTerm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opendaylight.controller.cluster.raft.messages.RaftRPC
的用法示例。
在下文中一共展示了RaftRPC.getTerm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入方法依赖的package包/类
@Override
public RaftActorBehavior handleMessage(final ActorRef sender, final Object message) {
if (message instanceof ElectionTimeout || message instanceof TimeoutNow) {
return handleElectionTimeout(message);
}
if (appendEntriesMessageAssembler.handleMessage(message, actor())) {
return this;
}
if (!(message instanceof RaftRPC)) {
// The rest of the processing requires the message to be a RaftRPC
return null;
}
final RaftRPC rpc = (RaftRPC) message;
// If RPC request or response contains term T > currentTerm:
// set currentTerm = T, convert to follower (§5.1)
// This applies to all RPC messages and responses
if (rpc.getTerm() > context.getTermInformation().getCurrentTerm()) {
log.info("{}: Term {} in \"{}\" message is greater than follower's term {} - updating term",
logName(), rpc.getTerm(), rpc, context.getTermInformation().getCurrentTerm());
context.getTermInformation().updateAndPersist(rpc.getTerm(), null);
}
if (rpc instanceof InstallSnapshot) {
handleInstallSnapshot(sender, (InstallSnapshot) rpc);
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
return this;
}
if (!(rpc instanceof RequestVote) || canGrantVote((RequestVote) rpc)) {
restartLastLeaderMessageTimer();
scheduleElection(electionDuration());
}
return super.handleMessage(sender, rpc);
}
示例2: handleMessage
import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入方法依赖的package包/类
@Override
public RaftActorBehavior handleMessage(ActorRef sender, Object message) {
if (message instanceof ElectionTimeout) {
log.debug("{}: Received ElectionTimeout", logName());
if (votesRequired == 0) {
// If there are no peers then we should be a Leader
// We wait for the election timeout to occur before declare
// ourselves the leader. This gives enough time for a leader
// who we do not know about (as a peer)
// to send a message to the candidate
return internalSwitchBehavior(RaftState.Leader);
}
startNewTerm();
scheduleElection(electionDuration());
return this;
}
if (message instanceof RaftRPC) {
RaftRPC rpc = (RaftRPC) message;
log.debug("{}: RaftRPC message received {}, my term is {}", logName(), rpc,
context.getTermInformation().getCurrentTerm());
// If RPC request or response contains term T > currentTerm:
// set currentTerm = T, convert to follower (§5.1)
// This applies to all RPC messages and responses
if (rpc.getTerm() > context.getTermInformation().getCurrentTerm()) {
log.info("{}: Term {} in \"{}\" message is greater than Candidate's term {} - switching to Follower",
logName(), rpc.getTerm(), rpc, context.getTermInformation().getCurrentTerm());
context.getTermInformation().updateAndPersist(rpc.getTerm(), null);
// The raft paper does not say whether or not a Candidate can/should process a RequestVote in
// this case but doing so gains quicker convergence when the sender's log is more up-to-date.
if (message instanceof RequestVote) {
super.handleMessage(sender, message);
}
return internalSwitchBehavior(RaftState.Follower);
}
}
return super.handleMessage(sender, message);
}
示例3: handleMessage
import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入方法依赖的package包/类
@Override
public RaftActorBehavior handleMessage(final ActorRef sender, final Object message) {
Preconditions.checkNotNull(sender, "sender should not be null");
if (appendEntriesMessageSlicer.handleMessage(message)) {
return this;
}
if (message instanceof RaftRPC) {
RaftRPC rpc = (RaftRPC) message;
// If RPC request or response contains term T > currentTerm:
// set currentTerm = T, convert to follower (§5.1)
// This applies to all RPC messages and responses
if (rpc.getTerm() > context.getTermInformation().getCurrentTerm()) {
log.info("{}: Term {} in \"{}\" message is greater than leader's term {} - switching to Follower",
logName(), rpc.getTerm(), rpc, context.getTermInformation().getCurrentTerm());
context.getTermInformation().updateAndPersist(rpc.getTerm(), null);
// This is a special case. Normally when stepping down as leader we don't process and reply to the
// RaftRPC as per raft. But if we're in the process of transferring leadership and we get a
// RequestVote, process the RequestVote before switching to Follower. This enables the requesting
// candidate node to be elected the leader faster and avoids us possibly timing out in the Follower
// state and starting a new election and grabbing leadership back before the other candidate node can
// start a new election due to lack of responses. This case would only occur if there isn't a majority
// of other nodes available that can elect the requesting candidate. Since we're transferring
// leadership, we should make every effort to get the requesting node elected.
if (message instanceof RequestVote && context.getRaftActorLeadershipTransferCohort() != null) {
log.debug("{}: Leadership transfer in progress - processing RequestVote", logName());
super.handleMessage(sender, message);
}
return internalSwitchBehavior(RaftState.Follower);
}
}
if (message instanceof SendHeartBeat) {
beforeSendHeartbeat();
sendHeartBeat();
scheduleHeartBeat(context.getConfigParams().getHeartBeatInterval());
} else if (message instanceof SendInstallSnapshot) {
SendInstallSnapshot sendInstallSnapshot = (SendInstallSnapshot) message;
setSnapshot(new SnapshotHolder(sendInstallSnapshot.getSnapshot(), sendInstallSnapshot.getSnapshotBytes()));
sendInstallSnapshot();
} else if (message instanceof Replicate) {
replicate((Replicate) message);
} else if (message instanceof InstallSnapshotReply) {
handleInstallSnapshotReply((InstallSnapshotReply) message);
} else if (message instanceof CheckConsensusReached) {
possiblyUpdateCommitIndex();
} else {
return super.handleMessage(sender, message);
}
return this;
}