use of org.glassfish.api.event.EventListener in project Payara by payara.
the class EventsImpl method send.
@Override
public void send(final Event event, boolean asynchronously) {
List<EventListener> l = new ArrayList<EventListener>();
l.addAll(listeners);
for (final EventListener listener : l) {
Method m = null;
try {
// check if the listener is interested with his event.
m = listener.getClass().getMethod("event", Event.class);
} catch (Throwable ex) {
// We need to catch Throwable, otherwise we can server not to
// shutdown when the following happens:
// Assume a bundle which has registered a event listener
// has been uninstalled without unregistering the listener.
// listener.getClass() refers to a class of such an uninstalled
// bundle. If framework has been refreshed, then the
// classloader can't be used further to load any classes.
// As a result, an exception like NoClassDefFoundError is thrown
// from getMethod.
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionSendEvent, ex);
}
if (m != null) {
RestrictTo fooBar = m.getParameterTypes()[0].getAnnotation(RestrictTo.class);
if (fooBar != null) {
EventTypes interested = EventTypes.create(fooBar.value());
if (!event.is(interested)) {
continue;
}
}
}
if (asynchronously) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
listener.event(event);
} catch (Throwable e) {
logger.log(Level.WARNING, KernelLoggerInfo.exceptionDispatchEvent, e);
}
}
});
} else {
try {
listener.event(event);
} catch (DeploymentException de) {
// we re-throw the exception to abort the deployment
throw de;
} catch (Throwable e) {
logger.log(Level.WARNING, KernelLoggerInfo.exceptionDispatchEvent, e);
}
}
}
}
Aggregations