本文整理汇总了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");
}
示例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();
}
示例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) {
}
}
示例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();
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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));
}
示例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");
}
}
示例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!");
}
示例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());
}
示例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);
}
}
示例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();
}
}
示例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;
}