Search in sources :

Example 31 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class AbstractDataListenerSupport method onLeadershipChange.

@Override
void onLeadershipChange(boolean isLeader, boolean hasLeader) {
    log.debug("{}: onLeadershipChange, isLeader: {}, hasLeader : {}", persistenceId(), isLeader, hasLeader);
    final EnableNotification msg = new EnableNotification(isLeader, persistenceId());
    for (ActorSelection dataChangeListener : leaderOnlyListenerActors) {
        dataChangeListener.tell(msg, getSelf());
    }
    if (hasLeader) {
        for (DelayedListenerRegistration<L, M> reg : delayedListenerOnAllRegistrations) {
            reg.doRegistration(this);
        }
        delayedListenerOnAllRegistrations.clear();
    }
    if (isLeader) {
        for (DelayedListenerRegistration<L, M> reg : delayedListenerRegistrations) {
            reg.doRegistration(this);
        }
        delayedListenerRegistrations.clear();
    }
}
Also used : ActorSelection(akka.actor.ActorSelection) EnableNotification(org.opendaylight.controller.cluster.datastore.messages.EnableNotification)

Example 32 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class DataTreeChangeListenerSupport method doRegistration.

@Override
void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) {
    final ActorSelection listenerActor = processListenerRegistrationMessage(message);
    DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor);
    log().debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath());
    final ShardDataTree shardDataTree = getShard().getDataStore();
    shardDataTree.registerTreeChangeListener(message.getPath(), listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell(new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () -> removeListenerActor(listenerActor)), ActorRef.noSender()));
}
Also used : ActorSelection(akka.actor.ActorSelection) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)

Example 33 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class DataChangeListenerSupport method doRegistration.

@Override
void doRegistration(final RegisterChangeListener message, final ActorRef registrationActor) {
    final ActorSelection listenerActor = processListenerRegistrationMessage(message);
    AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> listener = new DataChangeListenerProxy(listenerActor);
    log().debug("{}: Registering for path {}", persistenceId(), message.getPath());
    final ShardDataTree shardDataTree = getShard().getDataStore();
    shardDataTree.registerDataChangeListener(message.getPath(), listener, message.getScope(), shardDataTree.readCurrentData(), registration -> registrationActor.tell(new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () -> removeListenerActor(listenerActor)), ActorRef.noSender()));
}
Also used : ActorSelection(akka.actor.ActorSelection) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 34 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ActorContextTest method testExecuteRemoteOperation.

@Test
public void testExecuteRemoteOperation() {
    new TestKit(getSystem()) {

        {
            ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
            ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));
            ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mock(Configuration.class));
            ActorSelection actor = actorContext.actorSelection(shardActorRef.path());
            Object out = actorContext.executeOperation(actor, "hello");
            assertEquals("hello", out);
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorSelection(akka.actor.ActorSelection) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) EchoActor(org.opendaylight.controller.cluster.raft.utils.EchoActor) TestKit(akka.testkit.javadsl.TestKit) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 35 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class AbstractClientHistoryTest method createActorContextMock.

protected static ActorContext createActorContextMock(final ActorSystem system, final ActorRef actor) {
    final ActorContext mock = mock(ActorContext.class);
    final Promise<PrimaryShardInfo> promise = new DefaultPromise<>();
    final ActorSelection selection = system.actorSelection(actor.path());
    final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
    promise.success(shardInfo);
    when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future());
    return mock;
}
Also used : ActorSelection(akka.actor.ActorSelection) DefaultPromise(scala.concurrent.impl.Promise.DefaultPromise) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext)

Aggregations

ActorSelection (akka.actor.ActorSelection)43 ActorRef (akka.actor.ActorRef)9 Test (org.junit.Test)6 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)4 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)4 InvalidActorNameException (akka.actor.InvalidActorNameException)3 Status (akka.actor.Status)3 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 ArrayList (java.util.ArrayList)3 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)3 AkkaException (akka.AkkaException)2 ActorIdentity (akka.actor.ActorIdentity)2 Identify (akka.actor.Identify)2 Failure (akka.actor.Status.Failure)2 Success (akka.actor.Status.Success)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)2