java类javax.management.remote.JMXConnector的实例源码

JmxNetworkManagerTest.java 文件源码 项目:Byter 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testMBeanServer() throws IOException {
    //connect to server
    final JMXConnector connection = JmxConnectionHelper.buildJmxMPConnector(JMXSERVERIP,serverObj.getConnectorSystemPort());
    //do test
    MBeanServerConnection mbsConnection = JmxServerHelper.getMBeanServer(connection);
    Assert.assertNotNull(mbsConnection);
    if(mbsConnection != null){
        log.log(Level.INFO,"Registered MBeanCount on MBS: " + mbsConnection.getMBeanCount());
    }
    log.log(Level.FINEST, "DONE: testMBeanServer");
}
ClientProvider.java 文件源码 项目:OpenJSharp 阅读 28 收藏 0 点赞 0 评论 0
public JMXConnector newJMXConnector(JMXServiceURL serviceURL,
                                    Map<String,?> environment)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnector(serviceURL, environment);
}
ActiveMQJmxMonitor.java 文件源码 项目:activemq-jmx-monitor 阅读 28 收藏 0 点赞 0 评论 0
public ActiveMQJmxMonitor(String jmxUrl, String brokerName, String[] credentials) throws IOException, MalformedObjectNameException {
    Map<String, String[]> env = new HashMap<>();
    if (credentials != null) {
        env.put(JMXConnector.CREDENTIALS, credentials);
    }
    JMXServiceURL jmxServiceUrl = new JMXServiceURL(jmxUrl);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, env);

    mBeanConnection = jmxConnector.getMBeanServerConnection();
    initObjectNames(brokerName);
}
LauncherLifecycleCommandsDUnitTest.java 文件源码 项目:monarch 阅读 36 收藏 0 点赞 0 评论 0
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort,
    final String memberName) throws Exception {
  JMXConnector connector = null;

  try {
    connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
        "service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));

    MBeanServerConnection connection = connector.getMBeanServerConnection();

    ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");

    QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));

    Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);

    assertNotNull(objectNames);
    assertFalse(objectNames.isEmpty());
    assertEquals(1, objectNames.size());

    // final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
    // memberName);
    ObjectName objectName = objectNames.iterator().next();

    // System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName,
    // objectName);

    return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
  } finally {
    IOUtils.close(connector);
  }
}
JMXMBeanDUnitTest.java 文件源码 项目:monarch 阅读 32 收藏 0 点赞 0 评论 0
private void connectAndValidateAsJmxClient(final int jmxPort, final String serverHostName,
    final boolean useSSL, final boolean useMulti) throws Exception {
  // JMX RMI

  Map<String, Object> environment = new HashMap();

  if (useSSL) {
    System.setProperty("javax.net.ssl.keyStore",
        useMulti ? getMultiKeyKeystore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.keyStoreType", "JKS");
    System.setProperty("javax.net.ssl.keyStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStore",
        useMulti ? getMultiKeyTruststore() : getSimpleSingleKeyKeystore());
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.trustStorePassword", "password");
    environment.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
  }

  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + serverHostName + ":" + jmxPort
      + "/jndi/rmi://" + serverHostName + ":" + jmxPort + "/jmxrmi");
  JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);


  try {
    MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName("GemFire:service=System,type=Distributed");

    // Get MBean proxy instance that will be used to make calls to registered MBean
    DistributedSystemMXBean distributedSystemMXBean =
        JMX.newMBeanProxy(mbeanServerConnection, mbeanName, DistributedSystemMXBean.class, true);

    assertEquals(1, distributedSystemMXBean.getMemberCount());
    assertEquals(1, distributedSystemMXBean.getLocatorCount());

  } finally {
    jmxConnector.close();
  }
}
ClientProvider.java 文件源码 项目:OperatieBRP 阅读 27 收藏 0 点赞 0 评论 0
@Override
public JMXConnector newJMXConnector(final JMXServiceURL url, final Map<String, ?> environment)
        throws MalformedURLException {
    final String protocol = url.getProtocol();
    if (!SimpleJmx.PROTOCOL.equals(protocol)) {
        throw new MalformedURLException(
                "Invalid protocol '" + protocol + "' for provider " + this.getClass().getName());
    }

    return new ClientConnector(url, environment);
}
RMIConnector.java 文件源码 项目:jmx-prometheus-exporter 阅读 22 收藏 0 点赞 0 评论 0
@Override
public @NotNull JMXConnector connect() throws IOException {
  final Map<String, Object> environment = environment();
  if (ssl) {
    environment.put(Context.SECURITY_PROTOCOL, "ssl");
    final SslRMIClientSocketFactory clientSocketFactory = new SslRMIClientSocketFactory();
    environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientSocketFactory);
    environment.put("com.sun.jndi.rmi.factory.socket", clientSocketFactory);
  }
  final JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + address() + "/jmxrmi");
  return JMXConnectorFactory.connect(address, environment);
}
JmxNetworkManagerTest.java 文件源码 项目:Byter 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Test if there are Controller and NetworkManager registered to MBeanServer
 */
@Test
public void testRegisteredObjects() throws IOException {
    //connect to server
    final JMXConnector connection = JmxConnectionHelper.buildJmxMPConnector(JMXSERVERIP,serverObj.getConnectorSystemPort());
    //get MBeanServerConnection
    MBeanServerConnection mbsConnection = JmxServerHelper.getMBeanServer(connection);
    //do test
    Assert.assertNotSame(0,mbsConnection.getMBeanCount()); //check if there are beans registered
    //look for all standard mbeans
    List<ObjectName> standardMbeans = JmxServerHelper.findObjectNames(mbsConnection,"de.b4sh.byter");
    Assert.assertNotEquals(0,standardMbeans.size());
    //see if there is a network manager registered to
    ObjectName networkManager = null;
    for(ObjectName on: standardMbeans){
        if(on.getCanonicalName().contains("NetworkManager")){
            networkManager = on;
        }
    }
    Assert.assertNotNull(networkManager);
}
JMXMPConnector.java 文件源码 项目:jmx-prometheus-exporter 阅读 19 收藏 0 点赞 0 评论 0
@Override
public @NotNull JMXConnector connect() throws IOException {
  final JMXServiceURL address = new JMXServiceURL("service:jmx:jmxmp://" + address());
  final javax.management.remote.jmxmp.JMXMPConnector connector = new javax.management.remote.jmxmp.JMXMPConnector(address, environment());
  connector.connect();
  return connector;
}
ClientProvider.java 文件源码 项目:jdk8u-jdk 阅读 29 收藏 0 点赞 0 评论 0
public JMXConnector newJMXConnector(JMXServiceURL serviceURL,
                                    Map<String,?> environment)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnector(serviceURL, environment);
}


问题


面经


文章

微信
公众号

扫码关注公众号