Search in sources :

Example 1 with Registry

use of org.apache.tomcat.util.modeler.Registry in project meecrowave by apache.

the class Meecrowave method setupJmx.

private void setupJmx(final boolean skip) {
    try {
        final Field registry = Registry.class.getDeclaredField("registry");
        registry.setAccessible(true);
        registry.set(null, skip ? new NoDescriptorRegistry() : new Registry());
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : Field(java.lang.reflect.Field) NoDescriptorRegistry(org.apache.meecrowave.tomcat.NoDescriptorRegistry) NoDescriptorRegistry(org.apache.meecrowave.tomcat.NoDescriptorRegistry) Registry(org.apache.tomcat.util.modeler.Registry) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException)

Example 2 with Registry

use of org.apache.tomcat.util.modeler.Registry in project tomcat by apache.

the class AbstractEndpoint method destroy.

public final void destroy() throws Exception {
    if (bindState == BindState.BOUND_ON_INIT) {
        unbind();
        bindState = BindState.UNBOUND;
    }
    Registry registry = Registry.getRegistry(null, null);
    registry.unregisterComponent(oname);
    registry.unregisterComponent(socketProperties.getObjectName());
    for (SSLHostConfig sslHostConfig : findSslHostConfigs()) {
        unregisterJmx(sslHostConfig);
    }
}
Also used : Registry(org.apache.tomcat.util.modeler.Registry)

Example 3 with Registry

use of org.apache.tomcat.util.modeler.Registry in project tomcat by apache.

the class AbstractHttp11Protocol method destroy.

@Override
public void destroy() throws Exception {
    // There may be upgrade protocols with their own MBeans. These need to
    // be de-registered.
    ObjectName rgOname = getGlobalRequestProcessorMBeanName();
    if (rgOname != null) {
        Registry registry = Registry.getRegistry(null, null);
        ObjectName query = new ObjectName(rgOname.getCanonicalName() + ",Upgrade=*");
        Set<ObjectInstance> upgrades = registry.getMBeanServer().queryMBeans(query, null);
        for (ObjectInstance upgrade : upgrades) {
            registry.unregisterComponent(upgrade.getObjectName());
        }
    }
    super.destroy();
}
Also used : ObjectInstance(javax.management.ObjectInstance) Registry(org.apache.tomcat.util.modeler.Registry) ObjectName(javax.management.ObjectName)

Example 4 with Registry

use of org.apache.tomcat.util.modeler.Registry in project tomcat70 by apache.

the class NamingContextListener method lifecycleEvent.

// ---------------------------------------------- LifecycleListener Methods
/**
 * Acknowledge the occurrence of the specified event.
 *
 * @param event LifecycleEvent that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {
    container = event.getLifecycle();
    if (container instanceof Context) {
        namingResources = ((Context) container).getNamingResources();
        logger = log;
    } else if (container instanceof Server) {
        namingResources = ((Server) container).getGlobalNamingResources();
    } else {
        return;
    }
    if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) {
        if (initialized)
            return;
        try {
            Hashtable<String, Object> contextEnv = new Hashtable<String, Object>();
            try {
                namingContext = new NamingContext(contextEnv, getName());
            } catch (NamingException e) {
            // Never happens
            }
            ContextAccessController.setSecurityToken(getName(), container);
            ContextAccessController.setSecurityToken(container, container);
            ContextBindings.bindContext(container, namingContext, container);
            if (log.isDebugEnabled()) {
                log.debug("Bound " + container);
            }
            // Configure write when read-only behaviour
            namingContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite());
            // Setting the context in read/write mode
            ContextAccessController.setWritable(getName(), container);
            try {
                createNamingContext();
            } catch (NamingException e) {
                logger.error(sm.getString("naming.namingContextCreationFailed", e));
            }
            namingResources.addPropertyChangeListener(this);
            // Binding the naming context to the class loader
            if (container instanceof Context) {
                // Setting the context in read only mode
                ContextAccessController.setReadOnly(getName());
                try {
                    ContextBindings.bindClassLoader(container, container, ((Container) container).getLoader().getClassLoader());
                } catch (NamingException e) {
                    logger.error(sm.getString("naming.bindFailed", e));
                }
            }
            if (container instanceof Server) {
                org.apache.naming.factory.ResourceLinkFactory.setGlobalContext(namingContext);
                try {
                    ContextBindings.bindClassLoader(container, container, this.getClass().getClassLoader());
                } catch (NamingException e) {
                    logger.error(sm.getString("naming.bindFailed", e));
                }
                if (container instanceof StandardServer) {
                    ((StandardServer) container).setGlobalNamingContext(namingContext);
                }
            }
        } finally {
            // Regardless of success, so that we can do cleanup on configure_stop
            initialized = true;
        }
    } else if (Lifecycle.CONFIGURE_STOP_EVENT.equals(event.getType())) {
        if (!initialized)
            return;
        try {
            // Setting the context in read/write mode
            ContextAccessController.setWritable(getName(), container);
            ContextBindings.unbindContext(container, container);
            if (container instanceof Context) {
                ContextBindings.unbindClassLoader(container, container, ((Container) container).getLoader().getClassLoader());
            }
            if (container instanceof Server) {
                ContextBindings.unbindClassLoader(container, container, this.getClass().getClassLoader());
            }
            namingResources.removePropertyChangeListener(this);
            ContextAccessController.unsetSecurityToken(getName(), container);
            ContextAccessController.unsetSecurityToken(container, container);
            // unregister mbeans.
            if (!objectNames.isEmpty()) {
                Collection<ObjectName> names = objectNames.values();
                Registry registry = Registry.getRegistry(null, null);
                for (ObjectName objectName : names) {
                    registry.unregisterComponent(objectName);
                }
            }
            javax.naming.Context global = getGlobalNamingContext();
            if (global != null) {
                ResourceLinkFactory.deregisterGlobalResourceAccess(global);
            }
        } finally {
            objectNames.clear();
            namingContext = null;
            envCtx = null;
            compCtx = null;
            initialized = false;
        }
    }
}
Also used : NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) Server(org.apache.catalina.Server) Hashtable(java.util.Hashtable) Registry(org.apache.tomcat.util.modeler.Registry) NamingContext(org.apache.naming.NamingContext) ObjectName(javax.management.ObjectName) Container(org.apache.catalina.Container) Collection(java.util.Collection) NamingException(javax.naming.NamingException)

Example 5 with Registry

use of org.apache.tomcat.util.modeler.Registry in project tomcat by apache.

the class NamingContextListener method lifecycleEvent.

// ---------------------------------------------- LifecycleListener Methods
/**
 * Acknowledge the occurrence of the specified event.
 *
 * @param event LifecycleEvent that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {
    container = event.getLifecycle();
    if (container instanceof Context) {
        namingResources = ((Context) container).getNamingResources();
        token = ((Context) container).getNamingToken();
    } else if (container instanceof Server) {
        namingResources = ((Server) container).getGlobalNamingResources();
        token = ((Server) container).getNamingToken();
    } else {
        return;
    }
    if (Lifecycle.CONFIGURE_START_EVENT.equals(event.getType())) {
        if (initialized) {
            return;
        }
        try {
            Hashtable<String, Object> contextEnv = new Hashtable<>();
            namingContext = new NamingContext(contextEnv, getName());
            ContextAccessController.setSecurityToken(getName(), token);
            ContextAccessController.setSecurityToken(container, token);
            ContextBindings.bindContext(container, namingContext, token);
            if (log.isDebugEnabled()) {
                log.debug("Bound " + container);
            }
            // Configure write when read-only behaviour
            namingContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite());
            // Setting the context in read/write mode
            ContextAccessController.setWritable(getName(), token);
            try {
                createNamingContext();
            } catch (NamingException e) {
                log.error(sm.getString("naming.namingContextCreationFailed", e));
            }
            namingResources.addPropertyChangeListener(this);
            // Binding the naming context to the class loader
            if (container instanceof Context) {
                // Setting the context in read only mode
                ContextAccessController.setReadOnly(getName());
                try {
                    ContextBindings.bindClassLoader(container, token, ((Context) container).getLoader().getClassLoader());
                } catch (NamingException e) {
                    log.error(sm.getString("naming.bindFailed", e));
                }
            }
            if (container instanceof Server) {
                org.apache.naming.factory.ResourceLinkFactory.setGlobalContext(namingContext);
                try {
                    ContextBindings.bindClassLoader(container, token, this.getClass().getClassLoader());
                } catch (NamingException e) {
                    log.error(sm.getString("naming.bindFailed", e));
                }
                if (container instanceof StandardServer) {
                    ((StandardServer) container).setGlobalNamingContext(namingContext);
                }
            }
        } finally {
            // Regardless of success, so that we can do cleanup on configure_stop
            initialized = true;
        }
    } else if (Lifecycle.CONFIGURE_STOP_EVENT.equals(event.getType())) {
        if (!initialized) {
            return;
        }
        try {
            // Setting the context in read/write mode
            ContextAccessController.setWritable(getName(), token);
            ContextBindings.unbindContext(container, token);
            if (container instanceof Context) {
                ContextBindings.unbindClassLoader(container, token, ((Context) container).getLoader().getClassLoader());
            }
            if (container instanceof Server) {
                ContextBindings.unbindClassLoader(container, token, this.getClass().getClassLoader());
            }
            namingResources.removePropertyChangeListener(this);
            ContextAccessController.unsetSecurityToken(getName(), token);
            ContextAccessController.unsetSecurityToken(container, token);
            // unregister mbeans.
            if (!objectNames.isEmpty()) {
                Collection<ObjectName> names = objectNames.values();
                Registry registry = Registry.getRegistry(null, null);
                for (ObjectName objectName : names) {
                    registry.unregisterComponent(objectName);
                }
            }
            javax.naming.Context global = getGlobalNamingContext();
            if (global != null) {
                ResourceLinkFactory.deregisterGlobalResourceAccess(global);
            }
        } finally {
            objectNames.clear();
            namingContext = null;
            envCtx = null;
            compCtx = null;
            initialized = false;
        }
    }
}
Also used : NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) Server(org.apache.catalina.Server) Hashtable(java.util.Hashtable) Registry(org.apache.tomcat.util.modeler.Registry) NamingContext(org.apache.naming.NamingContext) ObjectName(javax.management.ObjectName) Collection(java.util.Collection) NamingException(javax.naming.NamingException)

Aggregations

Registry (org.apache.tomcat.util.modeler.Registry)6 ObjectName (javax.management.ObjectName)3 Collection (java.util.Collection)2 Hashtable (java.util.Hashtable)2 NamingException (javax.naming.NamingException)2 Context (org.apache.catalina.Context)2 Server (org.apache.catalina.Server)2 NamingContext (org.apache.naming.NamingContext)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 ObjectInstance (javax.management.ObjectInstance)1 Container (org.apache.catalina.Container)1 LifecycleException (org.apache.catalina.LifecycleException)1 NoDescriptorRegistry (org.apache.meecrowave.tomcat.NoDescriptorRegistry)1 SAXException (org.xml.sax.SAXException)1