Quantcast
Channel: Gigaspaces XAP forum - RSS feed
Viewing all articles
Browse latest Browse all 1486

Re-using AdminAPI JMX connection in application code

$
0
0
We currently create our own JMXConnection(s) to obtain some information like thread status etc, we do this via: private static Collection getServiceStatuses(final GridServiceContainer gsc) { List result = Collections.emptyList(); try { String jmxUrl = gsc.getVirtualMachine().getDetails().getJmxUrl(); if (jmxUrl != null) { JMXServiceURL url = new JMXServiceURL(jmxUrl); try (JMXConnector jmxc = JMXConnectorFactory.connect(url)) { MBeanServerConnection serverConnection = jmxc.getMBeanServerConnection(); Collection serviceStatusMXBeans = getServiceStatusMXBeans(serverConnection); long[] threadIds = getThreadIdsForServices(serviceStatusMXBeans); Map threadStatuses = getThreadStatuses(serverConnection, threadIds); result = serviceStatusMXBeans.stream().map(mxBean -> getServiceStatus(gsc, mxBean, threadStatuses)).collect(Collectors.toList()); } } } catch (IOException | MalformedObjectNameException | RuntimeException e) { LOG.warn("Error obtaining service statuses from JMX.", e); } return result; } As you can see, every time we execute this method, we create and tear down the connection. My question is, how could I re-use the JMX connections that are already created by the AdminAPI? Looking at the OpenSpaces code, I guess I could just cast the GridServiceContainer or the ProcessingUnitContainer to MBeanServer but I am not sure. Can you give me some hints or maybe you can show me an even easier way of doing this. Br, David

Viewing all articles
Browse latest Browse all 1486

Trending Articles