Search in sources :

Example 1 with ListenerSubscriptionPair

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

Example 2 with ListenerSubscriptionPair

use of org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair 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 3 with ListenerSubscriptionPair

use of org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair in project mule by mulesoft.

the class Configuration method removeListener.

public synchronized void removeListener(NotificationListener listener) {
    dirty = true;
    Set<ListenerSubscriptionPair> toRemove = new HashSet<>();
    for (Object element : listenerSubscriptionPairs) {
        ListenerSubscriptionPair pair = (ListenerSubscriptionPair) element;
        if (pair.getListener().equals(listener)) {
            toRemove.add(pair);
        }
    }
    listenerSubscriptionPairs.removeAll(toRemove);
}
Also used : ListenerSubscriptionPair(org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair) HashSet(java.util.HashSet)

Aggregations

ListenerSubscriptionPair (org.mule.runtime.core.api.context.notification.ListenerSubscriptionPair)3 HashSet (java.util.HashSet)2 NotificationListener (org.mule.runtime.api.notification.NotificationListener)2 HashMap (java.util.HashMap)1 Notification (org.mule.runtime.api.notification.Notification)1 ServerNotificationManager (org.mule.runtime.core.api.context.notification.ServerNotificationManager)1