当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.getPlatformMBeanServer方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getPlatformMBeanServer方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getPlatformMBeanServer方法的具体用法?Java ManagementFactory.getPlatformMBeanServer怎么用?Java ManagementFactory.getPlatformMBeanServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getPlatformMBeanServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    RMIJRMPServerImplSub impl = new RMIJRMPServerImplSub();

    System.out.println("Creating connectorServer");
    connectorServer = new RMIConnectorServer(url, null, impl, mbs);
    System.out.println("Starting connectorServer");
    connectorServer.start();
    System.out.println("Making client");
    RMIConnection cc = impl.newClient(null);
    System.out.println("Closing client");
    cc.close();
    if (connectorServer.isActive()) {
        System.out.println("Stopping connectorServer");
        connectorServer.stop();
    }
    if (failure == null)
        System.out.println("TEST PASSED, no deadlock");
    else
        System.out.println("TEST FAILED");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:ConnectorStopDeadlockTest.java

示例2: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    System.out.println("Starting pid: " + ManagementFactory.getRuntimeMXBean().getName());

    int size = 5 * 1000 * 1000;
    //int size = 50 * 1000 * 1000;//for OOM with -Xms512m
    //int size = 50 * 1000 * 100; //for small dump


    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("ru.otus:type=Benchmark");
    Benchmark mbean = new Benchmark();
    mbs.registerMBean(mbean, name);

    mbean.setSize(size);
    mbean.run();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:17,代码来源:Main.java

