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.fabric8.mq.controller.util.BrokerJmxUtils.java

public static ObjectName getRoot(J4pClient client) throws Exception {
    String type = "org.apache.activemq:*,type=Broker";
    String attribute = "BrokerName";
    ObjectName objectName = new ObjectName(type);
    J4pResponse<J4pReadRequest> response = client.execute(new J4pReadRequest(objectName, attribute));

    JSONObject jsonObject = response.getValue();
    JSONObject nameObject = (JSONObject) jsonObject.values().iterator().next();
    String name = nameObject.values().iterator().next().toString();
    ObjectName result = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + name);
    return result;
}

From source file:io.github.retz.admin.AdminConsoleClient.java

public AdminConsoleClient(JmxClient client) throws MalformedObjectNameException {
    this.client = Objects.requireNonNull(client);
    objectName = new ObjectName("io.github.retz.scheduler:type=AdminConsole");
    this.mapper = new ObjectMapper();
    this.mapper.registerModule(new Jdk8Module());
}

From source file:com.cisco.cta.taxii.adapter.AdapterConfigurationTest.java

@Test
public void jmxStatisticsRegistered() throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("com.cisco.cta.taxii:component=taxii-log-adapter,type=statistics");
    assertTrue(mbs.isRegistered(name));/*from  w  w  w . jav a2 s .c om*/
}

From source file:hivemall.mix.metrics.MetricsRegistry.java

private static ObjectName makeMBeanName(@Nonnull final String domain, @Nonnull final String type,
        @Nonnull final String channelName) {
    final String mbeanName = makeMBeanNameString(domain, type, channelName);
    try {/*w  w  w .  j a  v  a2s  . c o  m*/
        return new ObjectName(mbeanName);
    } catch (MalformedObjectNameException e) {
        throw new IllegalArgumentException(e);
    } catch (NullPointerException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.neophob.sematrix.cli.PixConClientJmx.java

/**
 * /*w w  w. j a va 2 s. com*/
 * @param mbsc
 * @throws Exception
 */
private static void printJmxStatus(MBeanServerConnection mbsc) throws Exception {
    ObjectName mbeanName = new ObjectName(PixelControllerStatus.JMX_BEAN_NAME);

    PixelControllerStatusMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, PixelControllerStatusMBean.class,
            true);

    // print general status information
    System.out.println("\nGeneric:");
    System.out.printf("%-25s: %s\n", "server version", mbeanProxy.getVersion());
    System.out.printf("%-25s: %3.3f (%s of configured fps: %2.0f)\n", "current fps", mbeanProxy.getCurrentFps(),
            PERCENT_FORMAT.format(mbeanProxy.getCurrentFps() / mbeanProxy.getConfiguredFps()),
            mbeanProxy.getConfiguredFps());
    System.out.printf("%-25s: %d\n", "frame count", mbeanProxy.getFrameCount());
    System.out.printf("%-25s: %s\n", "running since",
            DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - mbeanProxy.getStartTime()));

    // print average timing information
    System.out.println("\nThe following average times have been collected during the last "
            + DurationFormatUtils.formatDuration(mbeanProxy.getRecordedMilliSeconds(), "ss.SSS") + " seconds:");
    for (TimeMeasureItemGlobal valueEnum : TimeMeasureItemGlobal.values()) {
        System.out.printf("   %-22s: %3.3fms\n", valueEnum.getReadableName(),
                mbeanProxy.getAverageTime(valueEnum));
    }

    // print output specific timing information
    for (int output = 0; output < mbeanProxy.getNumberOfOutputs(); output++) {
        System.out.println("\nOuput-specific average times for output #" + (output + 1) + ": "
                + mbeanProxy.getOutputType(output).getReadableName());
        for (TimeMeasureItemOutput outputValueEnum : TimeMeasureItemOutput.values()) {
            System.out.printf("   %-22s: %3.3fms\n", outputValueEnum.getReadableName(),
                    mbeanProxy.getOutputAverageTime(output, outputValueEnum));
        }
    }
}

