org.apache.catalina.LifecycleListener Java Examples

The following examples show how to use org.apache.catalina.LifecycleListener. 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: LifecycleSupport.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove a lifecycle event listener from this component.
 *
 * @param listener The listener to remove
 */
public void removeLifecycleListener(LifecycleListener listener) {

    synchronized (listenersLock) {
        int n = -1;
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] == listener) {
                n = i;
                break;
            }
        }
        if (n < 0)
            return;
        LifecycleListener results[] =
          new LifecycleListener[listeners.length - 1];
        int j = 0;
        for (int i = 0; i < listeners.length; i++) {
            if (i != n)
                results[j++] = listeners[i];
        }
        listeners = results;
    }

}
 
Example #2
Source File: ConnectorSF.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aConnector,
        StoreDescription parentDesc) throws Exception {

    if (aConnector instanceof Connector) {
        Connector connector = (Connector) aConnector;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = connector.findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <UpgradeProtocol> elements
        UpgradeProtocol[] upgradeProtocols = connector.findUpgradeProtocols();
        storeElementArray(aWriter, indent, upgradeProtocols);
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            // Store nested <SSLHostConfig> elements
            SSLHostConfig[] hostConfigs = connector.findSslHostConfigs();
            storeElementArray(aWriter, indent, hostConfigs);
        }
    }
}
 
Example #3
Source File: LifecycleSupport.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove a lifecycle event listener from this component.
 *
 * @param listener The listener to remove
 */
public void removeLifecycleListener(LifecycleListener listener) {

    synchronized (listenersLock) {
        int n = -1;
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i] == listener) {
                n = i;
                break;
            }
        }
        if (n < 0)
            return;
        LifecycleListener results[] =
          new LifecycleListener[listeners.length - 1];
        int j = 0;
        for (int i = 0; i < listeners.length; i++) {
            if (i != n)
                results[j++] = listeners[i];
        }
        listeners = results;
    }

}
 
Example #4
Source File: Runner.java    From myrrix-recommender with Apache License 2.0 5 votes vote down vote up
private static void configureServer(Server server) {
  //server.addLifecycleListener(new SecurityListener());
  //server.addLifecycleListener(new AprLifecycleListener());
  LifecycleListener jasperListener = new JasperListener();
  server.addLifecycleListener(jasperListener);
  jasperListener.lifecycleEvent(new LifecycleEvent(server, Lifecycle.BEFORE_INIT_EVENT, null));
  server.addLifecycleListener(new JreMemoryLeakPreventionListener());
  //server.addLifecycleListener(new GlobalResourcesLifecycleListener());
  server.addLifecycleListener(new ThreadLocalLeakPreventionListener());
}
 
Example #5
Source File: UserConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Deploy a web application for the specified user if they have such an
 * application in the defined directory within their home directory.
 *
 * @param user Username owning the application to be deployed
 * @param home Home directory of this user
 */
private void deploy(String user, String home) {

    // Does this user have a web application to be deployed?
    String contextPath = "/~" + user;
    if (host.findChild(contextPath) != null)
        return;
    File app = new File(home, directoryName);
    if (!app.exists() || !app.isDirectory())
        return;
    /*
    File dd = new File(app, "/WEB-INF/web.xml");
    if (!dd.exists() || !dd.isFile() || !dd.canRead())
        return;
    */
    host.getLogger().info(sm.getString("userConfig.deploy", user));

    // Deploy the web application for this user
    try {
        Class<?> clazz = Class.forName(contextClass);
        Context context =
          (Context) clazz.newInstance();
        context.setPath(contextPath);
        context.setDocBase(app.toString());
        clazz = Class.forName(configClass);
        LifecycleListener listener =
            (LifecycleListener) clazz.newInstance();
        context.addLifecycleListener(listener);
        host.addChild(context);
    } catch (Exception e) {
        host.getLogger().error(sm.getString("userConfig.error", user), e);
    }

}
 
Example #6
Source File: StandardServerSF.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Store the specified server element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aObject Server to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aObject,
        StoreDescription parentDesc) throws Exception {
    if (aObject instanceof StandardServer) {
        StandardServer server = (StandardServer) aObject;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) server)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        /*LifecycleListener listener = null;
        for (int i = 0; listener == null && i < listeners.length; i++)
            if (listeners[i] instanceof ServerLifecycleListener)
                listener = listeners[i];
        if (listener != null) {
            StoreDescription elementDesc = getRegistry()
                    .findDescription(
                            StandardServer.class.getName()
                                    + ".[ServerLifecycleListener]");
            if (elementDesc != null) {
                elementDesc.getStoreFactory().store(aWriter, indent,
                        listener);
            }
        }*/
        // Store nested <GlobalNamingResources> element
        NamingResourcesImpl globalNamingResources = server
                .getGlobalNamingResources();
        StoreDescription elementDesc = getRegistry().findDescription(
                NamingResourcesImpl.class.getName()
                        + ".[GlobalNamingResources]");
        if (elementDesc != null) {
            elementDesc.getStoreFactory().store(aWriter, indent,
                    globalNamingResources);
        }
        // Store nested <Service> elements
        Service services[] = server.findServices();
        storeElementArray(aWriter, indent, services);
    }
}
 
