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;
}
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);
}
}
}
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);
}
Aggregations