Here you can find the source of invokeRemoteMBeanOperation(String remoteURL, String jmxName, Class
public static <T, R> R invokeRemoteMBeanOperation(String remoteURL, String jmxName, Class<T> klass, Function<T, R> function) throws MalformedObjectNameException, IOException
//package com.java2s; /*//from w ww. ja v a 2 s .co m * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ import java.io.IOException; import java.lang.management.ManagementFactory; import java.util.function.Function; import javax.management.JMX; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; public class Main { public static <T, R> R invokeRemoteMBeanOperation(String remoteURL, String jmxName, Class<T> klass, Function<T, R> function) throws MalformedObjectNameException, IOException { JMXServiceURL jmxURL = new JMXServiceURL(remoteURL); try (JMXConnector jmxc = JMXConnectorFactory.connect(jmxURL, null)) { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); T remoteMBean = getMBean(jmxName, klass, mbsc); return function.apply(remoteMBean); } } private static <T> T getMBean(String jmxName, Class<T> klass, MBeanServerConnection mbsc) throws MalformedObjectNameException { ObjectName objectName = new ObjectName(jmxName); if (JMX.isMXBeanInterface(klass)) { return JMX.newMXBeanProxy(mbsc, objectName, klass); } else { return JMX.newMBeanProxy(mbsc, objectName, klass); } } public static <T> T getMBean(String jmxName, Class<T> klass) throws MalformedObjectNameException { return getMBean(jmxName, klass, ManagementFactory.getPlatformMBeanServer()); } }