use of org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply in project controller by opendaylight.
the class ExampleRoleChangeListener method handleReceive.
@Override
protected void handleReceive(Object message) throws Exception {
if (message instanceof RegisterListener) {
// called by the scheduler at intervals to register any unregistered notifiers
sendRegistrationRequests();
} else if (message instanceof RegisterRoleChangeListenerReply) {
// called by the Notifier
handleRegisterRoleChangeListenerReply(getSender().path().toString());
} else if (message instanceof RoleChangeNotification) {
// called by the Notifier
RoleChangeNotification notification = (RoleChangeNotification) message;
LOG.info("Role Change Notification received for member:{}, old role:{}, new role:{}", notification.getMemberId(), notification.getOldRole(), notification.getNewRole());
// the apps dependent on such notifications can be called here
// TODO: add implementation here
}
}
use of org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply in project controller by opendaylight.
the class RoleChangeNotifierTest method testHandleRaftRoleChanged.
@Test
public void testHandleRaftRoleChanged() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
ActorRef shardActor = getTestActor();
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(new RoleChanged(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), shardActor);
// no notification should be sent as listener has not yet
// registered
assertNull(MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class));
// listener registers after role has been changed, ensure we
// sent the latest role change after a reply
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
assertNotNull(notification);
assertEquals(RaftState.Candidate.name(), notification.getOldRole());
assertEquals(RaftState.Leader.name(), notification.getNewRole());
}
};
}
use of org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply in project controller by opendaylight.
the class RoleChangeNotifierTest method testHandleRegisterRoleChangeListener.
@Test
public void testHandleRegisterRoleChangeListener() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListener";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
assertNull(notification);
}
};
}
Aggregations