Search in sources :

Example 1 with ServerNotificationManager

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();
    }
}
Also used : MuleContextLifecycleManager(org.mule.runtime.core.internal.lifecycle.MuleContextLifecycleManager) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Test(org.junit.Test)

Example 2 with ServerNotificationManager

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;
}
Also used : ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager)

Example 3 with ServerNotificationManager

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ListenerSubscriptionPair(org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair) Notification(org.mule.runtime.api.notification.Notification) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) NotificationListener(org.mule.runtime.api.notification.NotificationListener)

Example 4 with ServerNotificationManager

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;
}
Also used : HashMap(java.util.HashMap) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ServerNotificationManager(org.mule.runtime.core.api.context.notification.ServerNotificationManager) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) ListenerSubscriptionPair(org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair) Pair(org.mule.runtime.api.util.Pair)

Aggregations

ServerNotificationManager (org.mule.runtime.core.api.context.notification.ServerNotificationManager)4 HashMap (java.util.HashMap)2 ListenerSubscriptionPair (org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair)2 Test (org.junit.Test)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Notification (org.mule.runtime.api.notification.Notification)1 NotificationListener (org.mule.runtime.api.notification.NotificationListener)1 Pair (org.mule.runtime.api.util.Pair)1 NotificationsProvider (org.mule.runtime.core.api.context.notification.NotificationsProvider)1 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)1 MuleContextLifecycleManager (org.mule.runtime.core.internal.lifecycle.MuleContextLifecycleManager)1