use of org.glassfish.api.event.EventListener.Event in project Payara by payara.
the class AppServerStartup method stop.
@Override
public synchronized void stop() {
state.set(State.SHUTTING_DOWN);
if (env.getStatus() == ServerEnvironment.Status.stopped) {
// During shutdown because of shutdown hooks, we can be stopped multiple times.
// In such a case, ignore any subsequent stop operations.
logger.fine("Already stopped, so just returning");
return;
}
env.setStatus(ServerEnvironment.Status.stopping);
try {
events.send(new Event(EventTypes.PREPARE_SHUTDOWN), false);
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionDuringShutdown, e);
}
// deactivate the run level services
try {
proceedTo(InitRunLevel.VAL);
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionDuringShutdown, e);
}
// first send the shutdown event synchronously
env.setStatus(ServerEnvironment.Status.stopped);
try {
events.send(new Event(EventTypes.SERVER_SHUTDOWN), false);
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionDuringShutdown, e);
}
try {
runLevelController.proceedTo(0);
} catch (Exception e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionDuringShutdown, e);
}
logger.info(KernelLoggerInfo.shutdownFinished);
state.set(State.SHUT_DOWN);
// notify the server thread that we are done, so that it can come out.
if (serverThread != null) {
synchronized (serverThread) {
serverThread.notify();
}
try {
serverThread.join(0);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
use of org.glassfish.api.event.EventListener.Event 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