Java Code Examples for org.apache.catalina.mbeans.MBeanUtils#createMBean()

The following examples show how to use org.apache.catalina.mbeans.MBeanUtils#createMBean() . 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: 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 3
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 4
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 5
Source File: NamingResources.java    From Tomcat7.0.67 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 6
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 7
Source File: NamingResourcesImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Add an environment entry for this web application.
 *
 * @param environment New environment entry
 */
@Override
public void addEnvironment(ContextEnvironment environment) {

    if (entries.contains(environment.getName())) {
        ContextEnvironment ce = findEnvironment(environment.getName());
        ContextResourceLink rl = findResourceLink(environment.getName());
        if (ce != null) {
            if (ce.getOverride()) {
                removeEnvironment(environment.getName());
            } else {
                return;
            }
        } else if (rl != null) {
            // Link. Need to look at the global resources
            NamingResourcesImpl global = getServer().getGlobalNamingResources();
            if (global.findEnvironment(rl.getGlobal()) != null) {
                if (global.findEnvironment(rl.getGlobal()).getOverride()) {
                    removeResourceLink(environment.getName());
                } else {
                    return;
                }
            }
        } else {
            // It exists but it isn't an env or a res link...
            return;
        }
    }

    List<InjectionTarget> injectionTargets = environment.getInjectionTargets();
    String value = environment.getValue();
    String lookupName = environment.getLookupName();

    // Entries with injection targets but no value are effectively ignored
    if (injectionTargets != null && injectionTargets.size() > 0 &&
            (value == null || value.length() == 0)) {
        return;
    }

    // Entries with lookup-name and value are an error (EE.5.4.1.3)
    if (value != null && value.length() > 0 && lookupName != null && lookupName.length() > 0) {
        throw new IllegalArgumentException(
                sm.getString("namingResources.envEntryLookupValue", environment.getName()));
    }

    if (!checkResourceType(environment)) {
        throw new IllegalArgumentException(sm.getString(
                "namingResources.resourceTypeFail", environment.getName(),
                environment.getType()));
    }

    entries.add(environment.getName());

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

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(environment);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    environment.getName()), e);
        }
    }
}
 
Example 8
Source File: NamingResources.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Add an environment entry for this web application.
 *
 * @param environment New environment entry
 */
public void addEnvironment(ContextEnvironment environment) {

    if (entries.contains(environment.getName())) {
        ContextEnvironment ce = findEnvironment(environment.getName());
        ContextResourceLink rl = findResourceLink(environment.getName());
        if (ce != null) {
            if (ce.getOverride()) {
                removeEnvironment(environment.getName());
            } else {
                return;
            }
        } else if (rl != null) {
            // Link. Need to look at the global resources
            NamingResources global = getServer().getGlobalNamingResources();
            if (global.findEnvironment(rl.getGlobal()) != null) {
                if (global.findEnvironment(rl.getGlobal()).getOverride()) {
                    removeResourceLink(environment.getName());
                } else {
                    return;
                }
            }
        } else {
            // It exists but it isn't an env or a res link...
            return;
        }
    }
    
    if (!checkResourceType(environment)) {
        throw new IllegalArgumentException(sm.getString(
                "namingResources.resourceTypeFail", environment.getName(),
                environment.getType()));
    }

    entries.add(environment.getName());

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

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(environment);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    environment.getName()), e);
        }
    }
}
 
Example 9
Source File: NamingResources.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Add an environment entry for this web application.
 *
 * @param environment New environment entry
 */
public void addEnvironment(ContextEnvironment environment) {

    if (entries.contains(environment.getName())) {
        ContextEnvironment ce = findEnvironment(environment.getName());
        ContextResourceLink rl = findResourceLink(environment.getName());
        if (ce != null) {
            if (ce.getOverride()) {
                removeEnvironment(environment.getName());
            } else {
                return;
            }
        } else if (rl != null) {
            // Link. Need to look at the global resources
            NamingResources global = getServer().getGlobalNamingResources();
            if (global.findEnvironment(rl.getGlobal()) != null) {
                if (global.findEnvironment(rl.getGlobal()).getOverride()) {
                    removeResourceLink(environment.getName());
                } else {
                    return;
                }
            }
        } else {
            // It exists but it isn't an env or a res link...
            return;
        }
    }
    
    if (!checkResourceType(environment)) {
        throw new IllegalArgumentException(sm.getString(
                "namingResources.resourceTypeFail", environment.getName(),
                environment.getType()));
    }

    entries.add(environment.getName());

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

    // Register with JMX
    if (resourceRequireExplicitRegistration) {
        try {
            MBeanUtils.createMBean(environment);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail",
                    environment.getName()), e);
        }
    }
}