use of org.mule.runtime.api.notification.NotificationListener in project mule by mulesoft.
the class ServerNotificationsTestCase method testSyncNotificationException.
@Test
public void testSyncNotificationException() {
ServerNotificationManager manager = new ServerNotificationManager();
manager.setMuleContext(muleContext);
manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class);
Notification notification = mock(CustomNotification.class);
when(notification.isSynchronous()).thenReturn(true);
NotificationListener notificationListener = mock(CustomNotificationListener.class);
doThrow(new IllegalArgumentException()).when(notificationListener).onNotification(any(CustomNotification.class));
manager.addListener(notificationListener);
manager.fireNotification(notification);
verify(notificationListener, times(1)).onNotification(notification);
}
use of org.mule.runtime.api.notification.NotificationListener in project mule by mulesoft.
the class ServerNotificationsTestCase method testSyncNotificationError.
@Test
public void testSyncNotificationError() {
ServerNotificationManager manager = new ServerNotificationManager();
manager.setMuleContext(muleContext);
manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class);
Notification notification = mock(CustomNotification.class);
when(notification.isSynchronous()).thenReturn(true);
NotificationListener notificationListener = mock(CustomNotificationListener.class);
doThrow(new LinkageError()).when(notificationListener).onNotification(any(CustomNotification.class));
manager.addListener(notificationListener);
manager.fireNotification(notification);
verify(notificationListener, times(1)).onNotification(notification);
}
use of org.mule.runtime.api.notification.NotificationListener in project mule by mulesoft.
the class ServerNotificationManagerConfigurator method getMergedListeners.
protected Set<ListenerSubscriptionPair> getMergedListeners(ServerNotificationManager notificationManager) {
Set<ListenerSubscriptionPair> mergedListeners = new HashSet<>();
// Any singleton bean defined in spring that implements
// NotificationListener or a subclass.
Set<ListenerSubscriptionPair> adhocListeners = new HashSet<>();
for (String name : applicationContext.getBeanNamesForType(NotificationListener.class, false, true)) {
adhocListeners.add(new ListenerSubscriptionPair((NotificationListener<?>) applicationContext.getBean(name)));
}
if (notificationListeners != null) {
mergedListeners.addAll(notificationListeners);
for (ListenerSubscriptionPair candidate : adhocListeners) {
boolean explicityDefined = false;
for (ListenerSubscriptionPair explicitListener : notificationListeners) {
if (candidate.getListener().equals(explicitListener.getListener())) {
explicityDefined = true;
break;
}
}
if (!explicityDefined) {
mergedListeners.add(candidate);
}
}
} else {
mergedListeners.addAll(adhocListeners);
}
return mergedListeners;
}
use of org.mule.runtime.api.notification.NotificationListener in project mule by mulesoft.
the class ServerNotificationManagerConfigurator method initialise.
@Override
public void initialise() throws InitialisationException {
Map<String, Class<? extends Notification>> eventMap = new HashMap<>(EVENT_MAP);
Map<String, Class<? extends NotificationListener>> interfaceMap = new HashMap<>(INTERFACE_MAP);
ServerNotificationManager notificationManager = populateNotificationTypeMappings(eventMap, interfaceMap);
enableNotifications(notificationManager, eventMap, interfaceMap);
disableNotifications(notificationManager, eventMap, interfaceMap);
// ii) any singleton beans defined in spring that implement NotificationListener.
for (ListenerSubscriptionPair sub : getMergedListeners(notificationManager)) {
// Do this to avoid warnings when the Spring context is refreshed
if (!notificationManager.isListenerRegistered(sub.getListener())) {
notificationManager.addListenerSubscriptionPair(sub);
} else {
notificationManager.removeListener(sub.getListener());
notificationManager.addListenerSubscriptionPair(sub);
}
}
}
use of org.mule.runtime.api.notification.NotificationListener in project mule by mulesoft.
the class DefaultMuleContextBuilderTestCase method notificationManagerContainsTheCorrectInterfaces.
/**
* <p>
* After the mule context is built it has to contain the proper notification interfaces in the notification manager
* </p>
*/
@Test
public void notificationManagerContainsTheCorrectInterfaces() {
DefaultMuleContextBuilder builder = new DefaultMuleContextBuilder(APP);
builder.setMuleConfiguration(new MyMuleConfiguration());
builder.setLifecycleManager(new MyLifeCycleManager());
MuleContext muleContext = builder.buildMuleContext();
Map<Class<? extends NotificationListener>, Set<Class<? extends Notification>>> interfaces = muleContext.getNotificationManager().getInterfaceToTypes();
assertEquals(MuleContextNotification.class, interfaces.get(MuleContextNotificationListener.class).toArray()[0]);
assertEquals(RoutingNotification.class, interfaces.get(RoutingNotificationListener.class).toArray()[0]);
assertEquals(SecurityNotification.class, interfaces.get(SecurityNotificationListener.class).toArray()[0]);
assertEquals(ManagementNotification.class, interfaces.get(ManagementNotificationListener.class).toArray()[0]);
assertEquals(CustomNotification.class, interfaces.get(CustomNotificationListener.class).toArray()[0]);
assertEquals(ConnectionNotification.class, interfaces.get(ConnectionNotificationListener.class).toArray()[0]);
assertEquals(ExceptionNotification.class, interfaces.get(ExceptionNotificationListener.class).toArray()[0]);
assertEquals(TransactionNotification.class, interfaces.get(TransactionNotificationListener.class).toArray()[0]);
assertEquals(PipelineMessageNotification.class, interfaces.get(PipelineMessageNotificationListener.class).toArray()[0]);
assertEquals(AsyncMessageNotification.class, interfaces.get(AsyncMessageNotificationListener.class).toArray()[0]);
assertEquals(ClusterNodeNotification.class, interfaces.get(ClusterNodeNotificationListener.class).toArray()[0]);
}
Aggregations