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.joyent.manta.client.MetricReporterSupplier.java

private static JmxReporter buildJmxReporter(final MantaClientMetricConfiguration metricConfig) {
    return JmxReporter.forRegistry(metricConfig.getRegistry()).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).createsObjectNamesWith((type, domain, name) -> {
                final String metricJmxObjectName = String.format(MantaClientAgent.FMT_MBEAN_OBJECT_NAME, name,
                        metricConfig.getClientId());

                try {
                    return new ObjectName(metricJmxObjectName);
                } catch (final MalformedObjectNameException e) {
                    final String msg = String.format(
                            "Unable to create JMX object name for metric: %s (name=%s, clientId=%s)",
                            metricJmxObjectName, name, metricConfig.getClientId());
                    throw new RuntimeException(msg, e);
                }/*from  w  w  w . j  a  v a 2s  .  c om*/
            }).build();
}

From source file:cc.kune.core.server.mbean.MBeanRegistry.java

/**
 * Register this object itself in the JVM MBean Server.
 * /*from www  . j  a va  2 s  .  com*/
 * @param object
 *          the object
 * @param objectName
 *          the object name
 */
public void registerAsMBean(final Object object, final String objectName) {
    ObjectName mbeanName = null;

    try {
        mbeanName = new ObjectName(objectName);
    } catch (final MalformedObjectNameException e) {
        LOG.error("Error creating MBean ObjectName: " + objectName + ", " + e.getMessage());
    } catch (final NullPointerException e) {
        LOG.error("Error creating MBean ObjectName: " + objectName + ", " + e.getMessage());
    }

    try {
        mbeanServer.registerMBean(object, mbeanName);
    } catch (final InstanceAlreadyExistsException e) {
        LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage());
    } catch (final MBeanRegistrationException e) {
        LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage());
    } catch (final NotCompliantMBeanException e) {
        LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage());
    }

    LOG.info("Registered " + objectName + " as MBean sucessfully");
}

From source file:com.googlecode.psiprobe.Tomcat55ContainerAdaptor.java

public void setWrapper(Wrapper wrapper) {
    if (wrapper != null) {
        host = (Host) wrapper.getParent().getParent();
        try {/*from  w w  w . ja v  a2  s  .c o m*/
            deployerOName = new ObjectName(
                    host.getParent().getName() + ":type=Deployer,host=" + host.getName());
        } catch (MalformedObjectNameException e) {
            // do nothing here
        }
        host.getPipeline().addValve(valve);
        mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
    } else if (host != null) {
        host.getPipeline().removeValve(valve);
    }
}

From source file:io.galeb.router.tests.client.JmxClientService.java

public Long getValue(String name) {
    try {//from  w w  w .j  a  v a 2  s  .  co  m
        final ObjectName mBeanObject = new ObjectName(JmxReporterService.MBEAN_DOMAIN + ":name=" + name);
        return client != null ? (Long) client.getAttribute(mBeanObject, "Value") : 0L;
    } catch (MalformedObjectNameException | IOException | ReflectionException | AttributeNotFoundException
            | InstanceNotFoundException | MBeanException e) {
        logger.error(e.getMessage());
    }
    return -1L;
}

From source file:com.googlecode.arit.mbeans.MBeanScanner.java

public void scanForResources(ResourceListener resourceEventListener) {
    ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer mbs : mbeanServers) {
        MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs);
        if (mbeanAccessor == null) {
            String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName();
            LOG.error(errorMsg);/*w w w.j a  v a2 s.c  o  m*/
            if (messages != null) {
                messages.addMessage(errorMsg);
            }
        } else {
            Set<ObjectName> mbeans;
            try {
                mbeans = mbs.queryNames(new ObjectName("*:*"), null);
            } catch (MalformedObjectNameException ex) {
                // We should never get here
                throw new Error(ex);
            }

            for (ObjectName name : mbeans) {
                Object mbean = mbeanAccessor.retrieve(name);
                SimpleResource<Object> mbeanResource = new SimpleResource<Object>(resourceType, mbean,
                        "MBean: " + name);
                mbeanResource.addClassloaderReference(mbean.getClass().getClassLoader(),
                        "Implementation class: " + mbean.getClass().getName());
                resourceEventListener.onResourceFound(mbeanResource);
            }
        }
    }
}

