Example usage for javax.management ObjectName ObjectName

List of usage examples for javax.management ObjectName ObjectName

Introduction

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

Prototype

public ObjectName(String name) throws MalformedObjectNameException 

Source Link

Document

Construct an object name from the given string.

Usage

From source file:com.app.services.ExecutorServiceThread.java

public void init(Vector serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) {
    this.serviceList = serviceList;
    this.serverConfig = serverConfig;
    this.mbeanServer = mbeanServer;
    try {/*  ww w .j  a  v a  2  s.  c o  m*/
        serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel
                .bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverConfig.getServicesport())));
        serverSocketChannel.configureBlocking(false);
        this.executorServiceMap = (Hashtable) mbeanServer.getAttribute(new ObjectName(warDeployerName),
                "ExecutorServiceMap");
        this.urlClassLoaderMap = (Hashtable) mbeanServer.getAttribute(new ObjectName(warDeployerName),
                "UrlClassLoaderMap");
        this.deployDirectory = serverConfig.getDeploydirectory();
        //log.info("Nodesport=" + nodesport);
        this.nodesport = serverConfig.getNodesport().split(",");

    } catch (Exception e) {
        log.error("Error in creating server socket channel " + serverConfig.getServicesport(), e);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }

    log.info("initialized");

}

From source file:com.cognifide.aet.runner.util.MessagesManager.java

protected Set<ObjectName> getAetQueuesObjects(MBeanServerConnection connection) throws AETException {
    ObjectName[] queues;/* w  ww. j a va 2s. c  o  m*/
    try {
        ObjectName broker = new ObjectName(BROKER_OBJECT_NAME);
        connection.getMBeanInfo(broker);
        queues = (ObjectName[]) connection.getAttribute(broker, QUEUES_ATTRIBUTE);
    } catch (Exception e) {
        throw new AETException("Exception while getting AET Queues.", e);
    }
    return filter(queues);
}

From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java

public void testTempDestinations() throws Exception {
    Connection conn = factory.createConnection("guest", "password");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String name = "org.apache.activemq:BrokerName=localhost,Type=TempTopic";
    try {/* w w w  .  ja v a 2 s.co m*/
        conn.start();
        TemporaryTopic temp = sess.createTemporaryTopic();
        name += ",Destination=" + temp.getTopicName().replaceAll(":", "_");
        fail("Should have failed creating a temp topic");
    } catch (Exception ignore) {
    }

    ObjectName objName = new ObjectName(name);
    TopicViewMBean mbean = (TopicViewMBean) broker.getManagementContext().newProxyInstance(objName,
            TopicViewMBean.class, true);
    try {
        System.out.println(mbean.getName());
        fail("Shouldn't have created a temp topic");
    } catch (Exception ignore) {
    }
}

From source file:org.ff4j.jmx.FF4JMBeanTest.java

@Test
public void should_enable_feature() throws Exception {
    ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
    mbServConn.invoke(objectName, "enableFeature", new Object[] { "jmxDisabledFeature" },
            new String[] { "java.lang.String" });
    assertFF4J.assertThatFeatureIsEnabled("jmxDisabledFeature");
}

From source file:io.fabric8.cxf.endpoint.jaxrs.RestJsonSchemaJMXTest.java

private ObjectName getEndpointObjectName() throws MalformedObjectNameException, NullPointerException {
    StringBuilder buffer = new StringBuilder();
    String serviceName = "{http://jaxrs.endpoint.cxf.fabric8.io/}BookStore";
    String portName = "BookStore";
    buffer.append(ManagedApi.DOMAIN_NAME + ":type=Bus.Service.Endpoint,");
    buffer.append(ManagementConstants.SERVICE_NAME_PROP + "=\"" + serviceName + "\",");
    buffer.append(ManagementConstants.PORT_NAME_PROP + "=\"" + portName + "\",*");

    return new ObjectName(buffer.toString());
}

From source file:de.thorstenberger.examServer.pdf.PDFExporter.java

/**
 * use jmx, query catalina mbean to find non ssl connectors (-Dcom.sun.management.jmxremote) FIXME tomcat specific
 * code/*from w  w  w .  j  a v  a  2  s  .  c o  m*/
 *
 * @param request
 * @return
 */
