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


Java RaftRPC类代码示例

本文整理汇总了Java中org.opendaylight.controller.cluster.raft.messages.RaftRPC的典型用法代码示例。如果您正苦于以下问题:Java RaftRPC类的具体用法?Java RaftRPC怎么用?Java RaftRPC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RaftRPC类属于org.opendaylight.controller.cluster.raft.messages包,在下文中一共展示了RaftRPC类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertStateChangesToFollowerWhenRaftRPCHasNewerTerm

import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入依赖的package包/类
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(final MockRaftActorContext actorContext,
        final ActorRef actorRef, final RaftRPC rpc) {

    Payload payload = new MockRaftActorContext.MockPayload("");
    setLastLogEntry(actorContext, 1, 0, payload);
    actorContext.getTermInformation().update(1, "test");

    RaftActorBehavior origBehavior = createBehavior(actorContext);
    RaftActorBehavior raftBehavior = origBehavior.handleMessage(actorRef, rpc);

    assertEquals("New raft state", RaftState.Follower, raftBehavior.state());
    assertEquals("New election term", rpc.getTerm(), actorContext.getTermInformation().getCurrentTerm());

    origBehavior.close();
    raftBehavior.close();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:AbstractRaftActorBehaviorTest.java

示例2: 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

示例3: assertStateChangesToFollowerWhenRaftRPCHasNewerTerm

import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入依赖的package包/类
@Override
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(final MockRaftActorContext actorContext,
        final ActorRef actorRef, final RaftRPC rpc) {
    super.assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, actorRef, rpc);
    if (rpc instanceof RequestVote) {
        assertEquals("New votedFor", ((RequestVote)rpc).getCandidateId(),
                actorContext.getTermInformation().getVotedFor());
    } else {
        assertEquals("New votedFor", null, actorContext.getTermInformation().getVotedFor());
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:CandidateTest.java

示例4: testElectionScheduledWhenAnyRaftRPCReceived

import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入依赖的package包/类
@Test
public void testElectionScheduledWhenAnyRaftRPCReceived() {
    MockRaftActorContext context = createActorContext();
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, new RaftRPC() {
        private static final long serialVersionUID = 1L;

        @Override
        public long getTerm() {
            return 100;
        }
    });
    verify(follower).scheduleElection(any(FiniteDuration.class));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:15,代码来源:FollowerTest.java

示例5: assertStateChangesToFollowerWhenRaftRPCHasNewerTerm

import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入依赖的package包/类
@Override
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(final MockRaftActorContext actorContext,
        final ActorRef actorRef, final RaftRPC rpc) {
    super.assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, actorRef, rpc);

    String expVotedFor = rpc instanceof RequestVote ? ((RequestVote)rpc).getCandidateId() : null;
    assertEquals("New votedFor", expVotedFor, actorContext.getTermInformation().getVotedFor());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:9,代码来源:FollowerTest.java

示例6: 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

示例7: 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

示例8: assertStateChangesToFollowerWhenRaftRPCHasNewerTerm

import org.opendaylight.controller.cluster.raft.messages.RaftRPC; //导入依赖的package包/类
@Override
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(final MockRaftActorContext actorContext,
        final ActorRef actorRef, final RaftRPC rpc) {
    super.assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(actorContext, actorRef, rpc);
    assertEquals("New votedFor", null, actorContext.getTermInformation().getVotedFor());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:7,代码来源:LeaderTest.java


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