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

TestManager.java 文件源码 项目:jdk8u_jdk 阅读 33 收藏 0 点赞 0 评论 0
private static void connect(String pid, String address) throws Exception {
    if (address == null) {
        throw new RuntimeException("Local connector address for " +
                                   pid + " is null");
    }

    System.out.println("Connect to process " + pid + " via: " + address);

    JMXServiceURL url = new JMXServiceURL(address);
    JMXConnector c = JMXConnectorFactory.connect(url);
    MBeanServerConnection server = c.getMBeanServerConnection();

    System.out.println("Connected.");

    RuntimeMXBean rt = newPlatformMXBeanProxy(server,
        RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    System.out.println(rt.getName());

    // close the connection
    c.close();
}
JMXAgentInterfaceBinding.java 文件源码 项目:jdk8u_jdk 阅读 21 收藏 0 点赞 0 评论 0
private void connect() throws IOException {
    System.out.println(
            "JMXConnectorThread: Attempting JMX connection on: "
                    + addr + " on port " + jmxPort);
    JMXServiceURL url;
    try {
        url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
                + addr + ":" + jmxPort + "/jmxrmi");
    } catch (MalformedURLException e) {
        throw new RuntimeException("Test failed.", e);
    }
    Map<String, Object> env = new HashMap<>();
    if (useSSL) {
        SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
        env.put("com.sun.jndi.rmi.factory.socket", csf);
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    }
    // connect and immediately close
    JMXConnector c = JMXConnectorFactory.connect(url, env);
    c.close();
    System.out.println("JMXConnectorThread: connection to JMX worked");
    jmxConnectWorked = true;
    checkRmiSocket();
    latch.countDown(); // signal we are done.
}
StartManagementAgent.java 文件源码 项目:jdk8u_jdk 阅读 28 收藏 0 点赞 0 评论 0
private static void tryConnect(int port, boolean shouldSucceed) throws Exception {
    String jmxUrlStr =
        String.format(
            "service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi",
            port);
    JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
    HashMap<String, ?> env = new HashMap<>();

    boolean succeeded;
    try {
        JMXConnector c = JMXConnectorFactory.connect(url, env);
        c.getMBeanServerConnection();
        succeeded = true;
    } catch(Exception ex) {
        succeeded = false;
    }
    if (succeeded && !shouldSucceed) {
        throw new Exception("Could connect to agent, but should not have been possible");
    }
    if (!succeeded && shouldSucceed) {
        throw new Exception("Could not connect to agent");
    }
}
ClientProvider.java 文件源码 项目:HeliosStreams 阅读 23 收藏 0 点赞 0 评论 0
/**
    * {@inheritDoc}
    * @see javax.management.remote.JMXConnectorProvider#newJMXConnector(javax.management.remote.JMXServiceURL, java.util.Map)
    */
   @Override
public JMXConnector newJMXConnector(final JMXServiceURL serviceURL, final Map<String, ?> env) throws IOException {
    if (!serviceURL.getProtocol().equals(PROTOCOL_NAME)) {
        throw new MalformedURLException("Protocol not [" + PROTOCOL_NAME + "]: " +
                        serviceURL.getProtocol());
    }
    final Map<String, ?> environment = env==null ? new HashMap<String, Object>() : env;
    final String remoteHost = serviceURL.getHost();
    final int remotePort = serviceURL.getPort();

    final int localPort = SSHTunnelManager.getInstance().getPortForward(remoteHost, remotePort);
    final String format = environment.containsKey(DELEGATE_PROTOCOL_FORMAT_KEY) ? environment.get(DELEGATE_PROTOCOL_FORMAT_KEY).toString() : DEFAULT_DELEGATE_PROTOCOL_FORMAT;

    final JMXServiceURL tunneledURL = JMXHelper.serviceUrl(format, "localhost", localPort);
    final JMXConnector connector = JMXConnectorFactory.newJMXConnector(tunneledURL, environment);

    final UpdateableJMXConnector ujmx = new UpdateableJMXConnector(connector, serviceURL, environment);
    connector.addConnectionNotificationListener(this, this, ujmx);
    return ujmx;
   }
