Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Re-using AdminAPI JMX connection in application code

We currently create our own JMXConnection(s) to obtain some information like thread status etc, we do this via:

private static Collection<ServiceInstance> getServiceStatuses(final GridServiceContainer gsc) {
    List<ServiceInstance> 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<ServiceStatusMXBean> serviceStatusMXBeans = getServiceStatusMXBeans(serverConnection);
                long[] threadIds = getThreadIdsForServices(serviceStatusMXBeans);
                Map<Long, ThreadInfo> 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

asked 2016-04-09 10:26:36 -0500

leozilla gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

I suggest you maintain a map that will keep GSC (key) and its JMX connection (value).

answered 2016-04-09 11:02:36 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

The problem with this is that we need to maintain this cache, eg remove connection once GSC terminates and handle connection exceptions etc.

leozilla gravatar imageleozilla ( 2016-04-13 04:13:07 -0500 )edit

You can implement relevant listener to remove items from the cache once GSC terminated and the same once GSC started.-------- Original message --------From: forum@ask.gigaspaces.org

You can implement relevant listener to remove items from the cache once GSC terminated and the same once GSC started.-------- Original message --------From: forum@ask.gigaspaces.org

shay hassidim gravatar imageshay hassidim ( 2016-04-13 06:39:47 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-09 10:26:36 -0500

Seen: 59 times

Last updated: Apr 09 '16