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

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);
  }
}
AgentImpl.java 文件源码 项目:monarch 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Returns the address (URL) on which the RMI connector server runs or <code>null</code> if the
 * RMI connector server has not been started. This method is used primarily for testing purposes.
 *
 * @see JMXConnectorServer#getAddress()
 */
public JMXServiceURL getRMIAddress() {
  if (this.rmiConnector != null) {
    return this.rmiConnector.getAddress();

  } else {
    return null;
  }
}
SecurityTest.java 文件源码 项目:jdk8u-jdk 阅读 37 收藏 0 点赞 0 评论 0
public void run(Map<String, Object> serverArgs, String clientArgs[]) {

        System.out.println("SecurityTest::run: Start") ;
        int errorCount = 0;

        try {
            // Initialise the server side
            JMXServiceURL urlToUse = createServerSide(serverArgs);

            // Run client side
            errorCount = runClientSide(clientArgs, urlToUse.toString());

            if ( errorCount == 0 ) {
                System.out.println("SecurityTest::run: Done without any error") ;
            } else {
                System.out.println(
                    "SecurityTest::run: Done with " + errorCount + " error(s)");
                throw new RuntimeException("errorCount = " + errorCount);
            }

            cs.stop();

        } catch(Exception e) {
            throw new RuntimeException(e);
        }

    }
MBeanProcessController.java 文件源码 项目:monarch 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Connects to the JMX agent in the local process.
 * 
 * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
 *         in the process
 * @throws IOException if the JDK management agent cannot be found and loaded
 */
private void connect() throws ConnectionFailedException, IOException {
  try {
    final JMXServiceURL jmxUrl = getJMXServiceURL();
    this.jmxc = JMXConnectorFactory.connect(jmxUrl);
    this.server = this.jmxc.getMBeanServerConnection();
  } catch (AttachNotSupportedException e) {
    throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
  }
}
JMXMBeanDUnitTest.java 文件源码 项目:monarch 阅读 28 收藏 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();
  }
}
AnonymousSslSocketFactory.java 文件源码 项目:OperatieBRP 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Create a server socket.
 * @param serviceUrl jmx service url
 * @return server socket
 * @throws IOException if an I/O error occurs when creating the socket
 */
@Override
public ServerSocket createServerSocket(final JMXServiceURL serviceUrl) throws IOException {
    final InetAddress host = InetAddress.getByName(serviceUrl.getHost());
    final SSLServerSocket baseSslServerSocket = (SSLServerSocket) sslContext.getServerSocketFactory()
            .createServerSocket(serviceUrl.getPort(), BACKLOG, host);
    baseSslServerSocket.setEnabledProtocols(enabledProtocols);
    baseSslServerSocket.setEnabledCipherSuites(enabledCiphersuites);

    LOGGER.log(Level.FINE, "Created server socket");
    return baseSslServerSocket;
}
SystemSslSocketFactory.java 文件源码 项目:OperatieBRP 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Create a client socket.
 * @param serviceUrl jmx service url
 * @return client socket
 * @throws IOException if an I/O error occurs when creating the socket
 */
@Override
public Socket createSocket(final JMXServiceURL serviceUrl) throws IOException {
    final SSLSocket baseSslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(serviceUrl.getHost(),
            serviceUrl.getPort());
    baseSslSocket.setKeepAlive(true);

    LOGGER.log(Level.FINE, "Created client socket");
    return baseSslSocket;
}
ClientConnection.java 文件源码 项目:OperatieBRP 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Create a new client connection.
 * @param connector client connector (to send notifications)
 * @param serviceUrl jmx service url
 */
ClientConnection(final ClientConnector connector, final JMXSocketFactory socketFactory, final JMXServiceURL serviceUrl, final Object credentials,
                 final int requestTimeout) {
    this.connector = connector;
    this.socketFactory = socketFactory;
    this.serviceUrl = serviceUrl;
    this.credentials = credentials;
    this.requestTimeout = requestTimeout;
}
ClientProvider.java 文件源码 项目:OperatieBRP 阅读 28 收藏 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);
}


问题


面经


文章

微信
公众号

扫码关注公众号