use of org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply in project controller by opendaylight.
the class DataChangeListenerRegistrationProxyTest method testCloseBeforeRegistration.
@Test
public void testCloseBeforeRegistration() {
new TestKit(getSystem()) {
{
ActorContext actorContext = mock(ActorContext.class);
String shardName = "shard-1";
final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(shardName, actorContext, mockListener);
doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
doReturn(getSystem()).when(actorContext).getActorSystem();
doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
doReturn(getSystem().actorSelection(getRef().path())).when(actorContext).actorSelection(getRef().path());
doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
Answer<Future<Object>> answer = invocation -> {
proxy.close();
return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(getRef()));
};
doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME), AsyncDataBroker.DataChangeScope.ONE);
expectMsgClass(duration("5 seconds"), CloseDataTreeNotificationListenerRegistration.class);
Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
proxy.close();
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method registerChangeListener.
@SuppressWarnings("checkstyle:IllegalCatch")
private Entry<MockDataTreeChangeListener, ActorSelection> registerChangeListener(final YangInstanceIdentifier path, final int expectedEvents) {
MockDataTreeChangeListener listener = new MockDataTreeChangeListener(expectedEvents);
ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH));
RegisterDataTreeNotificationListenerReply reply;
try {
reply = (RegisterDataTreeNotificationListenerReply) Await.result(Patterns.ask(shardActor, new RegisterDataTreeChangeListener(path, dclActor, false), new Timeout(5, TimeUnit.SECONDS)), Duration.create(5, TimeUnit.SECONDS));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return new SimpleEntry<>(listener, getSystem().actorSelection(reply.getListenerRegistrationPath()));
}
use of org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply in project controller by opendaylight.
the class AbstractDataListenerSupport method onMessage.
@Override
void onMessage(M message, boolean isLeader, boolean hasLeader) {
log.debug("{}: {} for {}, isLeader: {}, hasLeader: {}", persistenceId(), logName(), message, isLeader, hasLeader);
ActorRef registrationActor = createActor(DataTreeNotificationListenerRegistrationActor.props());
if (hasLeader && message.isRegisterOnAllInstances() || isLeader) {
doRegistration(message, registrationActor);
} else {
log.debug("{}: Shard is not the leader - delaying registration", persistenceId());
DelayedListenerRegistration<L, M> delayedReg = new DelayedListenerRegistration<>(message, registrationActor);
Collection<DelayedListenerRegistration<L, M>> delayedRegList;
if (message.isRegisterOnAllInstances()) {
delayedRegList = delayedListenerOnAllRegistrations;
} else {
delayedRegList = delayedListenerRegistrations;
}
delayedRegList.add(delayedReg);
registrationActor.tell(new DataTreeNotificationListenerRegistrationActor.SetRegistration(delayedReg, () -> delayedRegList.remove(delayedReg)), ActorRef.noSender());
}
log.debug("{}: {} sending reply, listenerRegistrationPath = {} ", persistenceId(), logName(), registrationActor.path());
tellSender(new RegisterDataTreeNotificationListenerReply(registrationActor));
}
use of org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply in project controller by opendaylight.
the class DataTreeChangeListenerProxy method doRegistration.
private void doRegistration(final ActorRef shard) {
Future<Object> future = actorContext.executeOperationAsync(shard, new RegisterDataTreeChangeListener(registeredPath, dataChangeListenerActor, getInstance() instanceof ClusteredDOMDataTreeChangeListener), actorContext.getDatastoreContext().getShardInitializationTimeout());
future.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object result) {
if (failure != null) {
LOG.error("{}: Failed to register DataTreeChangeListener {} at path {}", logContext(), getInstance(), registeredPath, failure);
} else {
RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply) result;
setListenerRegistrationActor(actorContext.actorSelection(reply.getListenerRegistrationPath()));
}
}
}, actorContext.getClientDispatcher());
}
use of org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply in project controller by opendaylight.
the class DataChangeListenerRegistrationProxy method doRegistration.
private void doRegistration(final ActorRef shard, final YangInstanceIdentifier path, final DataChangeScope scope) {
Future<Object> future = actorContext.executeOperationAsync(shard, new RegisterChangeListener(path, dataChangeListenerActor, scope, listener instanceof ClusteredDOMDataChangeListener), actorContext.getDatastoreContext().getShardInitializationTimeout());
future.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object result) {
if (failure != null) {
LOG.error("Failed to register DataChangeListener {} at path {}", listener, path.toString(), failure);
} else {
RegisterDataTreeNotificationListenerReply reply = (RegisterDataTreeNotificationListenerReply) result;
setListenerRegistrationActor(actorContext.actorSelection(reply.getListenerRegistrationPath()));
}
}
}, actorContext.getClientDispatcher());
}
Aggregations