當前位置: 首頁>>代碼示例>>Java>>正文


Java JMXConnector.getMBeanServerConnection方法代碼示例

本文整理匯總了Java中javax.management.remote.JMXConnector.getMBeanServerConnection方法的典型用法代碼示例。如果您正苦於以下問題:Java JMXConnector.getMBeanServerConnection方法的具體用法?Java JMXConnector.getMBeanServerConnection怎麽用?Java JMXConnector.getMBeanServerConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.management.remote.JMXConnector的用法示例。


在下文中一共展示了JMXConnector.getMBeanServerConnection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connect

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TestManager.java

示例2: JMXExecutor

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
/**
 * Instantiates a new JMXExecutor targeting the VM indicated by the given host/port combination or a full JMX
 * Service URL
 *
 * @param target a host/port combination on the format "host:port" or a full JMX Service URL of the target VM
 */
public JMXExecutor(String target) {
    String urlStr;

    if (target.matches("^\\w[\\w\\-]*(\\.[\\w\\-]+)*:\\d+$")) {
        /* Matches "hostname:port" */
        urlStr = String.format("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", target);
    } else if (target.startsWith("service:")) {
        urlStr = target;
    } else {
        throw new IllegalArgumentException("Could not recognize target string: " + target);
    }

    try {
        JMXServiceURL url = new JMXServiceURL(urlStr);
        JMXConnector c = JMXConnectorFactory.connect(url, new HashMap<>());
        mbs = c.getMBeanServerConnection();
    } catch (IOException e) {
        throw new CommandExecutorException("Could not initiate connection to target: " + target, e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:JMXExecutor.java

示例3: MBeanWrapper

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
MBeanWrapper( int jvmPort ) throws MonitorConfigurationException {

        this.jvmPort = jvmPort;
        try {
            JMXConnector connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"
                                                                                           + this.jvmPort
                                                                                           + "/jmxrmi"),
                                                                         null);
            connector.connect();

            this.connection = connector.getMBeanServerConnection();
        } catch (Exception e) {
            final String msg = "Error initializing the JMV monitor. Unable to connect to JVM at port "
                               + this.jvmPort;
            log.error(msg, e);
            throw new MonitorConfigurationException(msg, e);
        }
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:19,代碼來源:MBeanWrapper.java

示例4: tryConnect

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:StartManagementAgent.java

示例5: dotest

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ProviderTest.java

示例6: getMBeanServerConnection

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
/**
 * Get an MBeanServerConnection object. Return null if there is any failure.
 */
public static MBeanServerConnection getMBeanServerConnection(String host, String jmxPort) {
  MBeanServerConnection mbs = null;
  try {
    Map<String, String[]> env = new HashMap<>();
    JMXServiceURL address = new JMXServiceURL(
        "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
    JMXConnector connector = JMXConnectorFactory.connect(address, env);
    mbs = connector.getMBeanServerConnection();
  } catch (Exception e) {
    LOG.error("Failed to connect to MBeanServer {}:{}", HostName, jmxPort, e);
  }
  return mbs;
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:17,代碼來源:OperatorUtil.java

示例7: testWithException

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
private static void testWithException(boolean send)
throws Exception {
    ClassLoader zoobyCL = new ZoobyClassLoader();
    Class<?> zoobyClass = Class.forName("Zooby", false, zoobyCL);
    Object zooby = zoobyClass.newInstance();

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, pmbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();

    Object rzooby;
    if (send) {
        System.out.println("Sending object...");
        mbsc.setAttribute(getSetName, new Attribute("It", zooby));
        rzooby = getSetInstance.getIt();
    } else {
        System.out.println("Receiving object...");
        getSetInstance.setIt(zooby);
        rzooby = mbsc.getAttribute(getSetName, "It");
    }

    if (!rzooby.getClass().getName().equals("Zooby")) {
        throw new Exception("FAILED: remote object is not a Zooby");
    }
    if (rzooby.getClass().getClassLoader() ==
            zooby.getClass().getClassLoader()) {
        throw new Exception("FAILED: same class loader: " +
                zooby.getClass().getClassLoader());
    }

    cc.close();
    cs.stop();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:RMIDownloadTest.java

示例8: getMemberId

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
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);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:33,代碼來源:LauncherLifecycleCommandsDUnitTest.java

示例9: testStart

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
@Test
public void testStart() throws Exception {
  JMXConnector connector = JMXConnectorFactory.connect(
    JMXListener.buildJMXServiceURL(connectorPort,connectorPort));

  MBeanServerConnection mb = connector.getMBeanServerConnection();
  String domain = mb.getDefaultDomain();
  Assert.assertTrue("default domain is not correct",
    !domain.isEmpty());
  connector.close();

}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:13,代碼來源:TestJMXListener.java

示例10: test

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:49,代碼來源:UnexpectedNotifTest.java

示例11: test

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:56,代碼來源:RMIExitTest.java

示例12: main

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    System.out.println("---RMIConnectorNullSubjectConnTest starting...");

    JMXConnectorServer connectorServer = null;
    JMXConnector connectorClient = null;

    try {
        MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0);
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver);
        connectorServer.start();

        JMXServiceURL serverAddr = connectorServer.getAddress();
        connectorClient = JMXConnectorFactory.connect(serverAddr, null);
        connectorClient.connect();

        Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef");
        nullSubjectConnField.setAccessible(true);

        WeakReference<MBeanServerConnection> weak =
                (WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient);

        if (weak != null && weak.get() != null) {
            throw new RuntimeException("nullSubjectConnRef must be null at initial time.");
        }

        MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null);
        MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null);
        if (conn1 == null) {
            throw new RuntimeException("A connection with null subject should not be null.");
        } else if (conn1 != conn2) {
            throw new RuntimeException("The 2 connections with null subject are not equal.");
        }

        conn1 = null;
        conn2 = null;
        int i = 1;
        do {
            System.gc();
            Thread.sleep(100);
            weak = (WeakReference<MBeanServerConnection>)nullSubjectConnField.get(connectorClient);
        } while ((weak != null && weak.get() != null) && i++ < 60);

        System.out.println("---GC times: " + i);

        if (weak != null && weak.get() != null) {
            throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn");
        } else {
            System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!");
        }
    } finally {
        try {
            connectorClient.close();
            connectorServer.stop();
        } catch (Exception e) {
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:59,代碼來源:RMIConnectorNullSubjectConnTest.java

示例13: run

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
public void run(Map<String, Object> args) {

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

        try {
            // JMX MbeanServer used inside single VM as if remote.
            // MBeanServer mbs = MBeanServerFactory.newMBeanServer();
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

            JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
            JMXConnectorServer cs =
                JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            cs.start();

            JMXServiceURL addr = cs.getAddress();
            JMXConnector cc = JMXConnectorFactory.connect(addr);
            MBeanServerConnection mbsc = cc.getMBeanServerConnection();

            // Print out registered java.lang.management MXBeans found
            // in the remote jvm.
            printMBeans(mbsc) ;

            // For each possible kind of JDK 5 defined MXBean, we retrieve its
            // MBeanInfo and print it and we call all getters and print
            // their output.
            errorCount += doClassLoadingMXBeanTest(mbsc) ;
            errorCount += doMemoryMXBeanTest(mbsc) ;
            errorCount += doThreadMXBeanTest(mbsc) ;
            errorCount += doRuntimeMXBeanTest(mbsc) ;
            errorCount += doOperatingSystemMXBeanTest(mbsc) ;
            errorCount += doCompilationMXBeanTest(mbsc) ;
            errorCount += doGarbageCollectorMXBeanTest(mbsc) ;
            errorCount += doMemoryManagerMXBeanTest(mbsc) ;
            errorCount += doMemoryPoolMXBeanTest(mbsc) ;

            // Terminate the JMX Client
            cc.close();

        } catch(Exception e) {
            Utils.printThrowable(e, true) ;
            throw new RuntimeException(e);
        }

        if ( errorCount == 0 ) {
            System.out.println("MXBeanInteropTest1::run: Done without any error") ;
        } else {
            System.out.println("MXBeanInteropTest1::run: Done with "
                    + errorCount
                    + " error(s)") ;
            throw new RuntimeException("errorCount = " + errorCount);
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:54,代碼來源:MXBeanInteropTest1.java

示例14: testInterface

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
private static <T> void testInterface(Class<T> c, boolean nullTest)
        throws Exception {

    System.out.println("Testing " + c.getName() +
                       (nullTest ? " for null values" : "") + "...");

    MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();

    NamedMXBeans namedMXBeans = new NamedMXBeans(mbsc);
    InvocationHandler ih =
        nullTest ? new MXBeanNullImplInvocationHandler(c, namedMXBeans) :
                   new MXBeanImplInvocationHandler(c, namedMXBeans);
    T impl = c.cast(Proxy.newProxyInstance(c.getClassLoader(),
                                           new Class[] {c},
                                           ih));
    ObjectName on = new ObjectName("test:type=" + c.getName());
    mbs.registerMBean(impl, on);

    System.out.println("Register any MXBeans...");

    Field[] fields = c.getFields();
    for (Field field : fields) {
        String n = field.getName();
        if (n.endsWith("ObjectName")) {
            String objectNameString = (String) field.get(null);
            String base = n.substring(0, n.length() - 10);
            Field f = c.getField(base);
            Object mxbean = f.get(null);
            ObjectName objectName =
                ObjectName.getInstance(objectNameString);
            mbs.registerMBean(mxbean, objectName);
            namedMXBeans.put(objectName, mxbean);
        }
    }

    try {
        testInterface(c, mbsc, on, namedMXBeans, nullTest);
    } finally {
        try {
            cc.close();
        } finally {
            cs.stop();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:54,代碼來源:MXBeanTest.java

示例15: init

import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
/**
 * @throws Exception
 *           initializes MBeanServer
 */
public void init() throws Exception {

  err("init: server=" + server + ";port=" + port + ";service=" + service
      + ";localVMUrl=" + localVMUrl);

  String url_string = null;
  // build connection url
  if (localVMUrl != null) {
    // use
    // jstat -snap <vmpid> | grep sun.management.JMXConnectorServer.address
    // to get url
    url_string = localVMUrl;
    err("url string for local pid = " + localVMUrl + " = " + url_string);

  } else if (!port.isEmpty() && !server.isEmpty()) {
    // using server and port
    url_string = "service:jmx:rmi:///jndi/rmi://" + server + ":" + port
    + "/jmxrmi";
  } // else url stays null

  // Create an RMI connector client and
  // connect it to the RMI connector server

  if (url_string == null) { // assume local vm (for example for Testing)
    mbsc = ManagementFactory.getPlatformMBeanServer();
  } else {
    JMXServiceURL url = new JMXServiceURL(url_string);

    err("Create RMI connector and connect to the RMI connector server" + url);

    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    // Get an MBeanServerConnection
    //
    err("\nGet an MBeanServerConnection");
    mbsc = jmxc.getMBeanServerConnection();
  }

  // Get domains from MBeanServer
  //
  err("\nDomains:");

  String domains[] = mbsc.getDomains();
  Arrays.sort(domains);
  for (String domain : domains) {
    err("\tDomain = " + domain);
  }

  // Get MBeanServer's default domain
  //
  err("\nMBeanServer default domain = " + mbsc.getDefaultDomain());

  // Get MBean count
  //
  err("\nMBean count = " + mbsc.getMBeanCount());

  // Query MBean names for specific domain "hadoop" and service
  ObjectName query = new ObjectName("Hadoop:service=" + service + ",*");
  hadoopObjectNames = new ArrayList<ObjectName>(5);
  err("\nQuery MBeanServer MBeans:");
  Set<ObjectName> names = new TreeSet<ObjectName>(mbsc
      .queryNames(query, null));

  for (ObjectName name : names) {
    hadoopObjectNames.add(name);
    err("Hadoop service: " + name);
  }

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:73,代碼來源:JMXGet.java


注:本文中的javax.management.remote.JMXConnector.getMBeanServerConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。