Java Code Examples for org.apache.catalina.LifecycleEvent#getLifecycle()

The following examples show how to use org.apache.catalina.LifecycleEvent#getLifecycle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Context context = (Context) event.getLifecycle();
        if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
            context.setConfigured(true);

            // Process annotations
            WebAnnotationSet.loadApplicationAnnotations(context);

            // LoginConfig is required to process @ServletSecurity
            // annotations
            if (context.getLoginConfig() == null) {
                context.setLoginConfig(new LoginConfig("NONE", null, null, null));
                context.getPipeline().addValve(new NonLoginAuthenticator());
            }
        }
    } catch (ClassCastException e) {
    }
}
 
Example 2
Source File: HostConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void lifecycleEvent(LifecycleEvent event) {
    if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
        // The context has stopped.
        Context context = (Context) event.getLifecycle();

        // Remove the old expanded WAR.
        ExpandWar.delete(toDelete);

        // Reset the docBase to trigger re-expansion of the WAR.
        context.setDocBase(newDocBase);

        // Remove this listener from the Context else it will run every
        // time the Context is stopped.
        context.removeLifecycleListener(this);
    }
}
 
Example 3
Source File: EngineConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
 
Example 4
Source File: UserConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Process the START event for an associated Host.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the host we are associated with
    try {
        host = (Host) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
 
Example 5
Source File: EngineConfig.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
 
Example 6
Source File: Tomcat.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Context context = (Context) event.getLifecycle();
        if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
            context.setConfigured(true);
        }
        // LoginConfig is required to process @ServletSecurity
        // annotations
        if (context.getLoginConfig() == null) {
            context.setLoginConfig(
                    new LoginConfig("NONE", null, null, null));
            context.getPipeline().addValve(new NonLoginAuthenticator());
        }
    } catch (ClassCastException e) {
        return;
    }
}
 
Example 7
Source File: Tomcat.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Context context = (Context) event.getLifecycle();
        if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
            context.setConfigured(true);
        }
        // LoginConfig is required to process @ServletSecurity
        // annotations
        if (context.getLoginConfig() == null) {
            context.setLoginConfig(
                    new LoginConfig("NONE", null, null, null));
            context.getPipeline().addValve(new NonLoginAuthenticator());
        }
    } catch (ClassCastException e) {
        return;
    }
}
 
Example 8
Source File: HostConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void lifecycleEvent(LifecycleEvent event) {
    if (event.getType() == Lifecycle.AFTER_STOP_EVENT) {
        // The context has stopped.
        Context context = (Context) event.getLifecycle();

        // Remove the old expanded WAR.
        ExpandWar.delete(toDelete);

        // Reset the docBase to trigger re-expansion of the WAR.
        context.setDocBase(newDocBase);

        // Remove this listener from the Context else it will run every
        // time the Context is stopped.
        context.removeLifecycleListener(this);
    }
}
 
Example 9
Source File: EngineConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
 
Example 10
Source File: UserConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the START event for an associated Host.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the host we are associated with
    try {
        host = (Host) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
 
Example 11
Source File: GlobalResourcesLifecycleListener.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Primary entry point for startup and shutdown events.
 *
 * @param event The event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    if (Lifecycle.START_EVENT.equals(event.getType())) {
        component = event.getLifecycle();
        createMBeans();
    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
        destroyMBeans();
        component = null;
    }

}
 
Example 12
Source File: OpenEJBNamingContextListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void lifecycleEvent(final LifecycleEvent event) {
    if (event.getLifecycle() != standardServer) {
        return;
    }

    if (Lifecycle.START_EVENT.equals(event.getType())) {
        start();

    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {

        stop();
    }
}
 
Example 13
Source File: ThreadLocalLeakPreventionListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Listens for {@link LifecycleEvent} for the start of the {@link Server} to
 * initialize itself and then for after_stop events of each {@link Context}.
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Lifecycle lifecycle = event.getLifecycle();
        if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // when the server starts, we register ourself as listener for
            // all context
            // as well as container event listener so that we know when new
            // Context are deployed
            Server server = (Server) lifecycle;
            registerListenersForServer(server);
        }

        if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // Server is shutting down, so thread pools will be shut down so
            // there is no need to clean the threads
            serverStopping = true;
        }

        if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Context) {
            stopIdleThreads((Context) lifecycle);
        }
    } catch (Exception e) {
        String msg =
            sm.getString(
                "threadLocalLeakPreventionListener.lifecycleEvent.error",
                event);
        log.error(msg, e);
    }
}
 
