Search in sources :

Example 66 with JMXServiceURL

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 67 with JMXServiceURL

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;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector)

Example 68 with JMXServiceURL

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;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException)

Example 69 with JMXServiceURL

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();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MBeanServer(javax.management.MBeanServer)

Example 70 with JMXServiceURL

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);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)280 JMXConnector (javax.management.remote.JMXConnector)150 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)78 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)71 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)22 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Properties (java.util.Properties)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11