Example usage for javax.management MBeanServerConnection getMBeanInfo

List of usage examples for javax.management MBeanServerConnection getMBeanInfo

Introduction

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

Prototype

public MBeanInfo getMBeanInfo(ObjectName name)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException;

Source Link

Document

This method discovers the attributes and operations that an MBean exposes for management.

Usage

From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java

private List<String> getAttributeNames(MBeanServerConnection connection, ObjectInstance objectInstance)
        throws Exception {
    MBeanInfo mbeanInfo = connection.getMBeanInfo(objectInstance.getObjectName());
    MBeanAttributeInfo[] attributes = mbeanInfo.getAttributes();
    return Arrays.asList(attributes).stream().map(attr -> attr.getName()).collect(Collectors.toList());
}

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

protected Set<ObjectName> getAetQueuesObjects(MBeanServerConnection connection) throws AETException {
    ObjectName[] queues;// w w w.  j  av  a  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.jminix.console.resource.AttributeResource.java

@Override
protected Map<String, Object> getModel() {
    String domain = getRequest().getAttributes().get("domain").toString();

    String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString());

    String attribute = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString());

    Map<String, Object> model = new HashMap<String, Object>();

    try {/*from  w  w  w  . j a  v  a  2 s.  com*/
        MBeanServerConnection server = getServer();

        MBeanAttributeInfo info = null;
        for (MBeanAttributeInfo i : server.getMBeanInfo(new ObjectName(domain + ":" + mbean)).getAttributes()) {
            if (i.getName().equals(attribute)) {
                info = i;
            }
        }

        Object value = server.getAttribute(new ObjectName(domain + ":" + mbean), attribute);

        model.put("attribute", info);
        if (value == null) {
            model.put("value", "<null>");
        } else if (value.getClass().isArray()) {
            templateName = "array-attribute";
            model.put("items", value);
        } else if (value instanceof CompositeData) {
            templateName = "composite-attribute";
            model.put("attribute", value);
        } else if (value instanceof TabularData) {
            templateName = "tabular-attribute";
            model.put("attribute", value);
        } else {
            model.put("value", value);
        }

        return model;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (AttributeNotFoundException e) {
        throw new RuntimeException(e);
    } catch (InstanceNotFoundException e) {
        throw new RuntimeException(e);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    } catch (MBeanException e) {
        Exception targetException = e.getTargetException();
        if (targetException instanceof RuntimeErrorException) {
            throw new RuntimeException(targetException.getCause());
        }
        log.warn("Error accessing attribute", e);
        model.put("value", e.getTargetException().getCause().getMessage());
        return model;
    } catch (ReflectionException e) {
        throw new RuntimeException(e);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    } catch (RuntimeException e) {
        model.put("value", e.getMessage());
        log.warn("Error accessing attribute", e);
        return model;
    }
}

From source file:org.wso2.dss.integration.test.jira.issues.CARBON15928JMXDisablingTest.java

private MBeanInfo testMBeanForDatasource() throws Exception {
    Map<String, String[]> env = new HashMap<>();
    String[] credentials = { "admin", "admin" };
    env.put(JMXConnector.CREDENTIALS, credentials);
    try {//from  w  w w .  jav a 2s  .c  o m
        String url = "service:jmx:rmi://localhost:12311/jndi/rmi://localhost:11199/jmxrmi";
        JMXServiceURL jmxUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
        ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource");
        MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject);
        return mBeanInfo;
    } catch (MalformedURLException | MalformedObjectNameException | IntrospectionException
            | ReflectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    }
}

From source file:org.jminix.console.resource.AttributeResource.java

@Override
public void acceptRepresentation(Representation entity) throws ResourceException {
    String value = new Form(entity).getFirstValue("value");

    String domain = getRequest().getAttributes().get("domain").toString();

    String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString());

    String attributeName = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString());

    MBeanServerConnection server = getServer();

    try {/*from ww  w . java2s .co m*/

        String type = "java.lang.String";
        for (MBeanAttributeInfo info : server.getMBeanInfo(new ObjectName(domain + ":" + mbean))
                .getAttributes()) {
            if (info.getName().equals(attributeName)) {
                type = info.getType();
            }
        }

        Object attribute = new ValueParser().parse(value, type);

        if (attribute != null) {
            server.setAttribute(new ObjectName(domain + ":" + mbean), new Attribute(attributeName, attribute));
        }

        String queryString = getQueryString();
        if (queryString == null) {
            queryString = "?";
        }
        queryString += "ok=1";
        getResponse().redirectPermanent(new EncoderBean().encode(attributeName) + queryString);
    } catch (InstanceNotFoundException e) {
        throw new RuntimeException(e);
    } catch (AttributeNotFoundException e) {
        throw new RuntimeException(e);
    } catch (InvalidAttributeValueException e) {
        throw new RuntimeException(e);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    } catch (MBeanException e) {
        throw new RuntimeException(e);
    } catch (ReflectionException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }

}

From source file:org.cloudfoundry.identity.statsd.MBeanMap.java

public MBeanMap(MBeanServerConnection server, ObjectName name) {
    this.server = server;
    this.name = name;
    if (server != null) {
        try {/*from  ww  w .j a  va 2  s.c  om*/
            info = server.getMBeanInfo(name);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    } else {
        info = null;
    }
}

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 .com*/
        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);
    }
}

From source file:org.hyperic.hq.plugin.jboss.jmx.ServerQuery.java

private boolean checkClass(MBeanServerConnection mServer, ObjectName name, String mbeanClass) {
    boolean res = true;
    if (mbeanClass != null) {
        try {/* www  .  j av  a2  s .c o m*/
            MBeanInfo info = mServer.getMBeanInfo(name);
            res = info.getClassName().matches(mbeanClass);
        } catch (Exception e) {
            log.error("mServer.getMBeanInfo(" + name + "): " + e);
            res = false;
        }
    }
    return res;
}

From source file:org.wso2.dss.integration.test.datasource.DataSourceInitializationAtStartUpTestCase.java

@Test(dependsOnMethods = { "isServiceExistAfterRestarting" }, enabled = false)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void testMBeanForDatasource() throws AxisFault {
    Map<String, String[]> env = new HashMap<String, String[]>();
    String[] credentials = { "admin", "admin" };
    env.put(JMXConnector.CREDENTIALS, credentials);
    try {/*from  www. j  a  v a2s  .c  o  m*/
        String url = "service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi";
        JMXServiceURL jmxUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
        ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource");
        MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject);
        Assert.assertNotNull(mBeanInfo, "Data Source is registered in the MBean server");
    } catch (MalformedURLException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (MalformedObjectNameException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (IntrospectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    }

}

From source file:org.wso2.ei.dataservice.integration.test.datasource.DataSourceInitializationAtStartUpTestCase.java

@Test(dependsOnMethods = { "isServiceExistAfterRestarting" }, enabled = false)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void testMBeanForDatasource() throws AxisFault {
    Map<String, String[]> env = new HashMap<String, String[]>();
    String[] credentials = { "admin", "admin" };
    env.put(JMXConnector.CREDENTIALS, credentials);
    try {/*from w w w .j ava 2 s.c  o  m*/
        String url = "service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi";
        JMXServiceURL jmxUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
        ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource");
        MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject);
        Assert.assertNotNull(mBeanInfo, "Datasource is registered in the MBean server");
    } catch (MalformedURLException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (MalformedObjectNameException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (IntrospectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    }

}