org.apache.catalina.mbeans.MBeanUtils Java Examples

The following examples show how to use org.apache.catalina.mbeans.MBeanUtils. 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: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Add a resource link for this web application.
 *
 * @param resourceLink New resource link
 */
@Override
public void addResourceLink(ContextResourceLink resourceLink) {

    if (entries.contains(resourceLink.getName())) {
        return;
    } else {
        entries.add(resourceLink.getName());
    }

    synchronized (resourceLinks) {
        resourceLink.setNamingResources(this);
        resourceLinks.put(resourceLink.getName(), resourceLink);
    }
    support.firePropertyChange("resourceLink", null, resourceLink);

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(resourceLink);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    resourceLink.getName()), e);
        }
    }
}
 
Example #2
Source File: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove any environment entry with the specified name.
 *
 * @param name Name of the environment entry to remove
 */
@Override
public void removeEnvironment(String name) {

    entries.remove(name);

    ContextEnvironment environment = null;
    synchronized (envs) {
        environment = envs.remove(name);
    }
    if (environment != null) {
        support.firePropertyChange("environment", environment, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(environment);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        environment.getName()), e);
            }
        }
        environment.setNamingResources(null);
    }
}
 
Example #3
Source File: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove any resource reference with the specified name.
 *
 * @param name Name of the resource reference to remove
 */
@Override
public void removeResource(String name) {

    entries.remove(name);

    ContextResource resource = null;
    synchronized (resources) {
        resource = resources.remove(name);
    }
    if (resource != null) {
        support.firePropertyChange("resource", resource, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resource);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resource.getName()), e);
            }
        }
        resource.setNamingResources(null);
    }
}
 
Example #4
Source File: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove any resource link with the specified name.
 *
 * @param name Name of the resource link to remove
 */
@Override
public void removeResourceLink(String name) {

    entries.remove(name);

    ContextResourceLink resourceLink = null;
    synchronized (resourceLinks) {
        resourceLink = resourceLinks.remove(name);
    }
    if (resourceLink != null) {
        support.firePropertyChange("resourceLink", resourceLink, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resourceLink);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resourceLink.getName()), e);
            }
        }
        resourceLink.setNamingResources(null);
    }
}
 
Example #5
Source File: NamingResources.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Add a resource link for this web application.
 *
 * @param resourceLink New resource link
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    if (entries.contains(resourceLink.getName())) {
        return;
    } else {
        entries.add(resourceLink.getName());
    }

    synchronized (resourceLinks) {
        resourceLink.setNamingResources(this);
        resourceLinks.put(resourceLink.getName(), resourceLink);
    }
    support.firePropertyChange("resourceLink", null, resourceLink);

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(resourceLink);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    resourceLink.getName()), e);
        }
    }
}
 
Example #6
Source File: NamingResources.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource link with the specified name.
 *
 * @param name Name of the resource link to remove
 */
public void removeResourceLink(String name) {

    entries.remove(name);

    ContextResourceLink resourceLink = null;
    synchronized (resourceLinks) {
        resourceLink = resourceLinks.remove(name);
    }
    if (resourceLink != null) {
        support.firePropertyChange("resourceLink", resourceLink, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resourceLink);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resourceLink.getName()), e);
            }
        }
        resourceLink.setNamingResources(null);
    }
}
 
Example #7
Source File: NamingResources.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource reference with the specified name.
 *
 * @param name Name of the resource reference to remove
 */
public void removeResource(String name) {

    entries.remove(name);

    ContextResource resource = null;
    synchronized (resources) {
        resource = resources.remove(name);
    }
    if (resource != null) {
        support.firePropertyChange("resource", resource, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resource);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resource.getName()), e);
            }
        }
        resource.setNamingResources(null);
    }
}
 
Example #8
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource link with the specified name.
 *
 * @param name Name of the resource link to remove
 */
public void removeResourceLink(String name) {

    entries.remove(name);

    ContextResourceLink resourceLink = null;
    synchronized (resourceLinks) {
        resourceLink = resourceLinks.remove(name);
    }
    if (resourceLink != null) {
        support.firePropertyChange("resourceLink", resourceLink, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resourceLink);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resourceLink.getName()), e);
            }
        }
        resourceLink.setNamingResources(null);
    }
}
 
