Search in sources :

Example 6 with Event

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);
        }
    }
}
Also used : Event(org.glassfish.api.event.EventListener.Event) InstanceLifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent) TimeoutException(java.util.concurrent.TimeoutException) GlassFishException(org.glassfish.embeddable.GlassFishException)

Example 7 with Event

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);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Event(org.glassfish.api.event.EventListener.Event) RestrictTo(org.glassfish.api.event.RestrictTo) EventTypes(org.glassfish.api.event.EventTypes) DeploymentException(org.glassfish.deployment.common.DeploymentException) EventListener(org.glassfish.api.event.EventListener) Method(java.lang.reflect.Method)

Aggregations

Event (org.glassfish.api.event.EventListener.Event)7 File (java.io.File)3 IOException (java.io.IOException)3 ActionReport (org.glassfish.api.ActionReport)3 com.sun.enterprise.config.serverbeans (com.sun.enterprise.config.serverbeans)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)2 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)2 LocalStringManagerImpl (com.sun.enterprise.util.LocalStringManagerImpl)2 FileUtils (com.sun.enterprise.util.io.FileUtils)2 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)2 PayaraExecutorService (fish.payara.nucleus.executorservice.PayaraExecutorService)2 ApplicationState (fish.payara.nucleus.hotdeploy.ApplicationState)2 HotDeployService (fish.payara.nucleus.hotdeploy.HotDeployService)2 PropertyVetoException (java.beans.PropertyVetoException)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2