Example #7
Source File: LifecycleSupport.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a lifecycle event listener to this component.
 *
 * @param listener The listener to add
 */
public void addLifecycleListener(LifecycleListener listener) {

  synchronized (listenersLock) {
      LifecycleListener results[] =
        new LifecycleListener[listeners.length + 1];
      for (int i = 0; i < listeners.length; i++)
          results[i] = listeners[i];
      results[listeners.length] = listener;
      listeners = results;
  }

}
 
Example #8
Source File: LifecycleSupport.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Notify all lifecycle event listeners that a particular event has
 * occurred for this Container.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireLifecycleEvent(String type, Object data) {

    LifecycleEvent event = new LifecycleEvent(lifecycle, type, data);
    LifecycleListener interested[] = listeners;

    // 循环所有的 LifecycleListener
    for (int i = 0; i < interested.length; i++)
        interested[i].lifecycleEvent(event);

}
 
Example #9
Source File: StandardServiceSF.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Store the specified service element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aService Service to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService,
        StoreDescription parentDesc) throws Exception {
    if (aService instanceof StandardService) {
        StandardService service = (StandardService) aService;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) service)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Executor> elements
        Executor[] executors = service.findExecutors();
        storeElementArray(aWriter, indent, executors);

        Connector connectors[] = service.findConnectors();
        storeElementArray(aWriter, indent, connectors);

        // Store nested <Engine> element
        Engine container = service.getContainer();
        if (container != null) {
            StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
            if (elementDesc != null) {
                IStoreFactory factory = elementDesc.getStoreFactory();
                factory.store(aWriter, indent, container);
            }
        }
    }
}
 
Example #10
Source File: TestMapperListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public ListenersInfo(Container container,
        ContainerListener[] containerListeners,
        LifecycleListener[] lifecycleListeners) {
    this.container = container;
    this.containerListeners = containerListeners;
    this.lifecycleListeners = lifecycleListeners;
}
 
Example #11
Source File: ContainerMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * List the class name of each of the lifecycle listeners added to this
 * container.
 * @return the lifecycle listeners class names
 * @throws MBeanException propagated from the managed resource access
 */
public String[] findLifecycleListenerNames() throws MBeanException {
    Container container = doGetManagedResource();
    List<String> result = new ArrayList<>();

    LifecycleListener[] listeners = container.findLifecycleListeners();
    for(LifecycleListener listener: listeners){
        result.add(listener.getClass().getName());
    }

    return result.toArray(new String[result.size()]);
}
 
Example #12
Source File: ContainerMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove a LifecycleEvent listeners from this component.
 *
 * @param type The ClassName of the listeners to be removed.
 * Note that all the listeners having given ClassName will be removed.
 * @throws MBeanException propagated from the managed resource access
 */
public void removeLifecycleListeners(String type) throws MBeanException{
    Container container = doGetManagedResource();

    LifecycleListener[] listeners = container.findLifecycleListeners();
    for (LifecycleListener listener : listeners){
        if (listener.getClass().getName().equals(type)) {
            container.removeLifecycleListener(listener);
        }
    }
}
 
Example #13
Source File: LazyStopLoader.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public LifecycleListener[] findLifecycleListeners() {
    if (delegate instanceof Lifecycle) {
        return ((Lifecycle) delegate).findLifecycleListeners();
    }
    return new LifecycleListener[0];
}
 
Example #14
Source File: UserConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Deploy a web application for the specified user if they have such an
 * application in the defined directory within their home directory.
 *
 * @param user Username owning the application to be deployed
 * @param home Home directory of this user
 */
private void deploy(String user, String home) {

    // Does this user have a web application to be deployed?
    String contextPath = "/~" + user;
    if (host.findChild(contextPath) != null)
        return;
    File app = new File(home, directoryName);
    if (!app.exists() || !app.isDirectory())
        return;

    host.getLogger().info(sm.getString("userConfig.deploy", user));

    // Deploy the web application for this user
    try {
        Class<?> clazz = Class.forName(contextClass);
        Context context = (Context) clazz.getConstructor().newInstance();
        context.setPath(contextPath);
        context.setDocBase(app.toString());
        clazz = Class.forName(configClass);
        LifecycleListener listener = (LifecycleListener) clazz.getConstructor().newInstance();
        context.addLifecycleListener(listener);
        host.addChild(context);
    } catch (Exception e) {
        host.getLogger().error(sm.getString("userConfig.error", user), e);
    }

}
 