Example 14
Source File: GlobalResourcesLifecycleListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Primary entry point for startup and shutdown events.
 *
 * @param event The event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    if (Lifecycle.START_EVENT.equals(event.getType())) {
        component = event.getLifecycle();
        createMBeans();
    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
        destroyMBeans();
        component = null;
    }

}
 
Example 15
Source File: ContextConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Process events for an associated Context.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the context we are associated with
    try {
        context = (Context) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("contextConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
        configureStart();
    } else if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
        beforeStart();
    } else if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
        // Restore docBase for management tools
        if (originalDocBase != null) {
            context.setDocBase(originalDocBase);
        }
    } else if (event.getType().equals(Lifecycle.CONFIGURE_STOP_EVENT)) {
        configureStop();
    } else if (event.getType().equals(Lifecycle.AFTER_INIT_EVENT)) {
        init();
    } else if (event.getType().equals(Lifecycle.AFTER_DESTROY_EVENT)) {
        destroy();
    }

}
 
Example 16
Source File: HostConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Process the START event for an associated Host.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the host we are associated with
    try {
        host = (Host) event.getLifecycle();
        if (host instanceof StandardHost) {
            setCopyXML(((StandardHost) host).isCopyXML());
            setDeployXML(((StandardHost) host).isDeployXML());
            setUnpackWARs(((StandardHost) host).isUnpackWARs());
            setContextClass(((StandardHost) host).getContextClass());
        }
    } catch (ClassCastException e) {
        log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.PERIODIC_EVENT)) {
        check();
    } else if (event.getType().equals(Lifecycle.START_EVENT)) {
        start();
    } else if (event.getType().equals(Lifecycle.STOP_EVENT)) {
        stop();
    }
}
 
Example 17
Source File: ThreadLocalLeakPreventionListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Listens for {@link LifecycleEvent} for the start of the {@link Server} to
 * initialize itself and then for after_stop events of each {@link Context}.
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Lifecycle lifecycle = event.getLifecycle();
        if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // when the server starts, we register ourself as listener for
            // all context
            // as well as container event listener so that we know when new
            // Context are deployed
            Server server = (Server) lifecycle;
            registerListenersForServer(server);
        }

        if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // Server is shutting down, so thread pools will be shut down so
            // there is no need to clean the threads
            serverStopping = true;
        }

        if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Context) {
            stopIdleThreads((Context) lifecycle);
        }
    } catch (Exception e) {
        String msg =
            sm.getString(
                "threadLocalLeakPreventionListener.lifecycleEvent.error",
                event);
        log.error(msg, e);
    }
}
 
Example 18
Source File: GlobalResourcesLifecycleListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Primary entry point for startup and shutdown events.
 *
 * @param event The event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    if (Lifecycle.START_EVENT.equals(event.getType())) {
        component = event.getLifecycle();
        createMBeans();
    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
        destroyMBeans();
        component = null;
    }
}
 
Example 19
Source File: ThreadLocalLeakPreventionListener.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Listens for {@link LifecycleEvent} for the start of the {@link Server} to
 * initialize itself and then for after_stop events of each {@link Context}.
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {
    try {
        Lifecycle lifecycle = event.getLifecycle();
        if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // when the server starts, we register ourself as listener for
            // all context
            // as well as container event listener so that we know when new
            // Context are deployed
            Server server = (Server) lifecycle;
            registerListenersForServer(server);
        }

        if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Server) {
            // Server is shutting down, so thread pools will be shut down so
            // there is no need to clean the threads
            serverStopping = true;
        }

        if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) &&
                lifecycle instanceof Context) {
            stopIdleThreads((Context) lifecycle);
        }
    } catch (Exception e) {
        String msg =
            sm.getString(
                "threadLocalLeakPreventionListener.lifecycleEvent.error",
                event);
        log.error(msg, e);
    }
}
 
Example 20
Source File: HostConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Process the START event for an associated Host.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the host we are associated with
    try {
        host = (Host) event.getLifecycle();
        if (host instanceof StandardHost) {
            setCopyXML(((StandardHost) host).isCopyXML());
            setDeployXML(((StandardHost) host).isDeployXML());
            setUnpackWARs(((StandardHost) host).isUnpackWARs());
            setContextClass(((StandardHost) host).getContextClass());
        }
    } catch (ClassCastException e) {
        log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.PERIODIC_EVENT)) {
        check();
    } else if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
        beforeStart();
    } else if (event.getType().equals(Lifecycle.START_EVENT)) {
        start();
    } else if (event.getType().equals(Lifecycle.STOP_EVENT)) {
        stop();
    }
}