Java Code Examples for org.apache.catalina.Container#addLifecycleListener()

The following examples show how to use org.apache.catalina.Container#addLifecycleListener() . 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: StandardHost.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Add a child Container, only if the proposed child is an implementation
 * of Context.
 *
 * @param child Child container to be added
 */
@Override
public void addChild(Container child) {

    if (!(child instanceof Context))
        throw new IllegalArgumentException
            (sm.getString("standardHost.notContext"));

    child.addLifecycleListener(new MemoryLeakTrackingListener());

    // Avoid NPE for case where Context is defined in server.xml with only a
    // docBase
    Context context = (Context) child;
    if (context.getPath() == null) {
        ContextName cn = new ContextName(context.getDocBase(), true);
        context.setPath(cn.getPath());
    }

    super.addChild(child);

}
 
Example 2
Source File: LazyRealm.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void setContainer(final Container container) {
    container.addLifecycleListener(new LifecycleListener() {
        @Override
        public void lifecycleEvent(final LifecycleEvent event) {
            if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType())) {
                if (creationalContext != null) {
                    creationalContext.release();
                }
            }
        }
    });

    if (delegate != null) {
        delegate.setContainer(container);
    } else {
        this.container = Context.class.cast(container);
    }
}
 
Example 3
Source File: MapperListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Add this mapper to the container and all child containers
 *
 * @param container
 */
private void addListeners(Container container) {
    container.addContainerListener(this);
    container.addLifecycleListener(this);
    for (Container child : container.findChildren()) {
        addListeners(child);
    }
}
 
Example 4
Source File: MapperListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add this mapper to the container and all child containers
 *
 * @param container
 */
private void addListeners(Container container) {
    container.addContainerListener(this);
    container.addLifecycleListener(this);
    for (Container child : container.findChildren()) {
        addListeners(child);
    }
}
 
Example 5
Source File: StandardHost.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a child Container, only if the proposed child is an implementation
 * of Context.
 *
 * @param child Child container to be added
 */
@Override
public void addChild(Container child) {

    child.addLifecycleListener(new MemoryLeakTrackingListener());

    if (!(child instanceof Context))
        throw new IllegalArgumentException
            (sm.getString("standardHost.notContext"));
    super.addChild(child);

}
 
Example 6
Source File: MapperListener.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Add this mapper to the container and all child containers
 *
 * @param container
 */
private void addListeners(Container container) {
    container.addContainerListener(this);
    container.addLifecycleListener(this);
    for (Container child : container.findChildren()) {
        addListeners(child);
    }
}
 
Example 7
Source File: ContainerMBean.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Add a LifecycleEvent listener to this component.
 *
 * @param type ClassName of the listener to add
 * @throws MBeanException if adding the listener failed
 */
public void addLifecycleListener(String type) throws MBeanException{
    LifecycleListener listener = (LifecycleListener) newInstance(type);
    Container container = doGetManagedResource();
    container.addLifecycleListener(listener);
}