Example #9
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any resource reference with the specified name.
 *
 * @param name Name of the resource reference to remove
 */
public void removeResource(String name) {

    entries.remove(name);

    ContextResource resource = null;
    synchronized (resources) {
        resource = resources.remove(name);
    }
    if (resource != null) {
        support.firePropertyChange("resource", resource, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(resource);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        resource.getName()), e);
            }
        }
        resource.setNamingResources(null);
    }
}
 
Example #10
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any environment entry with the specified name.
 *
 * @param name Name of the environment entry to remove
 */
public void removeEnvironment(String name) {

    entries.remove(name);

    ContextEnvironment environment = null;
    synchronized (envs) {
        environment = envs.remove(name);
    }
    if (environment != null) {
        support.firePropertyChange("environment", environment, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(environment);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        environment.getName()), e);
            }
        }
        environment.setNamingResources(null);
    }
}
 
Example #11
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Add a resource link for this web application.
 *
 * @param resourceLink New resource link
 */
public void addResourceLink(ContextResourceLink resourceLink) {

    if (entries.contains(resourceLink.getName())) {
        return;
    } else {
        entries.add(resourceLink.getName());
    }

    synchronized (resourceLinks) {
        resourceLink.setNamingResources(this);
        resourceLinks.put(resourceLink.getName(), resourceLink);
    }
    support.firePropertyChange("resourceLink", null, resourceLink);

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(resourceLink);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    resourceLink.getName()), e);
        }
    }
}
 
Example #12
Source File: NamingResources.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove any environment entry with the specified name.
 *
 * @param name Name of the environment entry to remove
 */
public void removeEnvironment(String name) {

    entries.remove(name);

    ContextEnvironment environment = null;
    synchronized (envs) {
        environment = envs.remove(name);
    }
    if (environment != null) {
        support.firePropertyChange("environment", environment, null);
        // De-register with JMX
        if (resourceRequireExplicitRegistration) {
            try {
                MBeanUtils.destroyMBean(environment);
            } catch (Exception e) {
                log.warn(sm.getString("namingResources.mbeanDestroyFail",
                        environment.getName()), e);
            }
        }
        environment.setNamingResources(null);
    }
}
 
Example #13
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected String getDomainInternal() {
    Container container = getContainer();
    if (container == null) {
        return null;
    }
    return MBeanUtils.getDomain(container);
}
 
Example #14
Source File: StandardServer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the MBean domain for this server. The domain is obtained using
 * the following search order:
 * <ol>
 * <li>Name of first {@link org.apache.catalina.Engine}.</li>
 * <li>Name of first {@link Service}.</li>
 * </ol>
 */
@Override
protected String getDomainInternal() {
    
    String domain = null;
    
    Service[] services = findServices();
    if (services.length > 0) {
        Service service = services[0];
        if (service != null) {
            domain = MBeanUtils.getDomain(service);
        }
    }
    return domain;
}
 
Example #15
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    if (clusterDeployer != null) {
        StringBuilder name = new StringBuilder("type=Cluster");
        Container container = getContainer();
        name.append(MBeanUtils.getContainerKeyProperties(container));
        name.append(",component=Deployer");
        onameClusterDeployer = register(clusterDeployer, name.toString());
    }
}
 
Example #16
Source File: StandardWrapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Load and initialize an instance of this servlet, if there is not already
 * at least one initialized instance.  This can be used, for example, to
 * load servlets that are marked in the deployment descriptor to be loaded
 * at server startup time.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  Servlets whose classnames begin with
 * <code>org.apache.catalina.</code> (so-called "container" servlets)
 * are loaded by the same classloader that loaded this class, rather than
 * the classloader for the current web application.
 * This gives such classes access to Catalina internals, which are
 * prevented for classes loaded for web applications.
 *
 * @exception ServletException if the servlet init() method threw
 *  an exception
 * @exception ServletException if some other loading problem occurs
 */
