FileDocCategorySizeDatePackage
RegistryContextListener.javaAPI DocApache Lucene 2.1.03319Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.server.registry

RegistryContextListener

public class RegistryContextListener extends Object implements ServletContextListener
This Listener creates the {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} when the context is loaded. The registry will be loaded before the {@link org.apache.lucene.gdata.servlet.RequestControllerServlet} is loaded. The Registry will be loaded and set up before the REST interface is available.

This ContextListener has to be configured in the web.xml deployment descriptor.

When the {@link javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)} method is called the registry will be destroyed using {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry#destroy()} method.

author
Simon Willnauer

Fields Summary
private GDataServerRegistry
serverRegistry
private static final Log
LOG
Constructors Summary
Methods Summary
public voidcontextDestroyed(javax.servlet.ServletContextEvent arg0)

see
javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)

        LOG.info("Destroying context");
        /*
         * this might be null if startup fails
         * --> prevent null pointer exception
         */
        if(this.serverRegistry != null)
            this.serverRegistry.destroy();

    
public voidcontextInitialized(javax.servlet.ServletContextEvent arg0)

see
javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)


           
        
        LOG.info("RegistryContextListener has been loaded");

        try {
            RegistryBuilder.buildRegistry();
            this.serverRegistry = GDataServerRegistry.getRegistry();
            /*
             * catch all exceptions and destroy the registry to release all resources.
             * some components start lots of threads, the will remain running if the registry is not destroyed
             */
        } catch (Throwable e) {
            GDataServerRegistry.getRegistry().destroy();
            LOG.error("can not register required components", e);
            throw new RuntimeException("Can not register required components",
                    e);
        }