本文整理汇总了Java中javax.management.MBeanServer.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServer.getAttribute方法的具体用法?Java MBeanServer.getAttribute怎么用?Java MBeanServer.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServer
的用法示例。
在下文中一共展示了MBeanServer.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJmxBeans
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void testJmxBeans() throws Exception {
final int NUM_SERVERS = 3;
final MiniRaftClusterWithSimulatedRpc cluster
= MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
cluster.start();
waitForLeader(cluster);
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
Assert.assertEquals(NUM_SERVERS, objectInstances.size());
for (ObjectInstance instance : objectInstances) {
Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
Assert.assertEquals(cluster.getGroupId().toString(), groupId);
}
cluster.shutdown();
}
示例2: testSecondaryWebUi
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test
public void testSecondaryWebUi()
throws IOException, MalformedObjectNameException,
AttributeNotFoundException, MBeanException,
ReflectionException, InstanceNotFoundException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = new ObjectName(
"Hadoop:service=SecondaryNameNode,name=SecondaryNameNodeInfo");
String[] checkpointDir = (String[]) mbs.getAttribute(mxbeanName,
"CheckpointDirectories");
Assert.assertArrayEquals(checkpointDir, snn.getCheckpointDirectories());
String[] checkpointEditlogDir = (String[]) mbs.getAttribute(mxbeanName,
"CheckpointEditlogDirectories");
Assert.assertArrayEquals(checkpointEditlogDir,
snn.getCheckpointEditlogDirectories());
}
示例3: testStorageBlockContentsStaleAfterNNRestart
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Verify the following scenario.
* 1. NN restarts.
* 2. Heartbeat RPC will retry and succeed. NN asks DN to reregister.
* 3. After reregistration completes, DN will send Heartbeat, followed by
* Blockreport.
* 4. NN will mark DatanodeStorageInfo#blockContentsStale to false.
* @throws Exception
*/
@Test(timeout = 60000)
public void testStorageBlockContentsStaleAfterNNRestart() throws Exception {
MiniDFSCluster dfsCluster = null;
try {
Configuration config = new Configuration();
dfsCluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
dfsCluster.waitActive();
dfsCluster.restartNameNode(true);
BlockManagerTestUtil.checkHeartbeat(
dfsCluster.getNamesystem().getBlockManager());
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanNameFsns = new ObjectName(
"Hadoop:service=NameNode,name=FSNamesystemState");
Integer numStaleStorages = (Integer) (mbs.getAttribute(
mxbeanNameFsns, "NumStaleStorages"));
assertEquals(0, numStaleStorages.intValue());
} finally {
if (dfsCluster != null) {
dfsCluster.shutdown();
}
}
return;
}
示例4: getStatus
import javax.management.MBeanServer; //导入方法依赖的package包/类
private int getStatus(MBeanServer server, ObjectName name)
{
try
{
return (Integer) server.getAttribute(name, "State");
}
catch (Exception e)
{
e.printStackTrace();
return -1;
}
}
示例5: getTmInTransitCount
import javax.management.MBeanServer; //导入方法依赖的package包/类
private long getTmInTransitCount(MBeanServer server, Set<ObjectName> names) throws Exception
{
final String clsName = TransactionManagerMBean.class.getName();
long cnt = 0;
for (ObjectName name : names)
{
if (server.isInstanceOf(name, clsName))
{
cnt += (Integer) server.getAttribute(name, "OutstandingTransactions");
}
}
return cnt;
}
示例6: writeJspMonitor
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Write JSP monitoring information.
*/
public static void writeJspMonitor(PrintWriter writer,
Set<ObjectName> jspMonitorONs,
MBeanServer mBeanServer,
int mode)
throws Exception {
int jspCount = 0;
int jspReloadCount = 0;
Iterator<ObjectName> iter = jspMonitorONs.iterator();
while (iter.hasNext()) {
ObjectName jspMonitorON = iter.next();
Object obj = mBeanServer.getAttribute(jspMonitorON, "jspCount");
jspCount += ((Integer) obj).intValue();
obj = mBeanServer.getAttribute(jspMonitorON, "jspReloadCount");
jspReloadCount += ((Integer) obj).intValue();
}
if (mode == 0) {
writer.print("<br>");
writer.print(" JSPs loaded: ");
writer.print(jspCount);
writer.print(" JSPs reloaded: ");
writer.print(jspReloadCount);
} else if (mode == 1) {
// for now we don't write out anything
}
}
示例7: main
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Get the JMX implementation version from the MBeanServerDelegateMBean
//
System.out.println("Get the JMX implementation version");
ObjectName mbsdName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
String mbsdAttribute = "ImplementationVersion";
String mbsdVersion = (String) mbs.getAttribute(mbsdName, mbsdAttribute);
// Display JMX implementation version and JVM implementation version
//
System.out.println("JMX implementation version = " +
mbsdVersion);
System.out.println("Java Runtime implementation version = " +
args[0]);
// Check JMX implementation version vs. JVM implementation version
//
if (Boolean.valueOf(args[1]).booleanValue()) {
if (!mbsdVersion.equals(args[0]))
throw new IllegalArgumentException(
"JMX and Java Runtime implementation versions do not match!");
// Test OK!
//
System.out.println("JMX and Java Runtime implementation " +
"versions match!");
} else {
// Test OK!
//
System.out.println("JMX and Java Runtime implementation " +
"versions do not match because the test " +
"is using an unbundled version of JMX!");
}
System.out.println("Bye! Bye!");
}
示例8: getListenPort
import javax.management.MBeanServer; //导入方法依赖的package包/类
/**
* Retrieves HTTP listen port used by the app. It assumes there
* is only one HTTP connector.
*/
private int getListenPort() {
int port = 8080;
try {
// get connectors
final MBeanServer mbeanServer = (MBeanServer) getServletContext().getAttribute("org.apache.catalina.MBeanServer");
// if (log.isDebugEnabled()) log.debug("server: " + mbeanServer);
final ObjectName objectName = new ObjectName("Catalina:type=Connector,*");
final Set mbeans = mbeanServer.queryMBeans(objectName, null);
// find http connector
for (final Iterator i = mbeans.iterator(); i.hasNext();) {
final ObjectInstance mbean = (ObjectInstance) i.next();
// if (log.isDebugEnabled()) log.debug("mbean: " + mbean);
// if (log.isDebugEnabled()) log.debug("mbean.getClassName(): " + mbean.getClassName());
// if (log.isDebugEnabled()) log.debug("mbean.getObjectName(): " + mbean.getObjectName());
// if (log.isDebugEnabled()) log.debug("connector className: " + mbeanServer.getAttribute(mbean.getObjectName(), "className"));
final String handlerClassName = (String) mbeanServer.getAttribute(mbean.getObjectName(), "className");
// is it HTTP connector?
if (handlerClassName.endsWith("HttpConnector")) {
port = ((Integer) mbeanServer.getAttribute(mbean.getObjectName(), "port")).intValue();
if (log.isDebugEnabled()) {
log.debug("port: " + port);
}
break;
}
}
} catch (Exception e) {
// just log error, default value will be used
log.error("Error while getting connector list", e);
}
return port;
}
示例9: testMXBean
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static void testMXBean(MBeanServer mbs, ObjectName on)
throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
MBeanAttributeInfo[] attrs = mbi.getAttributes();
int nattrs = attrs.length;
if (mbi.getAttributes().length != 1)
failure("wrong number of attributes: " + attrs);
else {
MBeanAttributeInfo mbai = attrs[0];
if (mbai.getName().equals("Ints")
&& mbai.isReadable() && !mbai.isWritable()
&& mbai.getDescriptor().getFieldValue("openType")
.equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
&& attrs[0].getType().equals("[I"))
success("MBeanAttributeInfo");
else
failure("MBeanAttributeInfo: " + mbai);
}
int[] ints = (int[]) mbs.getAttribute(on, "Ints");
if (equal(ints, new int[] {1, 2, 3}, null))
success("getAttribute");
else
failure("getAttribute: " + Arrays.toString(ints));
ExplicitMXBean proxy =
JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
int[] pints = proxy.getInts();
if (equal(pints, new int[] {1, 2, 3}, null))
success("getAttribute through proxy");
else
failure("getAttribute through proxy: " + Arrays.toString(pints));
}
示例10: testTopUsersDisabled
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test(timeout=120000)
public void testTopUsersDisabled() throws Exception {
final Configuration conf = new Configuration();
// Disable nntop
conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false);
MiniDFSCluster cluster = null;
try {
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
cluster.waitActive();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanNameFsns = new ObjectName(
"Hadoop:service=NameNode,name=FSNamesystemState");
FileSystem fs = cluster.getFileSystem();
final Path path = new Path("/");
final int NUM_OPS = 10;
for (int i=0; i< NUM_OPS; i++) {
fs.listStatus(path);
fs.setTimes(path, 0, 1);
}
String topUsers =
(String) (mbs.getAttribute(mxbeanNameFsns, "TopUserOpCounts"));
assertNull("Did not expect to find TopUserOpCounts bean!", topUsers);
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
示例11: testTopUsersNoPeriods
import javax.management.MBeanServer; //导入方法依赖的package包/类
@Test(timeout=120000)
public void testTopUsersNoPeriods() throws Exception {
final Configuration conf = new Configuration();
conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, true);
conf.set(DFSConfigKeys.NNTOP_WINDOWS_MINUTES_KEY, "");
MiniDFSCluster cluster = null;
try {
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
cluster.waitActive();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanNameFsns = new ObjectName(
"Hadoop:service=NameNode,name=FSNamesystemState");
FileSystem fs = cluster.getFileSystem();
final Path path = new Path("/");
final int NUM_OPS = 10;
for (int i=0; i< NUM_OPS; i++) {
fs.listStatus(path);
fs.setTimes(path, 0, 1);
}
String topUsers =
(String) (mbs.getAttribute(mxbeanNameFsns, "TopUserOpCounts"));
assertNotNull("Expected TopUserOpCounts bean!", topUsers);
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
示例12: main
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Get the JMX implementation version from the MBeanServerDelegateMBean
//
System.out.println("Get the JMX implementation version");
ObjectName mbsdName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
String mbsdAttribute = "ImplementationVersion";
String mbsdVersion = (String) mbs.getAttribute(mbsdName, mbsdAttribute);
// Display JMX implementation version and JVM implementation version
//
System.out.println("JMX implementation version = " +
mbsdVersion);
System.out.println("Java Runtime implementation version = " +
args[0]);
// Check JMX implementation version vs. JVM implementation version
//
if (!mbsdVersion.equals(args[0]))
throw new IllegalArgumentException(
"JMX and Java Runtime implementation versions do not match!");
// Test OK!
//
System.out.println("JMX and Java Runtime implementation " +
"versions match!");
System.out.println("Bye! Bye!");
}
示例13: haveRequiredMemory
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static boolean haveRequiredMemory() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName os = new ObjectName("java.lang", "type", "OperatingSystem");
Object attr = server.getAttribute(os, "TotalPhysicalMemorySize");
String value = attr.toString();
long memory = Long.parseLong(value);
return memory >= minMemory;
}
示例14: check
import javax.management.MBeanServer; //导入方法依赖的package包/类
public static void check(String attr, MBeanServer server, ObjectName mon,
ObjectName mbean, long start) throws Exception {
final Object obj = server.getAttribute(mon, "DerivedGauge");
final long now = System.currentTimeMillis();
final long gran = (Long)server.getAttribute(mon, "GranularityPeriod");
if (now > start +2*gran) {
throw new Exception(attr+": Can't verify test case: " +
"granularity period expired!");
}
check(attr,server,mon,mbean,obj);
}
示例15: getLongStats
import javax.management.MBeanServer; //导入方法依赖的package包/类
private static String getLongStats() {
StringBuilder resp = new StringBuilder();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
resp.append("jvmRoute: ").append(SessionManager.getJvmRoute()).append("\n");
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
MemoryUsage memoryUsage = memoryBean.getHeapMemoryUsage();
resp.append("Heap memory MB [init/used/committed/max]: ")
.append(RuntimeStatsServlet.toMB(memoryUsage.getInit())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getUsed())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getCommitted())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getMax())).append("\n");
memoryUsage = memoryBean.getNonHeapMemoryUsage();
resp.append("Non-heap memory MB [init/used/committed/max]: ")
.append(RuntimeStatsServlet.toMB(memoryUsage.getInit())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getUsed())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getCommitted())).append("/")
.append(RuntimeStatsServlet.toMB(memoryUsage.getMax())).append("\n");
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
resp.append("JVM threads [daemon/total/peak]: ").append(threadBean.getDaemonThreadCount()).append("/")
.append(threadBean.getThreadCount()).append("/").append(threadBean.getPeakThreadCount())
.append("\n");
/*
* Connector statistics do not seem to be present for WF 8.
* They should be available in WF 9+ (WFLY-4420).
* ObjectName connectorName = new ObjectName("jboss.as.expr:subsystem=io,worker=default");
* Integer busyThreads = (Integer) server.getAttribute(connectorName, "ioThreads");
* Integer maxThreads = (Integer) server.getAttribute(connectorName, "taskMaxThreads");
* resp.append("IO threads [io/task max]: "
* ).append(busyThreads).append("/").append(maxThreads).append("\n");
*/
resp.append("Active sessions : ").append(SessionManager.getSessionCount()).append("\n");
ObjectName dataSourceName = new ObjectName(
"jboss.as.expr:subsystem=datasources,data-source=lams-ds,statistics=pool");
String inUseConnections = (String) server.getAttribute(dataSourceName, "InUseCount");
String activeConnections = (String) server.getAttribute(dataSourceName, "ActiveCount");
String availConnections = (String) server.getAttribute(dataSourceName, "AvailableCount");
resp.append("Connections [in use/active/total]: ").append(inUseConnections).append("/")
.append(activeConnections).append("/").append(availConnections).append("\n");
} catch (Exception e) {
RuntimeStatsServlet.log.error("Error while getting long runtime stats", e);
}
return resp.toString();
}