use of javax.management.ObjectInstance in project jmxtrans by jmxtrans.
the class JmxResultProcessorTest method canReadTabularData.
@Test
public void canReadTabularData() throws MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException {
ObjectInstance runtime = getRuntime();
AttributeList attr = ManagementFactory.getPlatformMBeanServer().getAttributes(runtime.getObjectName(), new String[] { "SystemProperties" });
List<Result> results = new JmxResultProcessor(dummyQueryWithResultAlias(), runtime, attr.asList(), runtime.getClassName(), TEST_DOMAIN_NAME).getResults();
assertThat(results.size()).isGreaterThan(2);
Optional<Result> result = from(results).firstMatch(new ByAttributeName("SystemProperties.java.version"));
assertThat(result.isPresent()).isTrue();
assertThat(result.get().getAttributeName()).isEqualTo("SystemProperties.java.version");
Map<String, Object> values = result.get().getValues();
assertThat(values).hasSize(2);
Object objectValue = result.get().getValues().get("key");
assertThat(objectValue).isInstanceOf(String.class);
String key = (String) objectValue;
assertThat(key).isEqualTo("java.version");
}
use of javax.management.ObjectInstance in project rest.li by linkedin.
the class LoadBalancerClientCli method resetTogglingStores.
public static void resetTogglingStores(String host, boolean enabled) throws Exception {
MonitoredHost _host = MonitoredHost.getMonitoredHost(new HostIdentifier(host));
for (Object pidObj : _host.activeVms()) {
int pid = (Integer) pidObj;
System.out.println("checking pid: " + pid);
JMXServiceURL jmxUrl = null;
com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid + "");
try {
// get the connector address
String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);
// establish connection to connector server
if (connectorAddress != null) {
jmxUrl = new JMXServiceURL(connectorAddress);
}
} finally {
vm.detach();
}
if (jmxUrl != null) {
System.out.println("got jmx url: " + jmxUrl);
// connect to jmx
JMXConnector connector = JMXConnectorFactory.connect(jmxUrl);
connector.connect();
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// look for all beans in the d2 name space
Set<ObjectInstance> objectInstances = mbeanServer.queryMBeans(new ObjectName("com.linkedin.d2:*"), null);
for (ObjectInstance objectInstance : objectInstances) {
System.err.println("checking object: " + objectInstance.getObjectName());
// if we've found a toggling store, then toggle it
if (objectInstance.getObjectName().toString().endsWith("TogglingStore")) {
System.out.println("found toggling zk store, so toggling to: " + enabled);
mbeanServer.invoke(objectInstance.getObjectName(), "setEnabled", new Object[] { enabled }, new String[] { "boolean" });
}
}
} else {
System.out.println("pid is not a jmx process: " + pid);
}
}
}
use of javax.management.ObjectInstance in project pinpoint by naver.
the class PinpointMBeanServerTest method test.
@Test
public void test() throws Exception {
PinpointMBeanServer mBeanServer = new PinpointMBeanServer();
ATest aTest = new ATest();
mBeanServer.registerMBean(aTest);
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
String mBeanObjectName = "com.navercorp.pinpoint.collector.mbean:type=PinpointMBeanServerTest$ATest";
ObjectName objectName = new ObjectName(mBeanObjectName);
String packageName = this.getClass().getPackage().getName();
ObjectInstance instance = server.getObjectInstance(objectName);
Assert.assertEquals(packageName + ".PinpointMBeanServerTest$ATest", instance.getClassName());
mBeanServer.unregisterMBean(aTest);
}
use of javax.management.ObjectInstance in project graphdb by neo4j-attic.
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 presto by prestodb.
the class RebindSafeMBeanServer method registerMBean.
/**
* Delegates to the wrapped mbean server, but if a mbean is already registered
* with the specified name, the existing instance is returned.
*/
@Override
public ObjectInstance registerMBean(Object object, ObjectName name) throws MBeanRegistrationException, NotCompliantMBeanException {
while (true) {
try {
// try to register the mbean
return mbeanServer.registerMBean(object, name);
} catch (InstanceAlreadyExistsException ignored) {
}
try {
// a mbean is already installed, try to return the already registered instance
ObjectInstance objectInstance = mbeanServer.getObjectInstance(name);
log.debug("%s already bound to %s", name, objectInstance);
return objectInstance;
} catch (InstanceNotFoundException ignored) {
// the mbean was removed before we could get the reference
// start the whole process over again
}
}
}
Aggregations