use of javax.management.ObjectInstance in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadCompositeData.
@Test
public void canReadCompositeData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
ObjectInstance memory = getMemory();
AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(memory.getObjectName(), new String[] { "HeapMemoryUsage" });
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), memory, attr.asList(), memory.getClassName(), TEST_DOMAIN_NAME).getResults();
assertThat(results).hasSize(1);
Result result = results.get(0);
assertThat(result.getAttributeName()).isEqualTo("HeapMemoryUsage");
assertThat(result.getTypeName()).isEqualTo("type=Memory");
Map<String, Object> values = result.getValues();
assertThat(values).hasSize(4);
Object objectValue = result.getValues().get("init");
assertThat(objectValue).isInstanceOf(Long.class);
}
use of javax.management.ObjectInstance in project jersey by jersey.
the class MBeansTest method checkResourceMBean.
private void checkResourceMBean(String name) throws MalformedObjectNameException {
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName("org.glassfish.jersey:type=myApplication,subType=Uris,resource=\"" + name + "\"");
ObjectInstance mbean = null;
try {
mbean = mBeanServer.getObjectInstance(objectName);
} catch (InstanceNotFoundException e) {
Assert.fail("Resource MBean name '" + name + "' not found.");
}
assertNotNull(mbean);
}
use of javax.management.ObjectInstance in project jmxtrans by jmxtrans.
the class Query method fetchResults.
public Iterable<Result> fetchResults(MBeanServerConnection mbeanServer, ObjectName queryName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
MBeanInfo info = mbeanServer.getMBeanInfo(queryName);
ObjectInstance oi = mbeanServer.getObjectInstance(queryName);
List<String> attributes;
if (attr.isEmpty()) {
attributes = new ArrayList<>();
for (MBeanAttributeInfo attrInfo : info.getAttributes()) {
attributes.add(attrInfo.getName());
}
} else {
attributes = attr;
}
try {
if (!attributes.isEmpty()) {
logger.debug("Executing queryName [{}] from query [{}]", queryName.getCanonicalName(), this);
AttributeList al = mbeanServer.getAttributes(queryName, attributes.toArray(new String[attributes.size()]));
return new JmxResultProcessor(this, oi, al.asList(), info.getClassName(), queryName.getDomain()).getResults();
}
} catch (UnmarshalException ue) {
if ((ue.getCause() != null) && (ue.getCause() instanceof ClassNotFoundException)) {
logger.debug("Bad unmarshall, continuing. This is probably ok and due to something like this: " + "http://ehcache.org/xref/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#52", ue.getMessage());
} else {
throw ue;
}
}
return ImmutableList.of();
}
use of javax.management.ObjectInstance in project neo4j by neo4j.
the class KernelProxy method allBeans.
protected List<Object> allBeans() {
List<Object> beans = new ArrayList<Object>();
Iterable<ObjectInstance> mbeans;
try {
mbeans = server.queryMBeans(mbeanQuery(), null);
} catch (IOException handled) {
return beans;
}
for (ObjectInstance instance : mbeans) {
String className = instance.getClassName();
Class<?> beanType = null;
try {
if (className != null) {
beanType = Class.forName(className);
}
} catch (Exception ignored) {
// fall through
} catch (LinkageError ignored) {
// fall through
}
if (beanType != null) {
try {
beans.add(BeanProxy.load(server, beanType, instance.getObjectName()));
} catch (Exception ignored) {
// fall through
}
}
}
return beans;
}
use of javax.management.ObjectInstance in project camel by apache.
the class DefaultManagementAgent method registerMBeanWithServer.
private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
// have we already registered the bean, there can be shared instances in the camel routes
boolean exists = isRegistered(name);
if (exists) {
if (forceRegistration) {
LOG.info("ForceRegistration enabled, unregistering existing MBean with ObjectName: {}", name);
server.unregisterMBean(name);
} else {
// okay ignore we do not want to force it and it could be a shared instance
LOG.debug("MBean already registered with ObjectName: {}", name);
}
}
// register bean if by force or not exists
ObjectInstance instance = null;
if (forceRegistration || !exists) {
LOG.trace("Registering MBean with ObjectName: {}", name);
instance = server.registerMBean(obj, name);
}
// need to use the name returned from the server as some JEE servers may modify the name
if (instance != null) {
ObjectName registeredName = instance.getObjectName();
LOG.debug("Registered MBean with ObjectName: {}", registeredName);
mbeansRegistered.put(name, registeredName);
}
}
Aggregations