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());
}
}
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;
}
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;
}
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));
}
}
}
}
}
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);
}
}
Aggregations