@Override
public synchronized void load() throws ServletException {
    instance = loadServlet();
    
    if (!instanceInitialized) {
        initServlet(instance);
    }

    if (isJspServlet) {
        StringBuilder oname =
            new StringBuilder(MBeanUtils.getDomain(getParent()));
        
        oname.append(":type=JspMonitor,name=");
        oname.append(getName());
        
        oname.append(getWebModuleKeyProperties());
        
        try {
            jspMonitorON = new ObjectName(oname.toString());
            Registry.getRegistry(null, null)
                .registerComponent(instance, jspMonitorON, null);
        } catch( Exception ex ) {
            log.info("Error registering JSP monitoring with jmx " +
                     instance);
        }
    }
}
 
Example #17
Source File: StandardHost.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
protected String getObjectNameKeyProperties() {

    StringBuilder keyProperties = new StringBuilder("type=Host");
    keyProperties.append(MBeanUtils.getContainerKeyProperties(this));

    return keyProperties.toString();
}
 
Example #18
Source File: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Add a resource reference for this web application.
 *
 * @param resource New resource reference
 */
@Override
public void addResource(ContextResource resource) {

    if (entries.contains(resource.getName())) {
        return;
    } else {
        if (!checkResourceType(resource)) {
            throw new IllegalArgumentException(sm.getString(
                    "namingResources.resourceTypeFail", resource.getName(),
                    resource.getType()));
        }
        entries.add(resource.getName());
    }

    synchronized (resources) {
        resource.setNamingResources(this);
        resources.put(resource.getName(), resource);
    }
    support.firePropertyChange("resource", null, resource);

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(resource);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    resource.getName()), e);
        }
    }
}
 
Example #19
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected String getObjectNameKeyProperties() {
    StringBuilder name = new StringBuilder("type=Cluster");

    Container container = getContainer();
    if (container != null) {
        name.append(MBeanUtils.getContainerKeyProperties(container));
    }

    return name.toString();
}
 
Example #20
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void registerMember(Member member) {
    // JMX registration
    StringBuilder name = new StringBuilder("type=Cluster");
    Container container = getContainer();
    if (container != null) {
        name.append(MBeanUtils.getContainerKeyProperties(container));
    }
    name.append(",component=Member,name=");
    name.append(ObjectName.quote(member.getName()));

    ObjectName oname = register(member, name.toString());
    memberOnameMap.put(member, oname);
}
 
Example #21
Source File: WebappLoader.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Stop associated {@link ClassLoader} and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.stopping"));

    setState(LifecycleState.STOPPING);

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader != null) {
        ((Lifecycle) classLoader).stop();
        DirContextURLStreamHandler.unbind(classLoader);
    }

    try {
        StandardContext ctx=(StandardContext)container;
        String contextName = ctx.getName();
        if (!contextName.startsWith("/")) {
            contextName = "/" + contextName;
        }
        ObjectName cloname = new ObjectName
            (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context="
             + contextName + ",host=" + ctx.getParent().getName());
        Registry.getRegistry(null, null).unregisterComponent(cloname);
    } catch (Exception e) {
        log.error("LifecycleException ", e);
    }

    classLoader = null;
}
 
Example #22
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Add a resource reference for this web application.
 *
 * @param resource New resource reference
 */
public void addResource(ContextResource resource) {

    if (entries.contains(resource.getName())) {
        return;
    } else {
        if (!checkResourceType(resource)) {
            throw new IllegalArgumentException(sm.getString(
                    "namingResources.resourceTypeFail", resource.getName(),
                    resource.getType()));
        }
        entries.add(resource.getName());
    }

    synchronized (resources) {
        resource.setNamingResources(this);
        resources.put(resource.getName(), resource);
    }
    support.firePropertyChange("resource", null, resource);

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(resource);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    resource.getName()), e);
        }
    }
}
 
Example #23
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
protected String getObjectNameKeyProperties() {
    Object c = getContainer();
    if (c instanceof Container) {
        return "type=NamingResources" +
                MBeanUtils.getContainerKeyProperties((Container) c);
    }
    // Server or just unknown
    return "type=NamingResources";
}
 
