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


Java FindLeader类代码示例

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


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

示例1: waitUntilLeader

import org.opendaylight.controller.cluster.raft.client.messages.FindLeader; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
public static void waitUntilLeader(ActorRef actorRef) {
    FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
    for (int i = 0; i < 20 * 5; i++) {
        Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
        try {
            final Optional<String> maybeLeader = ((FindLeaderReply)Await.result(future, duration)).getLeaderActor();
            if (maybeLeader.isPresent()) {
                return;
            }
        } catch (Exception e) {
            LOG.error("FindLeader failed", e);
        }

        Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    }

    Assert.fail("Leader not found for actorRef " + actorRef.path());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:RaftActorTestKit.java

示例2: run

import org.opendaylight.controller.cluster.raft.client.messages.FindLeader; //导入依赖的package包/类
@Override
public void run() {
    final Future<Object> ask = Patterns.ask(shard, FindLeader.INSTANCE, context.getOperationTimeout());

    ask.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(final Throwable throwable, final Object findLeaderReply) throws Throwable {
            if (throwable != null) {
                tryReschedule(throwable);
            } else {
                final FindLeaderReply findLeader = (FindLeaderReply) findLeaderReply;
                final java.util.Optional<String> leaderActor = findLeader.getLeaderActor();
                if (leaderActor.isPresent()) {
                    // leader is found, backend seems ready, check if the frontend is ready
                    LOG.debug("{} - Leader for config shard is ready. Ending lookup.",
                            clusterWrapper.getCurrentMemberName());
                    replyTo.tell(new Status.Success(null), noSender());
                } else {
                    tryReschedule(null);
                }
            }
        }
    }, system.dispatcher());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:25,代码来源:ShardedDataTreeActor.java

示例3: handleCommand

import org.opendaylight.controller.cluster.raft.client.messages.FindLeader; //导入依赖的package包/类
/**
 * Handles a message.
 *
 * @deprecated This method is not final for testing purposes. DO NOT OVERRIDE IT, override
 * {@link #handleNonRaftCommand(Object)} instead.
 */
@Deprecated
@Override
// FIXME: make this method final once our unit tests do not need to override it
protected void handleCommand(final Object message) {
    if (serverConfigurationSupport.handleMessage(message, getSender())) {
        return;
    }
    if (snapshotSupport.handleSnapshotMessage(message, getSender())) {
        return;
    }
    if (message instanceof ApplyState) {
        ApplyState applyState = (ApplyState) message;

        if (!hasFollowers()) {
            // for single node, the capture should happen after the apply state
            // as we delete messages from the persistent journal which have made it to the snapshot
            // capturing the snapshot before applying makes the persistent journal and snapshot out of sync
            // and recovery shows data missing
            context.getReplicatedLog().captureSnapshotIfReady(applyState.getReplicatedLogEntry());

            context.getSnapshotManager().trimLog(context.getLastApplied());
        }

        possiblyHandleBehaviorMessage(message);
    } else if (message instanceof ApplyJournalEntries) {
        ApplyJournalEntries applyEntries = (ApplyJournalEntries) message;
        LOG.debug("{}: Persisting ApplyJournalEntries with index={}", persistenceId(), applyEntries.getToIndex());

        persistence().persistAsync(applyEntries, NoopProcedure.instance());

    } else if (message instanceof FindLeader) {
        getSender().tell(
            new FindLeaderReply(getLeaderAddress()),
            getSelf()
        );
    } else if (message instanceof GetOnDemandRaftState) {
        onGetOnDemandRaftStats();
    } else if (message instanceof InitiateCaptureSnapshot) {
        captureSnapshot();
    } else if (message instanceof SwitchBehavior) {
        switchBehavior((SwitchBehavior) message);
    } else if (message instanceof LeaderTransitioning) {
        onLeaderTransitioning((LeaderTransitioning)message);
    } else if (message instanceof Shutdown) {
        onShutDown();
    } else if (message instanceof Runnable) {
        ((Runnable)message).run();
    } else if (message instanceof NoopPayload) {
        persistData(null, null, (NoopPayload) message, false);
    } else if (message instanceof RequestLeadership) {
        onRequestLeadership((RequestLeadership) message);
    } else if (!possiblyHandleBehaviorMessage(message)) {
        handleNonRaftCommand(message);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:62,代码来源:RaftActor.java

示例4: testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration

import org.opendaylight.controller.cluster.raft.client.messages.FindLeader; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration() throws Exception {
    final CountDownLatch onFirstElectionTimeout = new CountDownLatch(1);
    final CountDownLatch onChangeListenerRegistered = new CountDownLatch(1);
    final Creator<Shard> creator = new Creator<Shard>() {
        boolean firstElectionTimeout = true;

        @Override
        public Shard create() throws Exception {
            return new Shard(newShardBuilder()) {
                @Override
                public void handleCommand(final Object message) {
                    if (message instanceof ElectionTimeout && firstElectionTimeout) {
                        firstElectionTimeout = false;
                        final ActorRef self = getSelf();
                        new Thread(() -> {
                            Uninterruptibles.awaitUninterruptibly(
                                    onChangeListenerRegistered, 5, TimeUnit.SECONDS);
                            self.tell(message, self);
                        }).start();

                        onFirstElectionTimeout.countDown();
                    } else {
                        super.handleCommand(message);
                    }
                }
            };
        }
    };

    setupInMemorySnapshotStore();

    final YangInstanceIdentifier path = TestModel.TEST_PATH;
    final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
    final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, path),
            "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration-DataChangeListener");

    final TestActorRef<Shard> shard = actorFactory.createTestActor(
            Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
            "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration");

    new ShardTestKit(getSystem()) {
        {
            assertEquals("Got first ElectionTimeout", true, onFirstElectionTimeout.await(5, TimeUnit.SECONDS));

            shard.tell(new RegisterDataTreeChangeListener(path, dclActor, false), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"),
                    RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath());

            shard.tell(FindLeader.INSTANCE, getRef());
            final FindLeaderReply findLeadeReply = expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
            assertFalse("Expected the shard not to be the leader", findLeadeReply.getLeaderActor().isPresent());

            onChangeListenerRegistered.countDown();

            // TODO: investigate why we do not receive data chage events
            listener.waitForChangeEvents();
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:63,代码来源:ShardTest.java


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