Example usage for javax.management ObjectName getKeyProperty

List of usage examples for javax.management ObjectName getKeyProperty

Introduction

In this page you can find the example usage for javax.management ObjectName getKeyProperty.

Prototype

public String getKeyProperty(String property) 

Source Link

Document

Obtains the value associated with a key in a key property.

Usage

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Host.//from  ww  w.j  av a  2 s  .c o  m
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    engine.removeChild(host);

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Context./* ww w.  java 2  s .  c  o  m*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeContext(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    String contextName = getPathStr(oname.getKeyProperty("path"));
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);
    Context context = (Context) host.findChild(contextName);

    // Remove this component from its parent component
    host.removeChild(context);

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new System Output Logger.//from  w w  w  . ja  va  2 s  .co m
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createSystemOutLogger(String parent) throws Exception {

    // Create a new SystemOutLogger instance
    SystemOutLogger logger = new SystemOutLogger();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setLogger(logger);
    } else if (type.equals("Engine")) {
        engine.setLogger(logger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setLogger(logger);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("SystemOutLogger");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), logger);
    return (oname.toString());
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new AccessLoggerValve./*from   ww w .j av  a  2 s  .  c  o  m*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createAccessLoggerValve(String parent) throws Exception {

    // Create a new AccessLogValve instance
    AccessLogValve accessLogger = new AccessLogValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(accessLogger);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(accessLogger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(accessLogger);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("AccessLogValve");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), accessLogger);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new FileLogger./*from   w ww .  jav a  2  s .  c om*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createFileLogger(String parent) throws Exception {

    // Create a new FileLogger instance
    FileLogger fileLogger = new FileLogger();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setLogger(fileLogger);
    } else if (type.equals("Engine")) {
        engine.setLogger(fileLogger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setLogger(fileLogger);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("FileLogger");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), fileLogger);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new JDBC Realm./* w  w  w .  j  av  a 2 s  .  co m*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createJDBCRealm(String parent) throws Exception {

    // Create a new JDBCRealm instance
    JDBCRealm realm = new JDBCRealm();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setRealm(realm);
    } else if (type.equals("Engine")) {
        engine.setRealm(realm);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setRealm(realm);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("JDBCRealm");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), realm);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new JNDI Realm.// w w  w . j  a  v a 2 s .c o  m
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createJNDIRealm(String parent) throws Exception {

    // Create a new JNDIRealm instance
    JNDIRealm realm = new JNDIRealm();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setRealm(realm);
    } else if (type.equals("Engine")) {
        engine.setRealm(realm);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setRealm(realm);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("JNDIRealm");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), realm);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Memory Realm./* w  ww . j av  a2 s .c  o  m*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createMemoryRealm(String parent) throws Exception {

    // Create a new MemoryRealm instance
    MemoryRealm realm = new MemoryRealm();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setRealm(realm);
    } else if (type.equals("Engine")) {
        engine.setRealm(realm);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setRealm(realm);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("MemoryRealm");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), realm);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Remote Address Filter Valve.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 *//*w  ww . j  a  va 2  s  .c o m*/
public String createRemoteAddrValve(String parent) throws Exception {

    // Create a new RemoteAddrValve instance
    RemoteAddrValve valve = new RemoteAddrValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("RemoteAddrValve");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), valve);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
* Create a new Remote Host Filter Valve.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*//*w w w .  j a  v  a  2  s.  c  om*/
public String createRemoteHostValve(String parent) throws Exception {

    // Create a new RemoteHostValve instance
    RemoteHostValve valve = new RemoteHostValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("RemoteHostValve");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), valve);
    return (oname.toString());

}