From source file:com.googlecode.psiprobe.controllers.threads.ThreadStackController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    long threadID = ServletRequestUtils.getLongParameter(request, "id", -1);
    String threadName = ServletRequestUtils.getStringParameter(request, "name", null);

    List stack = null;//from w  w w  .  j  ava2s . c o  m
    MBeanServer mBeanServer = new Registry().getMBeanServer();
    ObjectName threadingOName = new ObjectName("java.lang:type=Threading");

    if (threadID == -1 && threadName != null) {
        // find thread by name
        long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds");
        for (int i = 0; i < allIds.length; i++) {
            CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[] { new Long(allIds[i]) }, new String[] { "long" });
            String name = JmxTools.getStringAttr(cd, "threadName");
            if (threadName.equals(name)) {
                threadID = allIds[i];
                break;
            }
        }
    }

    if (mBeanServer.queryMBeans(threadingOName, null) != null && threadID != -1) {

        CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                new Object[] { new Long(threadID), new Integer(stackElementCount) },
                new String[] { "long", "int" });
        if (cd != null) {
            CompositeData[] elements = (CompositeData[]) cd.get("stackTrace");
            threadName = JmxTools.getStringAttr(cd, "threadName");

            stack = new ArrayList(elements.length);

            for (int i = 0; i < elements.length; i++) {
                CompositeData cd2 = elements[i];
                ThreadStackElement tse = new ThreadStackElement();
                tse.setClassName(JmxTools.getStringAttr(cd2, "className"));
                tse.setFileName(JmxTools.getStringAttr(cd2, "fileName"));
                tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName"));
                tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1));
                tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod"));
                stack.add(tse);
            }
        }
    }

    return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName);
}

From source file:net.testdriven.psiprobe.controllers.threads.ThreadStackController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    long threadID = ServletRequestUtils.getLongParameter(request, "id", -1);
    String threadName = ServletRequestUtils.getStringParameter(request, "name", null);

    List<ThreadStackElement> stack = null;
    MBeanServer mBeanServer = new Registry().getMBeanServer();
    ObjectName threadingOName = new ObjectName("java.lang:type=Threading");

    if (threadID == -1 && threadName != null) {
        // find thread by name
        long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds");
        for (long allId : allIds) {
            CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[] { allId }, new String[] { "long" });
            String name = JmxTools.getStringAttr(cd, "threadName");
            if (threadName.equals(name)) {
                threadID = allId;/*  w ww.  j  av  a 2 s  . c  o  m*/
                break;
            }
        }
    }

    if (mBeanServer.queryMBeans(threadingOName, null) != null && threadID != -1) {

        CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                new Object[] { threadID, stackElementCount }, new String[] { "long", "int" });
        if (cd != null) {
            CompositeData[] elements = (CompositeData[]) cd.get("stackTrace");
            threadName = JmxTools.getStringAttr(cd, "threadName");

            stack = new ArrayList<>(elements.length);

            for (CompositeData cd2 : elements) {
                ThreadStackElement tse = new ThreadStackElement();
                tse.setClassName(JmxTools.getStringAttr(cd2, "className"));
                tse.setFileName(JmxTools.getStringAttr(cd2, "fileName"));
                tse.setMethodName(JmxTools.getStringAttr(cd2, "methodName"));
                tse.setLineNumber(JmxTools.getIntAttr(cd2, "lineNumber", -1));
                tse.setNativeMethod(JmxTools.getBooleanAttr(cd2, "nativeMethod"));
                stack.add(tse);
            }
        }
    }

    return new ModelAndView(getViewName(), "stack", stack).addObject("threadName", threadName);
}

From source file:org.jmxtrans.embedded.spring.SpringEmbeddedJmxTrans.java

@Override
public ObjectName getObjectName() throws MalformedObjectNameException {
    return new ObjectName(objectName);
}

From source file:com.zavakid.mushroom.util.MBeans.java

static private ObjectName getMBeanName(String serviceName, String nameName) {
    ObjectName name = null;/*from   ww w  . ja  v  a2 s.c  om*/
    String nameStr = "Mushroom:service=" + serviceName + ",name=" + nameName;
    try {
        name = new ObjectName(nameStr);
    } catch (MalformedObjectNameException e) {
        LOG.warn("Error creating MBean object name: " + nameStr, e);
    }
    return name;
}

From source file:com.taobao.common.store.util.MyMBeanServer.java

/**
 * MBean/*w  w w  .j  av a  2s.  com*/
 * 
 * @param o
 * @param name
 */
public void registMBean(final Object o, final String name) {
    // MBean
    if (null != mbs) {
        try {
            mbs.registerMBean(o, new ObjectName(o.getClass().getPackage().getName() + ":type="
                    + o.getClass().getSimpleName()
                    + (null == name ? (",id=" + o.hashCode()) : (",name=" + name + "-" + o.hashCode()))));
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}