示例3: run

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void run() {
  try {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    // Metrics that belong to "FSNamesystem", these are metrics that
    // come from hadoop metrics framework for the class FSNamesystem.
    ObjectName mxbeanNamefsn = new ObjectName(
        "Hadoop:service=NameNode,name=FSNamesystem");

    // Metrics that belong to "FSNamesystemState".
    // These are metrics that FSNamesystem registers directly with MBeanServer.
    ObjectName mxbeanNameFsns = new ObjectName(
        "Hadoop:service=NameNode,name=FSNamesystemState");

    // Metrics that belong to "NameNodeInfo".
    // These are metrics that FSNamesystem registers directly with MBeanServer.
    ObjectName mxbeanNameNni = new ObjectName(
        "Hadoop:service=NameNode,name=NameNodeInfo");

    final Set<ObjectName> mbeans = new HashSet<ObjectName>();
    mbeans.add(mxbeanNamefsn);
    mbeans.add(mxbeanNameFsns);
    mbeans.add(mxbeanNameNni);

    for(ObjectName mbean : mbeans) {
      MBeanInfo attributes = mbs.getMBeanInfo(mbean);
      for (MBeanAttributeInfo attributeInfo : attributes.getAttributes()) {
        mbs.getAttribute(mbean, attributeInfo.getName());
      }
    }

    succeeded = true;
  } catch (Exception e) {
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestFSNamesystemMBean.java

示例4: startEchoServer

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void startEchoServer() throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("ru.otus:type=Server");
    NonBlockingEchoSocketMsgServer server = new NonBlockingEchoSocketMsgServer();
    mbs.registerMBean(server, name);

    server.start();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:9,代码来源:ServerMain.java

示例5: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:GetVMOption.java

示例6: dumpHeap

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@CheckForNull
private static File dumpHeap(@NonNull final String path) {
    try {
        if (heapDumper == null) {
            final Class<?> clz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");   //NOI18N
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            final Object bean = ManagementFactory.newPlatformMXBeanProxy(
                server,
                "com.sun.management:type=HotSpotDiagnostic",    //NOI18N
                clz);
            final Method m = clz.getDeclaredMethod("dumpHeap", String.class, Boolean.TYPE);
            heapDumper = Pair.of(bean,m);
        }
        final File folder = new File(path);
        final File[] children = folder.listFiles();
        if (children != null) {
            final String namePattern = "heapdump_"; //NOI18N
            final Set<String> names = Arrays.stream(children)
                    .map((f) -> f.getName())
                    .filter((n) -> n.startsWith(namePattern))
                    .collect(Collectors.toSet());
            int index = 1;
            while (true) {
                if (!names.contains(namePattern + index)) {
                    break;
                }
                index++;
            }
            final File file = new File(folder, namePattern + index);
            heapDumper.second().invoke(heapDumper.first(), file.getAbsolutePath(), true);
            return file;
        }
    } catch (Exception e) {
        //pass
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:JavaCustomIndexer.java

示例7: testQueryForMemberMXBeanWithProcessId

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Test
public void testQueryForMemberMXBeanWithProcessId() throws Exception {
  final Properties props = new Properties();
  props.setProperty(MCAST_PORT, "0");
  props.setProperty(LOCATORS, "");
  props.setProperty("name", getUniqueName());
  new CacheFactory(props).create();

  final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
  final ObjectName pattern = ObjectName.getInstance("GemFire:type=Member,*");
  final QueryExp constraint =
      Query.eq(Query.attr("ProcessId"), Query.value(ProcessUtils.identifyPid()));

  waitForMemberMXBean(mbeanServer, pattern);

  final Set<ObjectName> mbeanNames = mbeanServer.queryNames(pattern, constraint);
  assertFalse(mbeanNames.isEmpty());
  assertEquals(1, mbeanNames.size());

  final ObjectName objectName = mbeanNames.iterator().next();
  final MemberMXBean mbean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
      objectName, MemberMXBean.class, false);

  assertNotNull(mbean);
  assertEquals(ProcessUtils.identifyPid(), mbean.getProcessId());
  assertEquals(getUniqueName(), mbean.getName());
  assertEquals(getUniqueName(), mbean.getMember());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:29,代码来源:LauncherMemberMXBeanIntegrationTest.java

示例8: setUp

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {

    shardStats = new ShardStats("shard-1", "DataStore", null);
    shardStats.registerMBean();
    mbeanServer = ManagementFactory.getPlatformMBeanServer();
    String objectName = AbstractMXBean.BASE_JMX_PREFIX + "type=" + shardStats.getMBeanType() + ",Category="
            + shardStats.getMBeanCategory() + ",name=" + shardStats.getMBeanName();
    testMBeanName = new ObjectName(objectName);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:11,代码来源:ShardStatsTest.java

示例9: testPassword

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Test
public void testPassword() throws Exception {
    Assert.assertEquals("Passwords should match when not using JMX.",password,datasource.getPoolProperties().getPassword());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ConnectionPoolMBean mbean = JMX.newMBeanProxy(mbs, oname, ConnectionPoolMBean.class);
    String jmxPassword = mbean.getPassword();
    Properties jmxProperties = mbean.getDbProperties();
    Assert.assertFalse("Passwords should not match.", password.equals(jmxPassword));
    Assert.assertFalse("Password property should be missing", jmxProperties.containsKey(PoolUtilities.PROP_PASSWORD));
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:11,代码来源:JmxPasswordTest.java

示例10: registerMBean

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void registerMBean() {
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        instance = new ShutdownServer();
        mBeanServer.registerMBean(instance, new ObjectName("server:type=ShutdownServer"));
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        System.out.println("Error registering Shutdown MBean");
    }
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:10,代码来源:ShutdownServer.java

示例11: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    System.setProperty("javax.management.builder.initial",
            MBeanServerBuilderImpl.class.getName());
    try {
        ManagementFactory.getPlatformMBeanServer();
    } catch (RuntimeException e) {
        System.out.println(">>> Unhappy Bye, Bye!");
        throw e;
    }
    System.out.println(">>> Happy Bye, Bye!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:MBeanServerMXBeanUnsupportedTest.java

示例12: testSave

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Test of save method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testSave() throws Exception {
    System.out.println("save");

    final File file = File.createTempFile("testconf",".xml");
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ScanManagerMXBean manager = ScanManager.register(mbs);

    try {
        final ScanDirConfigMXBean instance =
                manager.createOtherConfigurationMBean("testSave",file.getAbsolutePath());
        assertTrue(mbs.isRegistered(
                ScanManager.makeScanDirConfigName("testSave")));
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testSave");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        instance.save();
        final ScanManagerConfig loaded =
            new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(),loaded);
        assertEquals(bean,loaded);

        instance.getConfiguration().removeScan("tmp");
        instance.save();
        assertNotSame(loaded,instance.getConfiguration());
        final ScanManagerConfig loaded2 =
            new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(),loaded2);
    } finally {
        manager.close();
        mbs.unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
    final ObjectName all =
            new ObjectName(ScanManager.SCAN_MANAGER_NAME.getDomain()+":*");
    assertEquals(0,mbs.queryNames(all,null).size());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:ScanDirConfigTest.java

示例13: registerJmx

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public synchronized void registerJmx() throws SQLException {
    if (this.isJmxRegistered) {
        return;
    }
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName name = new ObjectName("com.mysql.jdbc.jmx:type=ReplicationGroupManager");
        mbs.registerMBean(this, name);
        this.isJmxRegistered = true;
    } catch (Exception e) {
        throw SQLError.createSQLException("Unable to register replication host management bean with JMX", null, e, null);
    }

}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:15,代码来源:ReplicationGroupManager.java

示例14: testTimeoutMetric

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Test(timeout=60000)
public void testTimeoutMetric() throws Exception {
  final Configuration conf = new HdfsConfiguration();
  final Path path = new Path("/test");

  final MiniDFSCluster cluster =
      new MiniDFSCluster.Builder(conf).numDataNodes(2).build();

  final List<FSDataOutputStream> streams = Lists.newArrayList();
  try {
    final FSDataOutputStream out =
        cluster.getFileSystem().create(path, (short) 2);
    final DataNodeFaultInjector injector = Mockito.mock
        (DataNodeFaultInjector.class);
    Mockito.doThrow(new IOException("mock IOException")).
        when(injector).
        writeBlockAfterFlush();
    DataNodeFaultInjector.instance = injector;
    streams.add(out);
    out.writeBytes("old gs data\n");
    out.hflush();

    /* Test the metric. */
    final MetricsRecordBuilder dnMetrics =
        getMetrics(cluster.getDataNodes().get(0).getMetrics().name());
    assertCounter("DatanodeNetworkErrors", 1L, dnMetrics);

    /* Test JMX datanode network counts. */
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ObjectName mxbeanName =
        new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo");
    final Object dnc =
        mbs.getAttribute(mxbeanName, "DatanodeNetworkCounts");
    final String allDnc = dnc.toString();
    assertTrue("expected to see loopback address",
        allDnc.indexOf("127.0.0.1") >= 0);
    assertTrue("expected to see networkErrors",
        allDnc.indexOf("networkErrors") >= 0);
  } finally {
    IOUtils.cleanup(LOG, streams.toArray(new Closeable[0]));
    if (cluster != null) {
      cluster.shutdown();
    }
    DataNodeFaultInjector.instance = new DataNodeFaultInjector();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:47,代码来源:TestDataNodeMetrics.java

示例15: collect

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public List<MetricFamilySamples> collect() {
    List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
    try {
        final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName filterName = new ObjectName("tomcat.jdbc:class=org.apache.tomcat.jdbc.pool.DataSource,type=ConnectionPool,*");
        Set<ObjectInstance> mBeans = server.queryMBeans(filterName, null);

        if (mBeans.size() > 0) {
            List<String> labelList = Collections.singletonList("pool");

            GaugeMetricFamily maxActiveConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_max",
                    "Maximum number of active connections that can be allocated from this pool at the same time",
                    labelList);

            GaugeMetricFamily activeConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_active_total",
                    "Number of active connections allocated from this pool",
                    labelList);

            GaugeMetricFamily idleConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_idle_total",
                    "Number of idle connections in this pool",
                    labelList);

            GaugeMetricFamily totalConnectionsGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_connections_total",
                    "Total number of connections in this pool",
                    labelList);

            GaugeMetricFamily waitingThreadsCountGauge = new GaugeMetricFamily(
                    "tomcat_jdbc_waitingthreads_total",
                    "Number of threads waiting for connections from this pool",
                    labelList);

            for (final ObjectInstance mBean : mBeans) {
                List<String> labelValueList = Collections.singletonList(mBean.getObjectName().getKeyProperty("name").replaceAll("[\"\\\\]", ""));

                maxActiveConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "MaxActive")).doubleValue());

                activeConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Active")).doubleValue());

                idleConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Idle")).doubleValue());

                totalConnectionsGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "Size")).doubleValue());

                waitingThreadsCountGauge.addMetric(
                        labelValueList,
                        ((Integer) server.getAttribute(mBean.getObjectName(), "WaitCount")).doubleValue());
            }

            mfs.add(maxActiveConnectionsGauge);
            mfs.add(activeConnectionsGauge);
            mfs.add(idleConnectionsGauge);
            mfs.add(totalConnectionsGauge);
            mfs.add(waitingThreadsCountGauge);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mfs;
}
 
开发者ID:nlighten,项目名称:tomcat_exporter,代码行数:71,代码来源:TomcatJdbcPoolExports.java


注:本文中的java.lang.management.ManagementFactory.getPlatformMBeanServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。