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:io.github.tfahub.dropwizard.logging.XmlBasedLoggingFactory.java

void registerJmxConfiguratorMBean() throws JMException {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName objectName = new ObjectName("io.dropwizard:type=Logging");
    if (!server.isRegistered(objectName)) {
        server.registerMBean(new JMXConfigurator(loggerContext, server, objectName), objectName);
    }//from  w  ww .  j av  a  2 s  .co m
}

From source file:com.tesora.dve.server.bootstrap.BootstrapHost.java

@Override
protected void registerMBeans() {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    try {/*from  ww  w . jav a 2s  .  c o  m*/
        server.registerMBean(this, new ObjectName(MBEAN_BOOTSTRAP_HOST));
    } catch (Exception e) {
        logger.error("Unable to register " + MBEAN_BOOTSTRAP_HOST + " mbean", e);
    }

    try {
        HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
        server.registerMBean(hdm, new ObjectName(MBEAN_LOG4J_HIERARCHY));

        // Add the root logger to the Hierarchy MBean
        hdm.addLoggerMBean(Logger.getRootLogger().getName());

        LoggerRepository r = LogManager.getLoggerRepository();

        @SuppressWarnings("rawtypes")
        Enumeration loggers = r.getCurrentLoggers();
        while (loggers.hasMoreElements()) {
            hdm.addLoggerMBean(((Logger) loggers.nextElement()).getName());
        }
    } catch (Exception e) {
        logger.error("Unable to register " + MBEAN_LOG4J_HIERARCHY + " mbean", e);
    }

    super.registerMBeans();
}

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

public void should_remove_auth_role_from_feature() throws Exception {
    ObjectName objectName = new ObjectName(FF4J_OBJECT_NAME);
    mbServConn.invoke(objectName, "removeAuthRoleFromFeature",
            new Object[] { "ROLE_USER", "jmxFeatureWithAuth" },
            new String[] { "java.lang.String", "java.lang.String" });
}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

/**
 * constructor used for creating JMX connection
 *///from  ww  w .  j  a va2  s.c o m
public JMXDataUpdater(String server, String port, Cluster cluster) {
    this.serverName = server;
    this.port = port;
    this.userName = cluster.getJmxUserName();
    this.userPassword = cluster.getJmxUserPassword();
    this.cluster = cluster;

    try {
        // Initialize MBean object names
        this.MBEAN_OBJECT_NAME_SYSTEM_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_SYSTEM_DISTRIBUTED);
        this.MBEAN_OBJECT_NAME_REGION_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_REGION_DISTRIBUTED);
        this.MBEAN_OBJECT_NAME_MEMBER_MANAGER = new ObjectName(PulseConstants.OBJECT_NAME_MEMBER_MANAGER);
        this.MBEAN_OBJECT_NAME_MEMBER = new ObjectName(PulseConstants.OBJECT_NAME_MEMBER);
        this.MBEAN_OBJECT_NAME_STATEMENT_DISTRIBUTED = new ObjectName(
                PulseConstants.OBJECT_NAME_STATEMENT_DISTRIBUTED);

        // For SQLFire
        if (PulseConstants.PRODUCT_NAME_SQLFIRE.equalsIgnoreCase(PulseController.getPulseProductSupport())) {
            this.MBEAN_OBJECT_NAME_TABLE_AGGREGATE = new ObjectName(PulseConstants.OBJECT_NAME_TABLE_AGGREGATE);
        }

    } catch (MalformedObjectNameException e) {
        if (LOGGER.severeEnabled()) {
            LOGGER.severe(e.getMessage(), e);
        }
    } catch (NullPointerException e) {
        if (LOGGER.severeEnabled()) {
            LOGGER.severe(e.getMessage(), e);
        }
    }

}

From source file:io.github.albertopires.mjc.JConsoleM.java

public final int getAvailableProcessors() throws Exception {
    ObjectName mbeanName;/*from   w  w w .j av a 2  s  . c  o m*/
    mbeanName = new ObjectName("java.lang:type=OperatingSystem");
    Integer ut;
    ut = (Integer) mbsc.getAttribute(mbeanName, "AvailableProcessors");
    return ut.intValue();
}

From source file:io.fabric8.mq.controller.coordination.KubernetesControl.java

private ObjectName getBrokerJMXRoot(J4pClient client) throws Exception {

    String type = "org.apache.activemq:*,type=Broker";
    String attribute = "BrokerName";
    ObjectName objectName = new ObjectName(type);
    J4pResponse<J4pReadRequest> result = client.execute(new J4pReadRequest(objectName, attribute));
    JSONObject jsonObject = result.getValue();
    return new ObjectName(jsonObject.keySet().iterator().next().toString());

}

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