Example #24
Source File: RealmBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public String getObjectNameKeyProperties() {

    StringBuilder keyProperties = new StringBuilder("type=Realm");
    keyProperties.append(getRealmSuffix());
    keyProperties.append(MBeanUtils.getContainerKeyProperties(container));

    return keyProperties.toString();
}
 
Example #25
Source File: StandardServer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the MBean domain for this server. The domain is obtained using
 * the following search order:
 * <ol>
 * <li>Name of first {@link org.apache.catalina.Engine}.</li>
 * <li>Name of first {@link Service}.</li>
 * </ol>
 */
@Override
protected String getDomainInternal() {
    
    String domain = null;
    
    Service[] services = findServices();
    if (services.length > 0) {
        Service service = services[0];
        if (service != null) {
            domain = MBeanUtils.getDomain(service);
        }
    }
    return domain;
}
 
Example #26
Source File: StandardHost.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
protected String getObjectNameKeyProperties() {

    StringBuilder keyProperties = new StringBuilder("type=Host");
    keyProperties.append(MBeanUtils.getContainerKeyProperties(this));

    return keyProperties.toString();
}
 
Example #27
Source File: StandardWrapper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Load and initialize an instance of this servlet, if there is not already
 * at least one initialized instance.  This can be used, for example, to
 * load servlets that are marked in the deployment descriptor to be loaded
 * at server startup time.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  Servlets whose classnames begin with
 * <code>org.apache.catalina.</code> (so-called "container" servlets)
 * are loaded by the same classloader that loaded this class, rather than
 * the classloader for the current web application.
 * This gives such classes access to Catalina internals, which are
 * prevented for classes loaded for web applications.
 *
 * @exception ServletException if the servlet init() method threw
 *  an exception
 * @exception ServletException if some other loading problem occurs
 */
@Override
public synchronized void load() throws ServletException {
    instance = loadServlet();
    
    if (!instanceInitialized) {
        initServlet(instance);
    }

    if (isJspServlet) {
        StringBuilder oname =
            new StringBuilder(MBeanUtils.getDomain(getParent()));
        
        oname.append(":type=JspMonitor,name=");
        oname.append(getName());
        
        oname.append(getWebModuleKeyProperties());
        
        try {
            jspMonitorON = new ObjectName(oname.toString());
            Registry.getRegistry(null, null)
                .registerComponent(instance, jspMonitorON, null);
        } catch( Exception ex ) {
            log.info("Error registering JSP monitoring with jmx " +
                     instance);
        }
    }
}
 
Example #28
Source File: RealmBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public String getObjectNameKeyProperties() {
    
    StringBuilder keyProperties = new StringBuilder("type=Realm");
    keyProperties.append(getRealmSuffix());
    keyProperties.append(MBeanUtils.getContainerKeyProperties(container));

    return keyProperties.toString();
}
 
Example #29
Source File: WebappLoader.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Stop associated {@link ClassLoader} and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.stopping"));

    setState(LifecycleState.STOPPING);

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader != null) {
        ((Lifecycle) classLoader).stop();
        DirContextURLStreamHandler.unbind(classLoader);
    }

    try {
        StandardContext ctx=(StandardContext)container;
        String contextName = ctx.getName();
        if (!contextName.startsWith("/")) {
            contextName = "/" + contextName;
        }
        ObjectName cloname = new ObjectName
            (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context="
             + contextName + ",host=" + ctx.getParent().getName());
        Registry.getRegistry(null, null).unregisterComponent(cloname);
    } catch (Exception e) {
        log.error("LifecycleException ", e);
    }

    classLoader = null;
}
 
Example #30
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void registerMember(Member member) {
    // JMX registration
    StringBuilder name = new StringBuilder("type=Cluster");
    Container container = getContainer();
    if (container != null) {
        name.append(MBeanUtils.getContainerKeyProperties(container));
    }
    name.append(",component=Member,name=");
    name.append(ObjectName.quote(member.getName()));

    ObjectName oname = register(member, name.toString());
    memberOnameMap.put(member, oname);
}