use of javax.management.remote.JMXServiceURL in project masquerade by cuba-platform.
the class JmxCallHandler method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
JMXServiceURL url;
try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostInfo.getAddress() + "/jmxrmi");
} catch (MalformedURLException e) {
throw new RuntimeException("Incorrect service URL", e);
}
Map<String, Object> properties = new HashMap<>();
if (hostInfo.getUser() != null) {
properties.put(JMXConnector.CREDENTIALS, new String[] { hostInfo.getUser(), hostInfo.getPassword() });
}
try (JMXConnector jmxc = JMXConnectorFactory.connect(url, properties)) {
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName;
try {
mbeanName = new ObjectName(objectName);
} catch (MalformedObjectNameException e) {
throw new RuntimeException("Incorrect JMX object name", e);
}
MBeanServerInvocationHandler wrappedHandler = new MBeanServerInvocationHandler(mbsc, mbeanName);
if (args != null) {
log.info("Invoke method {} of {} with parameters {}", method.getName(), objectName, args);
} else {
log.info("Invoke method {} of {}", method.getName(), objectName);
}
return wrappedHandler.invoke(proxy, method, args);
} catch (IOException e) {
throw new RuntimeException("Unable to perform JMX call", e);
}
}
use of javax.management.remote.JMXServiceURL in project tesb-rt-se by Talend.
the class ApplicationManagerImpl method createRMIconnector.
public JMXConnector createRMIconnector(String serviceUrl, HashMap<String, String[]> environment) throws MalformedURLException, IOException {
echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server");
JMXServiceURL url = new JMXServiceURL(serviceUrl);
JMXConnector jmxc = JMXConnectorFactory.connect(url, environment);
return jmxc;
}
use of javax.management.remote.JMXServiceURL in project com.revolsys.open by revolsys.
the class JmxUtil method getJmxConnector.
public static JMXConnector getJmxConnector(final String connectorString, final String userName, final String password) {
final HashMap<String, String[]> environment = new HashMap<>();
final String[] jmxCredentials = new String[] { userName, password };
environment.put(JMXConnector.CREDENTIALS, jmxCredentials);
// Get JMXServiceURL of JMX Connector (must be known in advance)
JMXServiceURL jmxServiceUrl;
JMXConnector jmxConnector = null;
try {
jmxServiceUrl = new JMXServiceURL(connectorString);
jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, environment);
} catch (final MalformedURLException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
return jmxConnector;
}
use of javax.management.remote.JMXServiceURL in project ff4j by ff4j.
the class FF4JMBeanTest method openJmxConnection.
private void openJmxConnection() throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Make a connector server...
JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi://");
jmxConnectionServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, mbs);
jmxConnectionServer.start();
JMXServiceURL jmxAddress = jmxConnectionServer.getAddress();
// Now make a connector client using the server's address
jmxConnectionFactory = JMXConnectorFactory.connect(jmxAddress);
mbServConn = jmxConnectionFactory.getMBeanServerConnection();
}
use of javax.management.remote.JMXServiceURL in project eat by nhnent.
the class JMXClient method connect.
/**
* Connect to QA Service
*
* @throws IOException Throw Exception
* @throws MalformedObjectNameException Throw Exception
* @throws InterruptedException Throw Exception
* @throws SuspendExecution Throw Exception
* @throws ExecutionException Throw Exception
*/
private void connect() throws IOException, MalformedObjectNameException, InterruptedException, SuspendExecution, ExecutionException {
if (jmxConnector != null) {
return;
}
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + Config.obj().getQaService().getIpAddress() + ":" + Config.obj().getQaService().getPort() + "/jmxrmi");
jmxConnector = JMXConnectorFactory.connect(url);
MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();
// ObjectName should be same as your MBean name
ObjectName mBeanName = new ObjectName(Config.obj().getQaService().getEndPointName());
// Get MBean proxy instance that will be used to make calls to registered MBean
mBeanProxy = MBeanServerInvocationHandler.newProxyInstance(mbeanServerConnection, mBeanName, QaTestAPIMBean.class, true);
}
Aggregations