本文整理汇总了Java中javax.management.MBeanServerConnection.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.invoke方法的具体用法?Java MBeanServerConnection.invoke怎么用?Java MBeanServerConnection.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.invoke方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
MBeanServerConnection msc = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean mxbean =
ManagementFactory.getPlatformMXBean(msc, HotSpotDiagnosticMXBean.class);
String[] signatures = new String[] {
String.class.getName()
};
Object obj = msc.invoke(mxbean.getObjectName(), "getVMOption",
new String[] { "PrintVMOptions"}, signatures);
CompositeData data = (CompositeData)obj;
validateType(data);
VMOption option = mxbean.getVMOption("PrintVMOptions");
VMOption o = VMOption.from(data);
assertEquals(option, o);
}
示例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: jmxInvoke
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @throws Exception
*/
protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception {
Object result ;
if (args == null) {
result = jmxServerConnection.invoke(new ObjectName(name),
operation, null, null);
} else {
Object argsA[]=new Object[ args.size()];
String sigA[]=new String[args.size()];
for( int i=0; i<args.size(); i++ ) {
Arg arg=args.get(i);
if (arg.getType() == null) {
arg.setType("java.lang.String");
sigA[i]=arg.getType();
argsA[i]=arg.getValue();
} else {
sigA[i]=arg.getType();
argsA[i]=convertStringToType(arg.getValue(),arg.getType());
}
}
result = jmxServerConnection.invoke(new ObjectName(name), operation, argsA, sigA);
}
if(result != null) {
echoResult(operation,result);
createProperty(result);
}
return null;
}
示例4: jmxInvoke
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @throws Exception
*/
protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception {
Object result ;
if (args == null) {
result = jmxServerConnection.invoke(new ObjectName(name),
operation, null, null);
} else {
Object argsA[]=new Object[ args.size()];
String sigA[]=new String[args.size()];
for( int i=0; i<args.size(); i++ ) {
Arg arg=(Arg)args.get(i);
if( arg.type==null) {
arg.type="java.lang.String";
sigA[i]=arg.getType();
argsA[i]=arg.getValue();
} else {
sigA[i]=arg.getType();
argsA[i]=convertStringToType(arg.getValue(),arg.getType());
}
}
result = jmxServerConnection.invoke(new ObjectName(name), operation, argsA, sigA);
}
if(result != null) {
echoResult(operation,result);
createProperty(result);
}
return null;
}
示例5: bootAMX
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
Invoke the bootAMX() method on {@link BootAMXMBean}. Upon return,
AMX continues to load.
A cilent should call {@link invokeWaitAMXReady} prior to use.
*/
public void invokeBootAMX(final MBeanServerConnection conn)
{
// start AMX and wait for it to be ready
try
{
conn.invoke( getBootAMXMBeanObjectName(), BootAMXMBean.BOOT_AMX_OPERATION_NAME, null, null);
}
catch (final Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例6: jmxInvoke
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* @param jmxServerConnection
* @throws Exception
*/
protected String jmxInvoke(MBeanServerConnection jmxServerConnection, String name) throws Exception {
Object result;
if (args == null) {
result = jmxServerConnection.invoke(new ObjectName(name), operation, null, null);
} else {
Object argsA[] = new Object[args.size()];
String sigA[] = new String[args.size()];
for (int i = 0; i < args.size(); i++) {
Arg arg = args.get(i);
if (arg.getType() == null) {
arg.setType("java.lang.String");
sigA[i] = arg.getType();
argsA[i] = arg.getValue();
} else {
sigA[i] = arg.getType();
argsA[i] = convertStringToType(arg.getValue(), arg.getType());
}
}
result = jmxServerConnection.invoke(new ObjectName(name), operation, argsA, sigA);
}
if (result != null) {
echoResult(operation, result);
createProperty(result);
}
return null;
}
示例7: doInvokeRequest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
protected int doInvokeRequest(MBeanServerConnection mbsc,
ObjectName on,
boolean expectedException) {
int errorCount = 0;
try {
Utils.debug(Utils.DEBUG_STANDARD,
"ClientSide::doInvokeRequest: Invoke operations on the MBean") ;
mbsc.invoke(on, "operation", null, null) ;
if (expectedException) {
System.out.println("ClientSide::doInvokeRequest: " +
"(ERROR) Invoke did not fail with expected SecurityException");
errorCount++;
} else {
System.out.println("ClientSide::doInvokeRequest: (OK) Invoke succeed") ;
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
if (expectedException) {
if (e instanceof java.lang.SecurityException) {
System.out.println("ClientSide::doInvokeRequest: " +
"(OK) Invoke failed with expected SecurityException") ;
} else {
System.out.println("ClientSide::doInvokeRequest: " +
" (ERROR) Invoke failed with " +
e.getClass() + " instead of expected SecurityException");
errorCount++;
}
} else {
System.out.println("ClientSide::doInvokeRequest: " +
"(ERROR) Invoke failed");
errorCount++;
}
}
return errorCount;
}
示例8: receiveLogEventThroughJMX
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
@Test
public void receiveLogEventThroughJMX()
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException, MalformedObjectNameException,
PogamutException, MalformedURLException, IOException,
InterruptedException, MBeanException, InstanceNotFoundException,
AttributeNotFoundException, ReflectionException {
final String testMsg = "TEST LOG MESSAGE FROM receiveLogEventThroughJMX()";
ObjectName parentName = PogamutJMX.getObjectName("testDomain", "root", "test");
// export the log on the MBean server
ILogCategories logCategories = new LogCategories();
String testLogCategoryNameStr = "testLogCategory";
LogCategory testLog = logCategories.getCategory(testLogCategoryNameStr);
JMXLogCategories jmxLogCategories = new JMXLogCategories(
logCategories,
Pogamut.getPlatform().getMBeanServer(),
parentName
);
// connect through RMI and get the proxy
MBeanServerConnection mbsc = Pogamut.getPlatform().getMBeanServerConnection();
ObjectName logCatsName = jmxLogCategories.getJMXLogCategoriesName();
// get the name of all log category names
String[] catNames = (String[]) mbsc.getAttribute(logCatsName, "CategoryNames");
boolean found = false;
for (String catName : catNames) {
if (catName.equals(testLogCategoryNameStr)) {
found = true;
break;
}
}
Assert.assertTrue(testLogCategoryNameStr + " must be among exported log category names", found);
// get the object name for the test log category
ObjectName testCategoryName =
(ObjectName)
mbsc.invoke(
logCatsName,
"getJMXLogCategoryName",
new Object[]{ testLogCategoryNameStr },
new String[] { "java.lang.String" }
);
// add the listener
mbsc.addNotificationListener(testCategoryName,
new NotificationListener() {
public void handleNotification(Notification notification,
Object handback) {
receivedMessage = notification.getMessage();
messageReceivedLatch.countDown();
}
}, null, this
);
// send log event
if (testLog.isLoggable(Level.INFO)) testLog.info(testMsg);
// wait
messageReceivedLatch.await(30000, TimeUnit.MILLISECONDS);
// compare
assertTrue("Received message must contain testMsg", receivedMessage.contains(testMsg));
System.out.println("---/// TEST OK ///---");
Pogamut.getPlatform().close();
}
示例9: notifyTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
示例10: invoke
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
Object invoke(MBeanServerConnection mbsc, ObjectName name, Object[] args)
throws Exception {
return mbsc.invoke(name, getName(), args, signature);
}
示例11: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
int errorCount = 0 ;
String msgTag = "ClientSide::main: ";
try {
// Get a connection to remote mbean server
JMXServiceURL addr = new JMXServiceURL(args[0]);
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
// ----
System.out.println(msgTag + "Create and register the MBean");
ObjectName objName = new ObjectName("sqe:type=Basic,protocol=rmi") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Get attribute SqeParameterAtt on our MXBean");
Object result = mbsc.getAttribute(objName, "SqeParameterAtt");
System.out.println(msgTag +"(OK) Got result of class "
+ result.getClass().getName());
System.out.println(msgTag +"Received CompositeData is " + result);
System.out.println(msgTag +"---- OK\n") ;
// ----
// We use the value returned by getAttribute to perform the invoke.
System.out.println(msgTag +"Call operation doWeird on our MXBean [1]");
mbsc.invoke(objName, "doWeird",
new Object[]{result},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
// We build the CompositeData ourselves that time.
System.out.println(msgTag +"Call operation doWeird on our MXBean [2]");
String typeName = "SqeParameter";
String[] itemNames = new String[] {"glop"};
OpenType<?>[] openTypes = new OpenType<?>[] {SimpleType.STRING};
CompositeType rowType = new CompositeType(typeName, typeName,
itemNames, itemNames, openTypes);
Object[] itemValues = {"HECTOR"};
CompositeData data =
new CompositeDataSupport(rowType, itemNames, itemValues);
TabularType tabType = new TabularType(typeName, typeName,
rowType, new String[]{"glop"});
TabularDataSupport tds = new TabularDataSupport(tabType);
tds.put(data);
System.out.println(msgTag +"Source CompositeData is " + data);
mbsc.invoke(objName, "doWeird",
new Object[]{data},
new String[]{"javax.management.openmbean.CompositeData"});
System.out.println(msgTag +"---- OK\n") ;
// ----
System.out.println(msgTag +"Unregister the MBean");
mbsc.unregisterMBean(objName);
System.out.println(msgTag +"---- OK\n") ;
// Terminate the JMX Client
cc.close();
} catch(Exception e) {
Utils.printThrowable(e, true) ;
errorCount++;
throw new RuntimeException(e);
} finally {
System.exit(errorCount);
}
}
示例12: test
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void test() throws Exception {
// Create client
//
JMXConnector connector = JMXConnectorFactory.connect(url);
MBeanServerConnection client = connector.getMBeanServerConnection();
// Add listener at the client side
//
client.addNotificationListener(mbean, listener, null, null);
// Cleanup
//
receivedNotifs = 0;
// Ask to send notifs
//
Object[] params = new Object[] {new Integer(nb)};
String[] signatures = new String[] {"java.lang.Integer"};
client.invoke(mbean, "sendNotifications", params, signatures);
// Waiting...
//
synchronized (lock) {
for (int i = 0; i < 10; i++) {
if (receivedNotifs < nb) {
lock.wait(1000);
}
}
}
// Waiting again to ensure no more notifs
//
Thread.sleep(3000);
synchronized (lock) {
if (receivedNotifs != nb) {
throw new Exception("The client expected to receive " +
nb + " notifs, but got " + receivedNotifs);
}
}
// Remove listener
//
client.removeNotificationListener(mbean, listener);
connector.close();
}
示例13: test
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void test(String proto) throws Exception {
System.out.println("\n>>> Test for protocol " + proto);
JMXServiceURL url = new JMXServiceURL(proto, null, 0);
System.out.println(">>> Create a server: "+url);
JMXConnectorServer server = null;
try {
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
} catch (MalformedURLException e) {
System.out.println("System does not recognize URL: " + url +
"; ignoring");
return;
}
server.start();
url = server.getAddress();
System.out.println(">>> Creating a client connectint to: "+url);
JMXConnector conn = JMXConnectorFactory.connect(url, null);
MBeanServerConnection client = conn.getMBeanServerConnection();
// add listener from the client side
Listener listener = new Listener();
client.addNotificationListener(emitter, listener, null, null);
// ask to send one not serializable notif
Object[] params = new Object[] {new Integer(1)};
String[] signatures = new String[] {"java.lang.Integer"};
client.invoke(emitter, "sendNotserializableNotifs", params, signatures);
// listener clean
client.removeNotificationListener(emitter, listener);
listener = new Listener();
client.addNotificationListener(emitter, listener, null, null);
//ask to send serializable notifs
params = new Object[] {new Integer(sentNotifs)};
client.invoke(emitter, "sendNotifications", params, signatures);
// waiting ...
synchronized (listener) {
while (listener.received() < sentNotifs) {
listener.wait(); // either pass or test timeout (killed by test harness)
}
}
// clean
client.removeNotificationListener(emitter, listener);
conn.close();
server.stop();
}