Example #15
Source File: TestMapperListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public ListenersInfo(Container container,
        ContainerListener[] containerListeners,
        LifecycleListener[] lifecycleListeners) {
    this.container = container;
    this.containerListeners = containerListeners;
    this.lifecycleListeners = lifecycleListeners;
}
 
Example #16
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * @param host The host in which the context will be deployed
 * @param contextPath The context mapping to use, "" for root context.
 * @param docBase Base directory for the context, for static files.
 *  Must exist, relative to the server home
 * @param config Custom context configurator helper
 * @return the deployed context
 * @see #addWebapp(String, String)
 */
public Context addWebapp(Host host, String contextPath, String docBase,
        LifecycleListener config) {

    silence(host, contextPath);

    Context ctx = createContext(host, contextPath);
    ctx.setPath(contextPath);
    ctx.setDocBase(docBase);
    ctx.addLifecycleListener(getDefaultWebXmlListener());
    ctx.setConfigFile(getWebappConfigFile(docBase, contextPath));

    ctx.addLifecycleListener(config);

    if (config instanceof ContextConfig) {
        // prevent it from looking ( if it finds one - it'll have dup error )
        ((ContextConfig) config).setDefaultWebXml(noDefaultWebXmlPath());
    }

    if (host == null) {
        getHost().addChild(ctx);
    } else {
        host.addChild(ctx);
    }

    return ctx;
}
 
Example #17
Source File: StandardLifecycleSupportTest.java    From session-managers with Apache License 2.0 5 votes vote down vote up
@Test
public void findLifecycleListeners() {
    this.lifecycleSupport.add(this.lifecycleListener1);
    this.lifecycleSupport.add(this.lifecycleListener2);

    assertArrayEquals(new LifecycleListener[]{this.lifecycleListener1, this.lifecycleListener2},
            this.lifecycleSupport.getLifecycleListeners());
}
 
Example #18
Source File: StandardLifecycleSupport.java    From session-managers with Apache License 2.0 5 votes vote down vote up
private void notify(LifecycleEvent lifecycleEvent) {
    for (LifecycleListener lifecycleListener : this.lifecycleListeners) {
        try {
            lifecycleListener.lifecycleEvent(lifecycleEvent);
        } catch (RuntimeException e) {
            this.logger.warn("Exception encountered while notifying listener of lifecycle event", e);
        }
    }
}
 
Example #19
Source File: WebappClassLoaderBase.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Get the lifecycle listeners associated with this lifecycle. If this
 * Lifecycle has no listeners registered, a zero-length array is returned.
 */
@Override
public LifecycleListener[] findLifecycleListeners() {
    return new LifecycleListener[0];
}
 
Example #20
Source File: TesterHost.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public LifecycleListener[] findLifecycleListeners() {
    return null;
}
 
Example #21
Source File: Tomcat7Valve.java    From flex-blazeds with Apache License 2.0 4 votes vote down vote up
public LifecycleListener[] findLifecycleListeners()
{
    return null;
}
 
Example #22
Source File: StandardLifecycleSupport.java    From session-managers with Apache License 2.0 4 votes vote down vote up
@Override
public LifecycleListener[] getLifecycleListeners() {
    synchronized (this.monitor) {
        return this.lifecycleListeners.toArray(new LifecycleListener[this.lifecycleListeners.size()]);
    }
}
 
Example #23
Source File: Tomcat7Valve.java    From flex-blazeds with Apache License 2.0 4 votes vote down vote up
public void addLifecycleListener(LifecycleListener listener)
{
    // No-op.
}
 
Example #24
Source File: StandardLifecycleSupport.java    From session-managers with Apache License 2.0 4 votes vote down vote up
@Override
public void add(LifecycleListener lifecycleListener) {
    synchronized (this.monitor) {
        this.lifecycleListeners.add(lifecycleListener);
    }
}
 
Example #25
Source File: MockWebResourceRoot.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@Override
public LifecycleListener[] findLifecycleListeners() {
	throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
 
Example #26
Source File: MockWebResourceRoot.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@Override
public void addLifecycleListener(LifecycleListener listener) {
	throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
 
Example #27
Source File: TesterContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void removeLifecycleListener(LifecycleListener listener) {
    // NO-OP
}
 
Example #28
Source File: TesterContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public LifecycleListener[] findLifecycleListeners() {
    return null;
}
 
Example #29
Source File: TesterContext.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void addLifecycleListener(LifecycleListener listener) {
    // NO-OP
}
 
Example #30
Source File: LazyStopStandardRoot.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public void addLifecycleListener(final LifecycleListener listener) {
    delegate.addLifecycleListener(listener);
}