From source file:io.fabric8.mq.controller.util.BrokerJmxUtils.java

public static List<ObjectName> getDestinations(J4pClient client, ObjectName root, String type)
        throws Exception {
    List<ObjectName> list = new ArrayList<>();
    String objectNameStr = root.toString() + ",destinationType=" + type + ",destinationName=*";
    J4pResponse<J4pReadRequest> response = client
            .execute(new J4pReadRequest(new ObjectName(objectNameStr), "Name"));
    JSONObject value = response.getValue();
    for (Object key : value.keySet()) {
        ObjectName objectName = new ObjectName(key.toString());
        list.add(objectName);// www  .ja v a 2 s  .  co  m
    }

    return list;
}

From source file:com.citrix.g2w.webdriver.util.InvokeMBean.java

/**
 * Method to invoke m bean.//  www.j ava2  s  . c  o  m
 * 
 * @param userName
 *            (user name)
 * @param password
 *            (password)
 * @param rmiHost
 *            (rmi host)
 * @param rmiPort
 *            (rmi port)
 * @param objectName
 *            (object name)
 * @param methodName
 *            (method name)
 * @param params
 *            (array of objects)
 * @param signature
 *            (array of params type)
 * @return mBeanResult 
 *            (list of string containing mbean result)
 */
public List<String> invokeMBean(final String userName, final String password, final String rmiHost,
        final int rmiPort, final String objectName, final String methodName, final Object[] params,
        final String[] signature) {
    List<String> mBeanResult = new ArrayList<String>(2);
    try {
        String[] credentials = { userName, password };

        Map<String, String[]> env = new HashMap<String, String[]>();
        env.put("jmx.remote.credentials", credentials);

        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + rmiHost + ":" + rmiPort + "/jndi/rmi://"
                + rmiHost + ":" + rmiPort + "/jmxrmi");

        JMXConnector connector = JMXConnectorFactory.connect(url, env);

        MBeanServerConnection connection = connector.getMBeanServerConnection();
        ObjectName destConfigName = new ObjectName(objectName);

        Object returnValue = connection.invoke(destConfigName, methodName, params, signature);

        if (returnValue != null) {
            if (returnValue instanceof Collection) {
                Collection c = (Collection) returnValue;
                if (CollectionUtils.isNotEmpty(c)) {
                    for (Object val : c) {
                        mBeanResult.add(val.toString());
                    }
                }
            } else {
                mBeanResult.add(returnValue.toString());
            }
        }
        connector.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return mBeanResult;
}

From source file:com.clustercontrol.HinemosManagerCli.java

private void invoke() {
    System.setProperty("sun.rmi.transport.connectionTimeout", String.valueOf(connectTimeout));
    System.setProperty("sun.rmi.transport.tcp.responseTimeout", String.valueOf(responseTimeout));

    try {/*from w w  w.  java 2  s.co  m*/
        JMXServiceURL url = new JMXServiceURL(
                String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", ip, port));
        Map<String, Object> env = new HashMap<String, Object>();
        if (user != null && password != null) {
            env.put(JMXConnector.CREDENTIALS, new String[] { user, password });
        }
        MBeanServerConnection mbsc = JMXConnectorFactory.connect(url, env).getMBeanServerConnection();

        ObjectName mbeanName = new ObjectName("com.clustercontrol.mbean:type=" + name);
        if (doesOutputInfo) {
            printMBeanInfo(mbsc.getMBeanInfo(mbeanName));
            return;
        }

        Object ret;
        if (attribute != null) {
            ret = mbsc.getAttribute(mbeanName, attribute);
        } else {
            String[] signature = new String[operationArgs.length];
            for (int i = 0; i < signature.length; i++) {
                signature[i] = String.class.getName();
            }
            ret = mbsc.invoke(mbeanName, operation, operationArgs, signature);
        }
        System.out.println(ret);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(2);
    }
}