public static void main(String[] args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (Class<?> c : new Class<?>[] {
Spume.class, Thing.class, XSpume.class, XThing.class
}) {
for (ObjectName n : new ObjectName[] {null, new ObjectName("a:b=c")}) {
System.out.println("Class " + c.getName() + " with name " + n +
"...");
ObjectName realName = new ObjectName("a:type=" + c.getName());
Constructor<?> constr = c.getConstructor(ObjectName.class);
Object mbean = constr.newInstance(realName);
ObjectInstance oi;
String what =
"Registering MBean of type " + c.getName() + " under name " +
"<" + n + ">: ";
try {
oi = mbs.registerMBean(mbean, n);
} catch (Exception e) {
e.printStackTrace();
fail(what + " got " + e);
continue;
}
ObjectName registeredName = oi.getObjectName();
if (!registeredName.equals(realName))
fail(what + " registered as " + registeredName);
if (!mbs.isRegistered(realName)) {
fail(what + " not registered as expected");
}
mbs.unregisterMBean(registeredName);
}
}
System.err.flush();
if (failures == 0)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: " + failure);
}
java类javax.management.ObjectInstance的实例源码
PreRegisterNameTest.java 文件源码
项目:jdk8u-jdk
阅读 17
收藏 0
点赞 0
评论 0
MBeanServerAccessController.java 文件源码
项目:OpenJSharp
阅读 26
收藏 0
点赞 0
评论 0
/**
* Call <code>checkWrite()</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance registerMBean(Object object, ObjectName name)
throws
InstanceAlreadyExistsException,
MBeanRegistrationException,
NotCompliantMBeanException {
checkWrite();
return getMBeanServer().registerMBean(object, name);
}
ServerNotifForwarder.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
static void checkMBeanPermission(
final MBeanServer mbs, final ObjectName name, final String actions)
throws InstanceNotFoundException, SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
AccessControlContext acc = AccessController.getContext();
ObjectInstance oi;
try {
oi = AccessController.doPrivileged(
new PrivilegedExceptionAction<ObjectInstance>() {
public ObjectInstance run()
throws InstanceNotFoundException {
return mbs.getObjectInstance(name);
}
});
} catch (PrivilegedActionException e) {
throw (InstanceNotFoundException) extractException(e);
}
String classname = oi.getClassName();
MBeanPermission perm = new MBeanPermission(
classname,
null,
name,
actions);
sm.checkPermission(perm, acc);
}
}
RMIConnector.java 文件源码
项目:jdk8u-jdk
阅读 26
收藏 0
点赞 0
评论 0
public ObjectInstance createMBean(String className,
ObjectName name)
throws ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
IOException {
if (logger.debugOn())
logger.debug("createMBean(String,ObjectName)",
"className=" + className + ", name=" +
name);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.createMBean(className,
name,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.createMBean(className,
name,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
RMIConnector.java 文件源码
项目:OpenJSharp
阅读 26
收藏 0
点赞 0
评论 0
public ObjectInstance createMBean(String className,
ObjectName name)
throws ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
IOException {
if (logger.debugOn())
logger.debug("createMBean(String,ObjectName)",
"className=" + className + ", name=" +
name);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.createMBean(className,
name,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.createMBean(className,
name,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
OldMBeanServerTest.java 文件源码
项目:openjdk-jdk10
阅读 17
收藏 0
点赞 0
评论 0
public ObjectInstance createMBean(
String className, ObjectName name, ObjectName loaderName,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
Object mbean = instantiate(className, loaderName, params, signature);
return registerMBean(mbean, name);
}
ActiveMQJmxMonitorTest.java 文件源码
项目:activemq-jmx-monitor
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void onEvent(ActiveMQJmxMonitor.NotificationType notificationType, ActiveMQJmxMonitor.State state, ObjectInstance objectInstance) {
if (notificationType == ActiveMQJmxMonitor.NotificationType.SLOW_CONSUMER) {
if (state == ActiveMQJmxMonitor.State.START) slowConsumers++;
else if (state == ActiveMQJmxMonitor.State.END) slowConsumers--;
} else if (notificationType == ActiveMQJmxMonitor.NotificationType.PRODUCER_BLOCKED) {
if (state == ActiveMQJmxMonitor.State.START) blockedProducers++;
else if (state == ActiveMQJmxMonitor.State.END) blockedProducers--;
}
}
JBoss.java 文件源码
项目:ysoserial-modified
阅读 22
收藏 0
点赞 0
评论 0
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;
}
}
}
}
}
MBeanServerWrapper.java 文件源码
项目:monarch
阅读 24
收藏 0
点赞 0
评论 0
@Override
public ObjectInstance createMBean(String className, ObjectName name, Object[] params,
String[] signature) throws ReflectionException, InstanceAlreadyExistsException,
MBeanException, NotCompliantMBeanException {
checkDomain(name);
return mbs.createMBean(className, name, params, signature);
}
RMIConnector.java 文件源码
项目:openjdk-jdk10
阅读 27
收藏 0
点赞 0
评论 0
public ObjectInstance createMBean(String className,
ObjectName name,
ObjectName loaderName,
Object params[],
String signature[])
throws ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException,
IOException {
if (logger.debugOn()) logger.debug(
"createMBean(String,ObjectName,ObjectName,Object[],String[])",
"className=" + className + ", name=" + name + ", loaderName="
+ loaderName + ", signature=" + strings(signature));
final MarshalledObject<Object[]> sParams =
new MarshalledObject<Object[]>(params);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.createMBean(className,
name,
loaderName,
sParams,
signature,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.createMBean(className,
name,
loaderName,
sParams,
signature,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}