public static String getCpuUsage(String nodeName) {
    String cpuUsageStr = null;//from  w w  w  . j  a v a  2s.c  o m
    JmxClient jmxClient = jmxClientMap.get(nodeName);

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

        ObjectName osObjectName = new ObjectName("java.lang:type=OperatingSystem");
        ObjectName runTimeObjectName = new ObjectName("java.lang:type=Runtime");

        //before Cpu
        int availableProcessors = (Integer) connection.getAttribute(osObjectName, "AvailableProcessors");
        long prevUpTime = (Long) connection.getAttribute(runTimeObjectName, "Uptime");
        long prevProcessCpuTime = (Long) connection.getAttribute(osObjectName, "ProcessCpuTime");

        try {
            Thread.sleep(1000);
        } catch (Exception ignored) {
            // ignore
        }

        //after Cpu
        long upTime = (Long) connection.getAttribute(runTimeObjectName, "Uptime");
        long processCpuTime = (Long) connection.getAttribute(osObjectName, "ProcessCpuTime");

        long elapsedCpu = processCpuTime - prevProcessCpuTime;
        long elapsedTime = upTime - prevUpTime;

        double cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors));
        cpuUsageStr = String.format("%.2f", cpuUsage);
        logger.debug("nodeName: [{}], cpuUsage: [{}]", nodeName, cpuUsageStr);
    } catch (Exception e) {
        logger.error("unhandled exception has errored : ", e);
    }

    return cpuUsageStr;
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreadsCustomMarshal.java

public static void registerProtofile(String jmxHost, int jmxPort, String cacheContainerName) throws Exception {
    JMXConnector jmxConnector = JMXConnectorFactory
            .connect(new JMXServiceURL("service:jmx:remoting-jmx://" + jmxHost + ":" + jmxPort));
    MBeanServerConnection jmxConnection = jmxConnector.getMBeanServerConnection();

    ObjectName protobufMetadataManagerObjName = new ObjectName("jboss.infinispan:type=RemoteQuery,name="
            + ObjectName.quote(cacheContainerName) + ",component=ProtobufMetadataManager");

    // initialize client-side serialization context via JMX
    byte[] descriptor = readClasspathResource("/model/userbaseinfo.protobin");
    jmxConnection.invoke(protobufMetadataManagerObjName, "registerProtofile", new Object[] { descriptor },
            new String[] { byte[].class.getName() });
    jmxConnector.close();//from   www  .j  a  va  2  s  . com
}

From source file:com.brienwheeler.lib.jmx.logging.Log4jMBeanExporter.java

private synchronized int registerMBeansInternal() {
    // protect against JMX invocation while shutting down
    if (shutdown)
        return 0;

    MBeanServer server = JmxUtils.locateMBeanServer();

    HierarchyDynamicMBean hdm;//w ww.jav a 2 s .com
    synchronized (this.getClass()) {
        boolean usedNew = hierarchyDynamicMBean.compareAndSet(null, new HierarchyDynamicMBean());
        hdm = hierarchyDynamicMBean.get();
        if (usedNew) {
            try {
                ObjectName mbo = new ObjectName(LOG4J_HIERARCHY_DEFAULT);
                server.registerMBean(hdm, mbo);
                registeredHierarchy = true;
                // Add the root logger to the Hierarchy MBean
                hdm.addLoggerMBean(Logger.getRootLogger().getName());
            } catch (Exception e) {
                log.error("Error initializing Log4jMBeanExporter", e);
                return 0;
            }
        }
    }

    // Get each logger from the Log4J Repository and add it to
    // the Hierarchy MBean created above.
    LoggerRepository r = LogManager.getLoggerRepository();

    Enumeration<?> loggers = r.getCurrentLoggers();
    int count = 0;

    while (loggers.hasMoreElements()) {
        String name = ((Logger) loggers.nextElement()).getName();
        // this name definition copied from HierarchyDynamicMBean
        ObjectName objectName;
        try {
            objectName = new ObjectName("log4j", "logger", name);
        } catch (Exception e) {
            log.error("Error creating JMX name for " + name, e);
            continue;
        }

        if (!server.isRegistered(objectName)) {
            if (log.isDebugEnabled()) {
                log.debug("[contextInitialized]: Registering " + name);
            }
            registeredNames.add(hdm.addLoggerMBean(name));
            count++;
        }
    }

    log.debug("registered " + count + " new Log4j MBeans");
    return count;
}

From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java

private void unregisterAllMBeans(String appId) throws Exception {
    Set<ObjectName> objNames = this.server.queryNames(new ObjectName("*:appId=" + appId + ",*"), null);
    for (ObjectName name : objNames) {
        logger.info("Unregistered MBean: " + name);
        this.server.unregisterMBean(name);
    }/*from  w w w  .  j  av  a  2 s .c  om*/
}