Example usage for javax.management MBeanServer createMBean

List of usage examples for javax.management MBeanServer createMBean

Introduction

In this page you can find the example usage for javax.management MBeanServer createMBean.

Prototype

public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
        throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException;

Source Link

Document

If this method successfully creates an MBean, a notification is sent as described above.

Usage

From source file:net.sbbi.upnp.jmx.JMXManager.java

private MBeanServer initMBeanServer(MBeanServerConfig conf) throws Exception {
    mx4j.log.Log.redirectTo(new CommonsLogger());
    //  make sure that MX4j Server builder is used
    String oldSysProp = System.getProperty("javax.management.builder.initial");
    System.setProperty("javax.management.builder.initial", "mx4j.server.MX4JMBeanServerBuilder");
    MBeanServer server = MBeanServerFactory.createMBeanServer("UPNPLib");
    if (oldSysProp != null) {
        System.setProperty("javax.management.builder.initial", oldSysProp);
    }//from   ww  w. j  a  v  a 2  s.  co m
    ObjectName serverName = new ObjectName("Http:name=HttpAdaptor");
    server.createMBean("mx4j.tools.adaptor.http.HttpAdaptor", serverName, null);
    // set attributes
    server.setAttribute(serverName, new Attribute("Port", new Integer(conf.adapterAdapterPort)));

    Boolean allowWanBool = new Boolean(conf.allowWan);
    if (allowWanBool.booleanValue()) {
        server.setAttribute(serverName, new Attribute("Host", "0.0.0.0"));
    } else {
        server.setAttribute(serverName, new Attribute("Host", "localhost"));
    }

    ObjectName processorName = new ObjectName("Http:name=XSLTProcessor");
    server.createMBean("mx4j.tools.adaptor.http.XSLTProcessor", processorName, null);
    server.setAttribute(processorName, new Attribute("LocaleString", conf.locale));

    server.setAttribute(processorName, new Attribute("UseCache", Boolean.FALSE));

    server.setAttribute(processorName, new Attribute("PathInJar", "net/sbbi/jmx/xsl"));

    server.setAttribute(serverName, new Attribute("ProcessorName", processorName));
    // add user names
    server.invoke(serverName, "addAuthorization", new Object[] { conf.adapterUserName, conf.adapterPassword },
            new String[] { "java.lang.String", "java.lang.String" });
    // use basic authentication
    server.setAttribute(serverName, new Attribute("AuthenticationMethod", "basic"));
    // starts the server
    server.invoke(serverName, "start", null, null);

    return server;
}

From source file:org.openqa.jetty.util.jmx.MX4JHttpAdaptor.java

public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
    name = super.preRegister(server, name);
    ObjectName processorName = new ObjectName(name + ",processor=XSLT");
    server.createMBean("mx4j.tools.adaptor.http.XSLTProcessor", processorName, null);
    setProcessorName(processorName);/*from ww  w . j  av a  2s  . co m*/
    return name;
}