本文整理汇总了Java中javax.management.ObjectInstance类的典型用法代码示例。如果您正苦于以下问题:Java ObjectInstance类的具体用法?Java ObjectInstance怎么用?Java ObjectInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectInstance类属于javax.management包,在下文中一共展示了ObjectInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJmxBeans
import javax.management.ObjectInstance; //导入依赖的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: registerMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
public ObjectInstance registerMBean(Object object, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
// ------------------------------
// ------------------------------
Class<?> theClass = object.getClass();
Introspector.checkCompliance(theClass);
final String infoClassName = getNewMBeanClassName(object);
checkMBeanPermission(infoClassName, null, name, "registerMBean");
checkMBeanTrustPermission(theClass);
return registerObject(infoClassName, object, name);
}
示例3: scanMBeans
import javax.management.ObjectInstance; //导入依赖的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;
}
示例4: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className, ObjectName name)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name);
}
}
示例5: queryMBeans
import javax.management.ObjectInstance; //导入依赖的package包/类
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
Set<ObjectInstance> instances = newSet();
if (name == null)
name = ObjectName.WILDCARD;
if (query == null)
query = trueQuery;
MBeanServer oldMBS = QueryEval.getMBeanServer();
try {
query.setMBeanServer(this);
for (ObjectName n : mbeans.keySet()) {
if (name.apply(n)) {
try {
if (query.apply(n))
instances.add(getObjectInstance(n));
} catch (Exception e) {
// OK: Ignore this MBean in the result
}
}
}
} finally {
query.setMBeanServer(oldMBS);
}
return instances;
}
示例6: getObjectInstance
import javax.management.ObjectInstance; //导入依赖的package包/类
public ObjectInstance getObjectInstance(ObjectName name)
throws InstanceNotFoundException,
IOException {
if (logger.debugOn())
logger.debug("getObjectInstance", "name=" + name);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.getObjectInstance(name, delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.getObjectInstance(name, delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
示例7: queryMBeans
import javax.management.ObjectInstance; //导入依赖的package包/类
public Set<ObjectInstance> queryMBeans(ObjectName name,
QueryExp query)
throws IOException {
if (logger.debugOn()) logger.debug("queryMBeans",
"name=" + name + ", query=" + query);
final MarshalledObject<QueryExp> sQuery =
new MarshalledObject<QueryExp>(query);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.queryMBeans(name, sQuery, delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.queryMBeans(name, sQuery, delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
示例8: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
public ObjectInstance createMBean(String className, ObjectName name,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, null, true,
params, signature);
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
}
}
示例9: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className,
ObjectName name,
ObjectName loaderName)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className,
loaderName);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name, loaderName);
}
}
示例10: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
return createMBean(className, name, loaderName, false,
params, signature);
}
示例11: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName) throws ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException,
InstanceNotFoundException {
throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");
}
示例12: createMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
public ObjectInstance createMBean(
String className, ObjectName name, Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, clrName, params, signature);
} catch (InstanceNotFoundException ex) {
throw new RuntimeException(ex); // can't happen
}
}
示例13: registerMBean
import javax.management.ObjectInstance; //导入依赖的package包/类
@Override
public synchronized ObjectInstance registerMBean(Object object, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
ObjectInstance obj = mbs.registerMBean(object, name);
mBeans.add(new MBean1(name, object));
unregisteredMBeans.remove(new MBean1(name, object));
return obj;
}
示例14: doExploit
import javax.management.ObjectInstance; //导入依赖的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;
}
}
}
}
}
示例15: init
import javax.management.ObjectInstance; //导入依赖的package包/类
public void init(String host, int port) throws Exception {
int iport = 0;
String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
Set<ObjectInstance> set = mBeanServer.queryMBeans(objectName, null);
Iterator<ObjectInstance> iterator = set.iterator();
while (iterator.hasNext()) {
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
/* Name are:
* http-8080
* jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
String [] elenames = name.split("-");
String sport = elenames[elenames.length-1];
iport = Integer.parseInt(sport);
String [] shosts = elenames[1].split("%2F");
shost = shosts[0];
if (port==0 && host==null)
break; /* Take the first one */
if (host==null && iport==port)
break; /* Only port done */
if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
throw(new Exception("Can't find connector for " + host + ":" + port));
this.port = iport;
this.host = shost;
}