Search in sources :

Example 11 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project zookeeper by apache.

the class JMXEnv method dump.

public static void dump() throws IOException {
    LOG.info("JMXEnv.dump() follows");
    Set<ObjectName> beans;
    try {
        beans = conn().queryNames(new ObjectName(CommonNames.DOMAIN + ":*"), null);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    }
    for (ObjectName bean : beans) {
        LOG.info("bean:" + bean.toString());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 12 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project zookeeper by apache.

the class JMXEnv method ensureBeanAttribute.

/**
     * Ensure that the specified bean name and its attribute is registered. Note
     * that these are components of the name. It waits in a loop up to 60
     * seconds before failing if there is a mismatch. This will return the beans
     * which are not matched.
     *
     * @param expectedName
     *            - expected bean
     * @param expectedAttribute
     *            - expected attribute
     * @return the value of the attribute
     *
     * @throws Exception
     */
public static Object ensureBeanAttribute(String expectedName, String expectedAttribute) throws Exception {
    String value = "";
    LOG.info("ensure bean:{}, attribute:{}", new Object[] { expectedName, expectedAttribute });
    Set<ObjectName> beans;
    int nTry = 0;
    do {
        if (nTry++ > 0) {
            Thread.sleep(500);
        }
        try {
            beans = conn().queryNames(new ObjectName(CommonNames.DOMAIN + ":*"), null);
        } catch (MalformedObjectNameException e) {
            throw new RuntimeException(e);
        }
        LOG.info("expect:" + expectedName);
        for (ObjectName bean : beans) {
            // check the existence of name in bean
            if (bean.toString().equals(expectedName)) {
                LOG.info("found:{} {}", new Object[] { expectedName, bean });
                return conn().getAttribute(bean, expectedAttribute);
            }
        }
    } while (nTry < 120);
    Assert.fail("Failed to find bean:" + expectedName + ", attribute:" + expectedAttribute);
    return value;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 13 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project jcollectd by collectd.

the class CollectdMBeanRegistry method getMBean.

private Map<String, Number> getMBean(ValueList vl) {
    String instance = vl.getPluginInstance();
    StringBuffer bname = new StringBuffer();
    bname.append(getRootName(vl.getHost(), vl));
    if (!vl.defined(instance)) {
        List<DataSource> ds = vl.getDataSource();
        if (ds == null) {
            ds = TypesDB.getInstance().getType(vl.getType());
        }
        if ((ds != null) && (ds.size() > 1)) {
            //e.g. ds = {rx,tx} -> type=if_octets,typeInstance=en1 
            instance = vl.getTypeInstance();
        }
    }
    if (vl.defined(instance)) {
        bname.append(',').append("name=").append(instance);
    }
    ObjectName name;
    try {
        name = new ObjectName(bname.toString());
    } catch (MalformedObjectNameException e) {
        throw new IllegalArgumentException(bname + ": " + e);
    }
    Map<String, Number> metrics = getMBean(name);
    if (metrics != null) {
        return metrics;
    }
    metrics = new HashMap<String, Number>();
    beans.put(name, metrics);
    try {
        bs.registerMBean(new CollectdMBean(metrics), name);
        if (_doSummary) {
            ObjectName sname = new ObjectName(getRootName("__summary__", vl));
            if (!bs.isRegistered(sname)) {
                ObjectName query = new ObjectName(getRootName(null, vl));
                CollectdSummaryMBean summary = new CollectdSummaryMBean(query, metrics);
                summary.setMBeanRegistry(this);
                bs.registerMBean(summary, sname);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return metrics;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerNotFoundException(javax.management.ListenerNotFoundException) DataSource(org.collectd.api.DataSource) ObjectName(javax.management.ObjectName)

Example 14 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project jetty.project by eclipse.

the class JavaMonitorAction method parseResponse.

/* ------------------------------------------------------------ */
private void parseResponse(Properties response) {
    if (response.get("onhold") != null)
        throw new Error("Suspended");
    if (response.get("session") != null) {
        _session = (String) response.remove("session");
        AggregateEventTrigger trigger = (AggregateEventTrigger) getTrigger();
        String queryString;
        ObjectName[] queryResults;
        for (Map.Entry<Object, Object> entry : response.entrySet()) {
            String[] values = ((String) entry.getValue()).split("\\|");
            queryString = values[0];
            if (queryString.startsWith("com.javamonitor.openfire"))
                continue;
            if (queryString.startsWith("com.javamonitor")) {
                queryString = "org.eclipse.jetty.monitor.integration:type=javamonitortools,id=0";
            }
            queryResults = null;
            try {
                queryResults = queryNames(queryString);
            } catch (IOException e) {
                LOG.debug(e);
            } catch (MalformedObjectNameException e) {
                LOG.debug(e);
            }
            if (queryResults != null) {
                int idx = 0;
                for (ObjectName objName : queryResults) {
                    String id = entry.getKey().toString() + (idx == 0 ? "" : ":" + idx);
                    String name = queryString.equals(objName.toString()) ? "" : objName.toString();
                    boolean repeat = Boolean.parseBoolean(values[2]);
                    trigger.add(new JavaMonitorTrigger(objName, values[1], id, name, repeat));
                }
            }
        }
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) Map(java.util.Map) AggregateEventTrigger(org.eclipse.jetty.monitor.triggers.AggregateEventTrigger)

Example 15 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project sonarqube by SonarSource.

the class Jmx method register.

/**
   * Register a MBean to JMX server
   */
public static void register(String name, Object instance) {
    try {
        Class mbeanInterface = guessMBeanInterface(instance);
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));
    } catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new IllegalStateException("Can not register MBean [" + name + "]", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)123 ObjectName (javax.management.ObjectName)115 MBeanServer (javax.management.MBeanServer)34 MBeanRegistrationException (javax.management.MBeanRegistrationException)32 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)26 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)25 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)14 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)6 StandardMBean (javax.management.StandardMBean)5 CacheServiceMBean (org.apache.cassandra.service.CacheServiceMBean)5 Map (java.util.Map)4 HashSet (java.util.HashSet)3 CacheException (javax.cache.CacheException)3 Group (org.apache.catalina.Group)3 User (org.apache.catalina.User)3 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)3