TestManager.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 24 收藏 0 点赞 0 评论 0
private static void connect(String pid, String address) throws Exception {
    if (address == null) {
        throw new RuntimeException("Local connector address for " +
                                   pid + " is null");
    }

    System.out.println("Connect to process " + pid + " via: " + address);

    JMXServiceURL url = new JMXServiceURL(address);
    JMXConnector c = JMXConnectorFactory.connect(url);
    MBeanServerConnection server = c.getMBeanServerConnection();

    System.out.println("Connected.");

    RuntimeMXBean rt = newPlatformMXBeanProxy(server,
        RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    System.out.println(rt.getName());

    // close the connection
    c.close();
}
JMXAgentInterfaceBinding.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 24 收藏 0 点赞 0 评论 0
private void connect() throws IOException {
    System.out.println(
            "JMXConnectorThread: Attempting JMX connection on: "
                    + addr + " on port " + jmxPort);
    JMXServiceURL url;
    try {
        url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
                + addr + ":" + jmxPort + "/jmxrmi");
    } catch (MalformedURLException e) {
        throw new RuntimeException("Test failed.", e);
    }
    Map<String, Object> env = new HashMap<>();
    if (useSSL) {
        SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
        env.put("com.sun.jndi.rmi.factory.socket", csf);
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    }
    // connect and immediately close
    JMXConnector c = JMXConnectorFactory.connect(url, env);
    c.close();
    System.out.println("JMXConnectorThread: connection to JMX worked");
    jmxConnectWorked = true;
    checkRmiSocket();
    latch.countDown(); // signal we are done.
}
StartManagementAgent.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 106 收藏 0 点赞 0 评论 0
private static void tryConnect(int port, boolean shouldSucceed) throws Exception {
    String jmxUrlStr =
        String.format(
            "service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi",
            port);
    JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
    HashMap<String, ?> env = new HashMap<>();

    boolean succeeded;
    try {
        JMXConnector c = JMXConnectorFactory.connect(url, env);
        c.getMBeanServerConnection();
        succeeded = true;
    } catch(Exception ex) {
        succeeded = false;
    }
    if (succeeded && !shouldSucceed) {
        throw new Exception("Could connect to agent, but should not have been possible");
    }
    if (!succeeded && shouldSucceed) {
        throw new Exception("Could not connect to agent");
    }
}
CARBON15928JMXDisablingTest.java 文件源码 项目:product-ei 阅读 18 收藏 0 点赞 0 评论 0
private MBeanInfo testMBeanForDatasource() throws Exception {
    Map<String, String[]> env = new HashMap<>();
    String[] credentials = { "admin", "admin" };
    env.put(JMXConnector.CREDENTIALS, credentials);
    try {
        String url = "service:jmx:rmi://localhost:12311/jndi/rmi://localhost:11199/jmxrmi";
        JMXServiceURL jmxUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
        MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
        ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource");
        MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject);
        return mBeanInfo;
    } catch (MalformedURLException | MalformedObjectNameException | IntrospectionException |
            ReflectionException e) {
        throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e);
    }
}
DefaultPogamutPlatform.java 文件源码 项目:Pogamut3 阅读 25 收藏 0 点赞 0 评论 0
/**
 * @return Connection to a remote MBeanServer
 * @throws cz.cuni.amis.utils.exception.PogamutException
 */
public MBeanServerConnection getMBeanServerConnection() throws PogamutException {
    // connect through RMI and get the proxy
    try {
        if (mbsc == null) {
            JMXServiceURL url = getMBeanServerURL();
            JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
            mbsc = jmxc.getMBeanServerConnection();
        }
        return mbsc;
    } catch (IOException iOException) {
        throw new PogamutException("IO exception occured while creating remote MBeanServer connector.",
                iOException);
    }
}
AbstractJMXAgentObserver.java 文件源码 项目:Pogamut3 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Creates JMX wrapper for agent on specified adress and adds it to the list
 * of all connected agents.
 * @param serviceUrl URL of the JMX service where remote agent resides eg. service:jmx:rmi:///jndi/rmi://localhost:9999/server
 * @param objectName name of the MBean representing agent eg. myDomain:name=MyAgent1
 */
protected void addJMXAgentFromAdress(String serviceUrl, ObjectName objectName) throws IOException {
    JMXServiceURL url = new JMXServiceURL(serviceUrl);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    IAgent agent = JMX.newMXBeanProxy(mbsc, objectName, IAgent.class);

    agents.add(agent);
}


问题


面经


文章

微信
公众号

扫码关注公众号