Search in sources :

Example 96 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project flink by apache.

the class JMXServer method internalStart.

private void internalStart(int port) throws IOException {
    rmiServerReference.set(null);
    // this allows clients to lookup the JMX service
    rmiRegistry = new JmxRegistry(port, "jmxrmi", rmiServerReference);
    String serviceUrl = "service:jmx:rmi://localhost:" + port + "/jndi/rmi://localhost:" + port + "/jmxrmi";
    JMXServiceURL url;
    try {
        url = new JMXServiceURL(serviceUrl);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Malformed service url created " + serviceUrl, e);
    }
    final RMIJRMPServerImpl rmiServer = new RMIJRMPServerImpl(port, null, null, null);
    connector = new RMIConnectorServer(url, null, rmiServer, ManagementFactory.getPlatformMBeanServer());
    connector.start();
    // we can't pass the created stub directly to the registry since this would form a cyclic
    // dependency:
    // - you can only start the connector after the registry was started
    // - you can only create the stub after the connector was started
    // - you can only start the registry after the stub was created
    rmiServerReference.set(rmiServer.toStub());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) RMIJRMPServerImpl(javax.management.remote.rmi.RMIJRMPServerImpl) MalformedURLException(java.net.MalformedURLException) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer)

Example 97 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project flink by apache.

the class JMXServerTest method testJMXServiceRegisterMBean.

/**
 * Verifies initialize, registered mBean and retrieval via attribute.
 */
@Test
public void testJMXServiceRegisterMBean() throws Exception {
    TestObject testObject = new TestObject();
    ObjectName testObjectName = new ObjectName("org.apache.flink.management", "key", "value");
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        Optional<JMXServer> server = JMXService.getInstance();
        assertTrue(server.isPresent());
        mBeanServer.registerMBean(testObject, testObjectName);
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + server.get().getPort() + "/jndi/rmi://localhost:" + server.get().getPort() + "/jmxrmi");
        JMXConnector jmxConn = JMXConnectorFactory.connect(url);
        MBeanServerConnection mbeanConnConn = jmxConn.getMBeanServerConnection();
        assertEquals(1, mbeanConnConn.getAttribute(testObjectName, "Foo"));
        mBeanServer.unregisterMBean(testObjectName);
        try {
            mbeanConnConn.getAttribute(testObjectName, "Foo");
        } catch (Exception e) {
            // expected for unregistered objects.
            assertTrue(e instanceof InstanceNotFoundException);
        }
    } finally {
        JMXService.stopInstance();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServerConnection(javax.management.MBeanServerConnection) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 98 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project flink by apache.

the class JMXReporterTest method testJMXAvailability.

/**
 * Verifies that we can connect to multiple JMXReporters running on the same machine.
 */
@Test
void testJMXAvailability() throws Exception {
    final JMXReporter rep1 = new JMXReporter("9040-9055");
    final JMXReporter rep2 = new JMXReporter("9040-9055");
    Gauge<Integer> g1 = () -> 1;
    Gauge<Integer> g2 = () -> 2;
    rep1.notifyOfAddedMetric(g1, "rep1", metricGroup);
    rep2.notifyOfAddedMetric(g2, "rep2", metricGroup);
    ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
    ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
    JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep1.getPort().get() + "/jndi/rmi://localhost:" + rep1.getPort().get() + "/jmxrmi");
    JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
    MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();
    assertThat(mCon1.getAttribute(objectName1, "Value")).isEqualTo(1);
    assertThat(mCon1.getAttribute(objectName2, "Value")).isEqualTo(2);
    jmxCon1.close();
    JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep2.getPort().get() + "/jndi/rmi://localhost:" + rep2.getPort().get() + "/jmxrmi");
    JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
    MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();
    assertThat(mCon2.getAttribute(objectName1, "Value")).isEqualTo(1);
    assertThat(mCon2.getAttribute(objectName2, "Value")).isEqualTo(2);
    // JMX Server URL should be identical since we made it static.
    assertThat(url2).isEqualTo(url1);
    rep1.notifyOfRemovedMetric(g1, "rep1", null);
    rep1.notifyOfRemovedMetric(g2, "rep2", null);
    jmxCon2.close();
    rep1.close();
    rep2.close();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test)

Example 99 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project cassandra-mesos-deprecated by mesosphere.

the class ProdJmxConnect method connect.

private void connect() throws IOException {
    lock.lock();
    try {
        if (jmxc != null) {
            return;
        }
        final JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
        final Map<String, Object> env = new HashMap<>();
        if (username != null) {
            final String[] creds = { username, password };
            env.put(JMXConnector.CREDENTIALS, creds);
        }
        jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        mbeanServerConn = jmxc.getMBeanServerConnection();
    } finally {
        lock.unlock();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL)

Example 100 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project voldemort by voldemort.

the class AbstractFailureDetectorTest method assertJmxEquals.

protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception {
    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"), null, ManagementFactory.getPlatformMBeanServer());
    cs.start();
    JMXConnector cc = null;
    try {
        cc = JMXConnectorFactory.connect(cs.getAddress());
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();
        ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), failureDetector.getClass().getSimpleName());
        Object availableNodes = mbsc.getAttribute(objectName, attributeName);
        assertEquals(attributeValue, availableNodes);
    } finally {
        if (cc != null)
            cc.close();
        cs.stop();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) JMXConnectorServer(javax.management.remote.JMXConnectorServer) 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