private String getServerUrl() {

    final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        for (final Object mbean : beanServer.queryMBeans(new ObjectName("*:type=Connector,*"), null)) {
            final ObjectInstance oi = (ObjectInstance) mbean;
            final Boolean isSecure = (Boolean) beanServer.getAttribute(oi.getObjectName(), "secure");
            final String protocol = (String) beanServer.getAttribute(oi.getObjectName(), "protocol");
            final int port = (Integer) beanServer.getAttribute(oi.getObjectName(), "port");
            if (!isSecure && protocol.startsWith("HTTP")) {
                log.debug(String.format("Using unsecured tomcat connector at port %d", port));
                return "http://localhost:" + port;
            }
        }
    } catch (final MalformedObjectNameException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final NullPointerException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final AttributeNotFoundException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final InstanceNotFoundException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final MBeanException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final ReflectionException e) {
        log.warn("Could not access JMX mbeans.", e);
    }
    log.warn(
            "No mbeans of type '*:type=Connector,*' configured, using default url (assuming non-ssl http connector on port 8080).");
    return "http://localhost:8080";
}

From source file:com.athena.dolly.console.module.jmx.JmxClientManager.java

public static OperationgSystemVo getOperatingSystemUsage(String nodeName) {
    JmxClient jmxClient = jmxClientMap.get(nodeName);

    OperationgSystemVo osVo = null;//from w  ww . j  ava2  s  .  com
    try {
        ObjectName objectName = new ObjectName("java.lang:type=OperatingSystem");

        MBeanServerConnection connection = jmxClient.getJmxConnector().getMBeanServerConnection();

        osVo = new OperationgSystemVo();

        osVo.setName((String) connection.getAttribute(objectName, "Name"));
        osVo.setVersion((String) connection.getAttribute(objectName, "Version"));
        osVo.setArch((String) connection.getAttribute(objectName, "Arch"));
        osVo.setSystemLoadAverage((Double) connection.getAttribute(objectName, "SystemLoadAverage"));
        osVo.setAvailableProcessors((Integer) connection.getAttribute(objectName, "AvailableProcessors"));

        osVo.setFreePhysicalMemory((Long) connection.getAttribute(objectName, "FreePhysicalMemorySize"));
        osVo.setFreeSwapSpaceSize((Long) connection.getAttribute(objectName, "FreeSwapSpaceSize"));
        osVo.setProcessCpuTime((Long) connection.getAttribute(objectName, "ProcessCpuTime"));
        osVo.setCommittedVirtualMemorySize(
                (Long) connection.getAttribute(objectName, "CommittedVirtualMemorySize"));
        osVo.setTotalPhysicalMemorySize((Long) connection.getAttribute(objectName, "TotalPhysicalMemorySize"));
        osVo.setTotalSwapSpaceSize((Long) connection.getAttribute(objectName, "TotalSwapSpaceSize"));

    } catch (Exception e) {
        logger.error("unhandled exception has errored : ", e);
    }

    return osVo;
}

From source file:com.app.server.EARDeployer.java

public void init(Vector serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) {
    this.serviceList = serviceList;
    this.serverConfig = serverConfig;
    this.mbeanServer = mbeanServer;
    this.registry = registry;
    fsManager = new StandardFileSystemManager();
    try {//w  w w  . jav a  2 s  . c o m
        warObjectName = new ObjectName("com.app.server:type=deployer,service=WARDeployer");
        ejbObjectName = new ObjectName("com.app.server:type=deployer,service=EJBDeployer");
        sarObjectName = new ObjectName("com.app.server:type=deployer,service=SARDeployer");
        rarObjectName = new ObjectName("com.app.server:type=deployer,service=RARDeployer");
        ezbObjectName = new ObjectName("com.app.server:type=deployer,service=EZBeansDeployer");
        this.executorServiceMap = (Hashtable) mbeanServer.getAttribute(warObjectName, "ExecutorServiceMap");
        this.urlClassLoaderMap = (Hashtable) mbeanServer.getAttribute(warObjectName, "UrlClassLoaderMap");
        System.setProperty("java.io.tmpdir", serverConfig.getCachedir());
        /*DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir));
        //fsManager.setReplicator(new PrivilegedFileReplicator(replicator));
        fsManager.setTemporaryFileStore(replicator);*/
        fsManager.init();
    } catch (Exception e) {
        log.error("Error in initialization", e);
        // TODO Auto-generated catch block
        //e3.printStackTrace();
    }
}

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 w ww .j  a  va2  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:dk.dma.ais.reader.AisReaders.java

public static void manageGroup(AisReaderGroup group) throws JMException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName mxbeanName = new ObjectName("dk.dma.ais.readers.group." + group.name + ":name=Group");
    mbs.registerMBean(new AisReaderGroupMXBeanImpl(group), mxbeanName);
    for (AisTcpReader r : group.readers.values()) {
        mxbeanName = new ObjectName(
                "dk.dma.ais.readers.group." + group.name + ":source=Source-" + r.getSourceId());
        mbs.registerMBean(new AisReaderMXBeanImpl(r), mxbeanName);

    }/*from  w  w  w  .ja  v  a 2 s .c o m*/
}