Search in sources :

Example 1 with JmxEnabled

use of org.apache.catalina.JmxEnabled in project tomcat by apache.

the class MBeanFactory method removeValve.

/**
 * Remove an existing Valve.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeValve(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Container container = getParentContainerFromChild(oname);
    Valve[] valves = container.getPipeline().getValves();
    for (Valve valve : valves) {
        ObjectName voname = ((JmxEnabled) valve).getObjectName();
        if (voname.equals(oname)) {
            container.getPipeline().removeValve(valve);
        }
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 2 with JmxEnabled

use of org.apache.catalina.JmxEnabled in project tomcat by apache.

the class MBeanFactory method createValve.

/**
 * Create a new Valve and associate it with a {@link Container}.
 *
 * @param className The fully qualified class name of the {@link Valve} to
 *                  create
 * @param parent    The MBean name of the associated parent
 *                  {@link Container}.
 *
 * @return  The MBean name of the {@link Valve} that was created or
 *          <code>null</code> if the {@link Valve} does not implement
 *          {@link JmxEnabled}.
 * @exception Exception if an MBean cannot be created or registered
 */
public String createValve(String className, String parent) throws Exception {
    // Look for the parent
    ObjectName parentName = new ObjectName(parent);
    Container container = getParentContainerFromParent(parentName);
    if (container == null) {
        // TODO
        throw new IllegalArgumentException();
    }
    Valve valve = (Valve) Class.forName(className).getConstructor().newInstance();
    container.getPipeline().addValve(valve);
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 3 with JmxEnabled

use of org.apache.catalina.JmxEnabled in project tomcat by apache.

the class ContainerMBean method addValve.

/**
 * Adds a valve to this Container instance.
 *
 * @param valveType ClassName of the valve to be added
 * @return the MBean name of the new valve
 * @throws MBeanException if adding the valve failed
 */
public String addValve(String valveType) throws MBeanException {
    Valve valve = (Valve) newInstance(valveType);
    Container container = doGetManagedResource();
    container.getPipeline().addValve(valve);
    if (valve instanceof JmxEnabled) {
        return ((JmxEnabled) valve).getObjectName().toString();
    } else {
        return null;
    }
}
Also used : Container(org.apache.catalina.Container) Valve(org.apache.catalina.Valve) JmxEnabled(org.apache.catalina.JmxEnabled)

Example 4 with JmxEnabled

use of org.apache.catalina.JmxEnabled in project tomcat by apache.

the class StandardHost method getValveNames.

// -------------------- JMX  --------------------
/**
 * @return the MBean Names of the Valves associated with this Host
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String[] getValveNames() throws Exception {
    Valve[] valves = this.getPipeline().getValves();
    String[] mbeanNames = new String[valves.length];
    for (int i = 0; i < valves.length; i++) {
        if (valves[i] instanceof JmxEnabled) {
            ObjectName oname = ((JmxEnabled) valves[i]).getObjectName();
            if (oname != null) {
                mbeanNames[i] = oname.toString();
            }
        }
    }
    return mbeanNames;
}
Also used : ErrorReportValve(org.apache.catalina.valves.ErrorReportValve) Valve(org.apache.catalina.Valve) JmxEnabled(org.apache.catalina.JmxEnabled) ObjectName(javax.management.ObjectName)

Example 5 with JmxEnabled

use of org.apache.catalina.JmxEnabled in project tomcat by apache.

the class StandardPipeline method getValveObjectNames.

public ObjectName[] getValveObjectNames() {
    List<ObjectName> valveList = new ArrayList<>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof JmxEnabled) {
            valveList.add(((JmxEnabled) current).getObjectName());
        }
        current = current.getNext();
    }
    return valveList.toArray(new ObjectName[0]);
}
Also used : ArrayList(java.util.ArrayList) Valve(org.apache.catalina.Valve) ObjectName(javax.management.ObjectName) JmxEnabled(org.apache.catalina.JmxEnabled)

Aggregations

JmxEnabled (org.apache.catalina.JmxEnabled)8 ObjectName (javax.management.ObjectName)6 Valve (org.apache.catalina.Valve)6 Container (org.apache.catalina.Container)5 ArrayList (java.util.ArrayList)1 MBeanException (javax.management.MBeanException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 Executor (org.apache.catalina.Executor)1 Connector (org.apache.catalina.connector.Connector)1 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)1