Search in sources :

Example 6 with JMXConnector

use of javax.management.remote.JMXConnector in project jcollectd by collectd.

the class RemoteMBeanSender method setMBeanServerConnection.

public void setMBeanServerConnection(JMXServiceURL url) throws IOException {
    JMXConnector connector = JMXConnectorFactory.connect(url);
    setMBeanServerConnection(connector.getMBeanServerConnection());
}
Also used : JMXConnector(javax.management.remote.JMXConnector)

Example 7 with JMXConnector

use of javax.management.remote.JMXConnector in project druid by alibaba.

the class StatViewServlet method initJmxConn.

/**
     * 初始化jmx连接
     * 
     * @throws IOException
     */
private void initJmxConn() throws IOException {
    if (jmxUrl != null) {
        JMXServiceURL url = new JMXServiceURL(jmxUrl);
        Map<String, String[]> env = null;
        if (jmxUsername != null) {
            env = new HashMap<String, String[]>();
            String[] credentials = new String[] { jmxUsername, jmxPassword };
            env.put(JMXConnector.CREDENTIALS, credentials);
        }
        JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
        conn = jmxc.getMBeanServerConnection();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector)

Example 8 with JMXConnector

use of javax.management.remote.JMXConnector in project druid by alibaba.

the class DruidStat method getDataSourceIds.

@SuppressWarnings("all")
public static List<Integer> getDataSourceIds(Option option) throws Exception {
    String address = loadManagementAgentAndGetAddress(option.getPid());
    JMXServiceURL jmxUrl = new JMXServiceURL(address);
    JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl);
    MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
    List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.DATA_SOURCE);
    TabledDataPrinter.printDataSourceData(content, option);
    List<Integer> result = new ArrayList<Integer>();
    for (Map<String, Object> dsStat : content) {
        Integer id = (Integer) dsStat.get("Identity");
        result.add(id);
    }
    return result;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 9 with JMXConnector

use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.

the class JMXConnectionTest method connectorIsClosed.

@Test
public void connectorIsClosed() throws IOException {
    MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
    JMXConnector jmxConnector = mock(JMXConnector.class);
    JMXConnection jmxConnection = new JMXConnection(jmxConnector, mBeanServerConnection);
    jmxConnection.close();
    verify(jmxConnector).close();
}
Also used : JMXConnection(com.googlecode.jmxtrans.connections.JMXConnection) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 10 with JMXConnector

use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.

the class MBeanServerConnectionFactoryTest method connectionIsCreatedForRemoteServer.

@Test
public void connectionIsCreatedForRemoteServer() throws IOException {
    JmxConnectionProvider server = mock(JmxConnectionProvider.class);
    JMXConnector jmxConnector = mock(JMXConnector.class);
    MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
    when(server.isLocal()).thenReturn(false);
    when(server.getServerConnection()).thenReturn(jmxConnector);
    when(jmxConnector.getMBeanServerConnection()).thenReturn(mBeanServerConnection);
    JMXConnection jmxConnection = factory.makeObject(server);
    assertThat(jmxConnection.getMBeanServerConnection()).isSameAs(mBeanServerConnection);
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Aggregations

JMXConnector (javax.management.remote.JMXConnector)118 MBeanServerConnection (javax.management.MBeanServerConnection)85 JMXServiceURL (javax.management.remote.JMXServiceURL)78 ObjectName (javax.management.ObjectName)54 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 MBeanServer (javax.management.MBeanServer)37 IOException (java.io.IOException)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)22 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Attribute (javax.management.Attribute)13 MalformedURLException (java.net.MalformedURLException)12 RemoteException (java.rmi.RemoteException)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 LocateRegistry (java.rmi.registry.LocateRegistry)8 Registry (java.rmi.registry.Registry)8 Properties (java.util.Properties)7