本文整理汇总了Java中javax.management.MBeanServerConnection.queryMBeans方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.queryMBeans方法的具体用法?Java MBeanServerConnection.queryMBeans怎么用?Java MBeanServerConnection.queryMBeans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.queryMBeans方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanMBeans
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* scan out all monitor MBeans
*
* @param mbsc
* @return
* @throws IOException
*/
protected Set<ObjectInstance> scanMBeans(MBeanServerConnection mbsc, String pattern) throws IOException {
Set<ObjectInstance> monitorMBeans = null;
int count = 2;
while (count > 0) {
try {
monitorMBeans = mbsc.queryMBeans(new ObjectName(pattern), null);
if (monitorMBeans == null || monitorMBeans.isEmpty()) {
ThreadHelper.suspend(2000);
}
else {
break;
}
}
catch (MalformedObjectNameException e) {
// ignore
}
count--;
}
return monitorMBeans;
}
示例2: doExploit
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void doExploit ( final Object payloadObject, MBeanServerConnection mbc )
throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
Object[] params = new Object[1];
params[ 0 ] = payloadObject;
System.err.println("Querying MBeans");
Set<ObjectInstance> testMBeans = mbc.queryMBeans(null, null);
System.err.println("Found " + testMBeans.size() + " MBeans");
for ( ObjectInstance oi : testMBeans ) {
MBeanInfo mBeanInfo = mbc.getMBeanInfo(oi.getObjectName());
for ( MBeanOperationInfo opInfo : mBeanInfo.getOperations() ) {
try {
mbc.invoke(oi.getObjectName(), opInfo.getName(), params, new String[] {});
System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS");
return;
}
catch ( Throwable e ) {
String msg = e.getMessage();
if ( msg.startsWith("java.lang.ClassNotFoundException:") ) {
int start = msg.indexOf('"');
int stop = msg.indexOf('"', start + 1);
String module = ( start >= 0 && stop > 0 ) ? msg.substring(start + 1, stop) : "<unknown>";
if ( !"<unknown>".equals(module) && !"org.jboss.as.jmx:main".equals(module) ) {
int cstart = msg.indexOf(':');
int cend = msg.indexOf(' ', cstart + 2);
String cls = msg.substring(cstart + 2, cend);
System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> FAIL CNFE " + cls + " (" + module + ")");
}
}
else {
System.err.println(oi.getObjectName() + ":" + opInfo.getName() + " -> SUCCESS|ERROR " + msg);
return;
}
}
}
}
}
示例3: testQueryBean
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* looks like everyone can query for beans, but the AccessControlMXBean is filtered from the
* result
*/
@Test
@ConnectionConfiguration(user = "stranger", password = "1234567")
public void testQueryBean() throws MalformedObjectNameException, IOException {
MBeanServerConnection con = connectionRule.getMBeanServerConnection();
Set<ObjectInstance> objects =
con.queryMBeans(ObjectName.getInstance(ResourceConstants.OBJECT_NAME_ACCESSCONTROL), null);
assertThat(objects.size()).isEqualTo(0); // no AccessControlMBean in the query result
objects = con.queryMBeans(ObjectName.getInstance("GemFire:service=CacheServer,*"), null);
assertThat(objects.size()).isEqualTo(1);
}
示例4: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
// 如果执行的JavaScript脚本内容过长
// 则可以把脚本写在一个文件里,然后使用jmx client 动态调用mbean接口方法
String user = "root";
String pwd = "root";
// 如果生产环境需要账号验证的话
String[] account = new String[] { user, pwd };
Map<String, String[]> props = new HashMap<String, String[]>();
props.put("jmx.remote.credentials", account);
// 10086参数,具体见启动脚本的vm参数,@see -Dcom.sun.management.jmxremote.port=10086
JMXServiceURL address =
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:10086/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(address, props);
MBeanServerConnection mBeanConnection = connector.getMBeanServerConnection();
connector.connect();
ObjectName objectName=new ObjectName("GameMXBean:name=GameMonitor");
System.out.println("\nMBean count = " + mBeanConnection.getMBeanCount());
for (ObjectInstance object : mBeanConnection.queryMBeans(null, null)) {
// System.out.println("object.getObjectName="+object.getObjectName());
}
final GameMonitorMXBean mBean = JMX.newMBeanProxy(mBeanConnection, objectName,
GameMonitorMXBean.class);
String script = readScript("script.js");
System.err.println(script);
System.err.println(mBean.execJavascript(script));
}
示例5: collectTomcatConnections
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private void collectTomcatConnections ( MBeanServerConnection mbeanConn, ServiceCollectionResults jmxResults,
String serviceNamePort )
throws IOException, MalformedObjectNameException, MBeanException,
AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
String mbeanName;
String tomcatJmxRoot = jmxResults.getServiceInstance().getTomcatJmxName();
// **************** Tomcat connections
mbeanName = tomcatJmxRoot + ":type=ThreadPool,name=*";
Set<ObjectInstance> tomcatThreadPoolBeans = mbeanConn.queryMBeans(
new ObjectName( mbeanName ), null );
for ( ObjectInstance objectInstance : tomcatThreadPoolBeans ) {
logger.debug( "Service: {} ObjectName: {}", serviceNamePort, objectInstance.getObjectName() );
if ( jmxResults.getHttpConn() < 0 ) {
// get rid of -10 init
jmxResults.setHttpConn( 0 );
jmxResults.setThreadsBusy( 0 );
jmxResults.setThreadCount( 0 );
}
try {
jmxResults.setHttpConn( jmxResults.getHttpConn() + (Long) mbeanConn.getAttribute(
objectInstance.getObjectName(),
"connectionCount" ) );
} catch (Exception e) {
// tomcat 6 might not have.
logger.debug( "Failed to get jmx data for service: {} Reason: {}", serviceNamePort, e.getMessage() );
}
jmxResults.setThreadsBusy( jmxResults.getThreadsBusy() + (int) mbeanConn.getAttribute(
objectInstance.getObjectName(),
"currentThreadsBusy" ) );
jmxResults.setThreadCount( jmxResults.getThreadCount() + (int) mbeanConn.getAttribute(
objectInstance.getObjectName(),
"currentThreadCount" ) );
}
}
示例6: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException,
MalformedObjectNameException, InstanceNotFoundException,
AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException, IntrospectionException {
String domainName = "MyMBean";
int rmiPort = 1099;
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
// 可以类比HelloAgent.java中的那句:
// JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
//print domains
System.out.println("Domains:------------------");
String domains[] = mbsc.getDomains();
for(int i=0;i<domains.length;i++){
System.out.println("\tDomain["+i+"] = "+domains[i]);
}
//MBean count
System.out.println("MBean count = "+mbsc.getMBeanCount());
//process attribute
ObjectName mBeanName = new ObjectName(domainName+":name=HelloWorld");
mbsc.setAttribute(mBeanName, new Attribute("Name","zzh"));//注意这里是Name而不是name
System.out.println("Name = "+mbsc.getAttribute(mBeanName, "Name"));
//接下去是执行Hello中的printHello方法,分别通过代理和rmi的方式执行
//via proxy
HelloMBean proxy = MBeanServerInvocationHandler.newProxyInstance(mbsc, mBeanName, HelloMBean.class, false);
proxy.printHello();
proxy.printHello("jizhi boy");
//via rmi
mbsc.invoke(mBeanName, "printHello", null, null);
mbsc.invoke(mBeanName, "printHello", new String[]{"jizhi gril"}, new String[]{String.class.getName()});
//get mbean information
MBeanInfo info = mbsc.getMBeanInfo(mBeanName);
System.out.println("Hello Class: "+info.getClassName());
for(int i=0;i<info.getAttributes().length;i++){
System.out.println("Hello Attribute:"+info.getAttributes()[i].getName());
}
for(int i=0;i<info.getOperations().length;i++){
System.out.println("Hello Operation:"+info.getOperations()[i].getName());
}
//ObjectName of MBean
System.out.println("all ObjectName:--------------");
Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
for(Iterator<ObjectInstance> it = set.iterator();it.hasNext();){
ObjectInstance oi = it.next();
System.out.println("\t"+oi.getObjectName());
}
jmxc.close();
}