当前位置: 首页>>代码示例>>Java>>正文


Java RaftRPC.getTerm方法代码示例

本文整理汇总了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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:41,代码来源:Follower.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:49,代码来源:Candidate.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:57,代码来源:AbstractLeader.java


注:本文中的org.opendaylight.controller.cluster.raft.messages.RaftRPC.getTerm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。