use of org.mule.runtime.core.api.context.notification.ServerNotificationManager in project mule by mulesoft.
the class DefaultMuleContextTestCase method callDisposeIfInitFails.
@Test
public void callDisposeIfInitFails() throws Exception {
ServerNotificationManager mockNotificationManager = mock(ServerNotificationManager.class);
doThrow(MuleRuntimeException.class).when(mockNotificationManager).initialise();
DefaultMuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder(APP);
muleContextBuilder.setLifecycleManager(new MuleContextLifecycleManager());
muleContextBuilder.setNotificationManager(mockNotificationManager);
DefaultMuleContext defaultMuleContext = (DefaultMuleContext) muleContextBuilder.buildMuleContext();
try {
defaultMuleContext.initialise();
fail("exception expected");
} catch (Exception e) {
verify(mockNotificationManager).dispose();
}
}
use of org.mule.runtime.core.api.context.notification.ServerNotificationManager in project mule by mulesoft.
the class DomainMuleContextBuilder method createNotificationManager.
@Override
protected ServerNotificationManager createNotificationManager() {
ServerNotificationManager manager = new ServerNotificationManager();
manager.addInterfaceToType(MuleContextNotificationListener.class, MuleContextNotification.class);
manager.addInterfaceToType(SecurityNotificationListener.class, SecurityNotification.class);
manager.addInterfaceToType(ManagementNotificationListener.class, ManagementNotification.class);
manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class);
manager.addInterfaceToType(ConnectionNotificationListener.class, ConnectionNotification.class);
manager.addInterfaceToType(ExceptionNotificationListener.class, ExceptionNotification.class);
manager.addInterfaceToType(ClusterNodeNotificationListener.class, ClusterNodeNotification.class);
manager.addInterfaceToType(ExceptionNotificationListener.class, ExtensionNotification.class);
return manager;
}
use of org.mule.runtime.core.api.context.notification.ServerNotificationManager 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.core.api.context.notification.ServerNotificationManager in project mule by mulesoft.
the class ServerNotificationManagerConfigurator method populateNotificationTypeMappings.
public ServerNotificationManager populateNotificationTypeMappings(Map<String, Class<? extends Notification>> eventMap, Map<String, Class<? extends NotificationListener>> interfaceMap) throws InitialisationException {
Map<String, NotificationsProvider> providersMap = new HashMap<>();
for (NotificationsProvider provider : registry.lookupAllByType(NotificationsProvider.class)) {
for (Entry<String, Pair<Class<? extends Notification>, Class<? extends NotificationListener>>> entry : provider.getEventListenerMapping().entrySet()) {
final String notificationType = entry.getKey();
if (!notificationType.matches("[a-zA-Z]+:[A-Z\\-]+")) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' doesn't comply with the '[artifactID]:[NOTIFICATION-ID]' format", notificationType, provider.toString()), this);
}
if (eventMap.containsKey(notificationType)) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' is already declared for another artifact in provider '%s'.", notificationType, provider.toString(), eventMap.get(notificationType)), this);
}
eventMap.put(notificationType, entry.getValue().getFirst());
interfaceMap.put(notificationType, entry.getValue().getSecond());
providersMap.put(notificationType, provider);
}
}
ServerNotificationManager notificationManager = muleContext.getNotificationManager();
if (dynamic != null) {
notificationManager.setNotificationDynamic(dynamic.booleanValue());
}
return notificationManager;
}
Aggregations