本文整理汇总了Java中javax.management.MBeanServerConnection.createMBean方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.createMBean方法的具体用法?Java MBeanServerConnection.createMBean怎么用?Java MBeanServerConnection.createMBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.createMBean方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
System.out.println("DEBUG: Calling createMBean");
mbsc.createMBean(Name.class.getName(), objName);
System.out.println("DEBUG: Calling setAttributes");
AttributeList attList = new AttributeList();
attList.add(new Attribute("FirstName", ANY_NAME));
attList.add(new Attribute("LastName", ANY_NAME));
mbsc.setAttributes(objName, attList);
}
示例2: doCreateRequest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
protected int doCreateRequest(MBeanServerConnection mbsc,
ObjectName on,
boolean expectedException) {
int errorCount = 0;
try {
Utils.debug(Utils.DEBUG_STANDARD,
"ClientSide::doCreateRequest: Create and register the MBean") ;
mbsc.createMBean("Simple", on) ;
if (expectedException) {
System.out.println("ClientSide::doCreateRequest: " +
"(ERROR) Create did not fail with expected SecurityException");
errorCount++;
} else {
System.out.println("ClientSide::doCreateRequest: (OK) Create succeed") ;
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
if (expectedException) {
if (e instanceof java.lang.SecurityException) {
System.out.println("ClientSide::doCreateRequest: " +
"(OK) Create failed with expected SecurityException") ;
} else {
System.out.println("ClientSide::doCreateRequest: " +
"(ERROR) Create failed with " +
e.getClass() + " instead of expected SecurityException");
errorCount++;
}
} else {
System.out.println("ClientSide::doCreateRequest: " +
"(ERROR) Create failed");
errorCount++;
}
}
return errorCount;
}
示例3: mbeanOp
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void mbeanOp(MBeanServerConnection mserver, ObjectName name, boolean adding)
throws Exception {
if (adding) {
mserver.createMBean("javax.management.timer.Timer", name);
} else {
mserver.unregisterMBean(name);
}
}
示例4: jmxCreate
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* create new Mbean and when set from ClassLoader Objectname
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxCreate(MBeanServerConnection jmxServerConnection,
String name) throws Exception {
String error = null;
Object argsA[] = null;
String sigA[] = null;
if (args != null) {
argsA = new Object[ args.size()];
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());
}
}
}
if (classLoader != null && !"".equals(classLoader)) {
if (isEcho()) {
handleOutput("create MBean " + name + " from class "
+ className + " with classLoader " + classLoader);
}
if(args == null)
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader));
else
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader),argsA,sigA);
} else {
if (isEcho()) {
handleOutput("create MBean " + name + " from class "
+ className);
}
if(args == null)
jmxServerConnection.createMBean(className, new ObjectName(name));
else
jmxServerConnection.createMBean(className, new ObjectName(name),argsA,sigA);
}
return error;
}
示例5: jmxCreate
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* create new Mbean and when set from ClassLoader Objectname
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxCreate(MBeanServerConnection jmxServerConnection,
String name) throws Exception {
String error = null;
Object argsA[] = null;
String sigA[] = null;
if (args != null) {
argsA = new Object[ args.size()];
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());
}
}
}
if (classLoader != null && !"".equals(classLoader)) {
if (isEcho()) {
handleOutput("create MBean " + name + " from class "
+ className + " with classLoader " + classLoader);
}
if(args == null)
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader));
else
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader),argsA,sigA);
} else {
if (isEcho()) {
handleOutput("create MBean " + name + " from class "
+ className);
}
if(args == null)
jmxServerConnection.createMBean(className, new ObjectName(name));
else
jmxServerConnection.createMBean(className, new ObjectName(name),argsA,sigA);
}
return error;
}
示例6: doBasicMXBeanTest
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- doBasicMXBeanTest") ;
try {
ObjectName objName =
new ObjectName("sqe:type=BasicMXBean") ;
mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
printMBeanInfo(mbInfo);
System.out.println("---- OK\n") ;
System.out.println("getMBeanInfo\t\t"
+ mbInfo);
System.out.println("---- OK\n") ;
System.out.println("Check mxbean field in the MBeanInfo");
String mxbeanField =
(String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);
if ( mxbeanField == null || ! mxbeanField.equals("true")) {
System.out.println("---- ERROR : Improper mxbean field value "
+ mxbeanField);
errorCount++;
}
System.out.println("---- OK\n") ;
System.out.println("Set attribute ObjectNameAtt");
Attribute att = new Attribute("ObjectNameAtt", objName);
mbsc.setAttribute(objName, att);
ObjectName value =
(ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");
if ( ! value.equals(objName) ) {
errorCount++;
System.out.println("---- ERROR : setAttribute failed, got "
+ value
+ " while expecting "
+ objName);
}
System.out.println("---- OK\n") ;
System.out.println("Call operation doNothing");
mbsc.invoke(objName, "doNothing", null, null);
System.out.println("---- OK\n") ;
System.out.println("Call operation getWeather");
Object weather = mbsc.invoke(objName,
"getWeather",
new Object[]{Boolean.TRUE},
new String[]{"boolean"});
System.out.println("Weather is " + weather);
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
示例7: 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);
}
}
示例8: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start();
JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);
final MBeanServerConnection mbsc = client.getMBeanServerConnection();
final ObjectName mbean = ObjectName.getInstance(":type=Simple");
mbsc.createMBean(Simple.class.getName(), mbean);
System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
final Listener li = new Listener();
mbsc.addNotificationListener(mbean, li, null, null);
System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
mbsc.invoke(mbean, "emitNotification", null, null);
System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
final long stopTime = System.currentTimeMillis() + 2000;
synchronized(li) {
long toWait = stopTime - System.currentTimeMillis();
while (li.received < 1 && toWait > 0) {
li.wait(toWait);
toWait = stopTime - System.currentTimeMillis();
}
}
if (li.received < 1) {
throw new RuntimeException("No notif received!");
} else if (li.received > 1) {
throw new RuntimeException("Wait one notif but got: "+li.received);
}
System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");
System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
mbsc.removeNotificationListener(mbean, li);
// clean
client.close();
server.stop();
System.out.println("EmptyDomainNotificationTest-main: Bye.");
}
示例9: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start();
JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);
final MBeanServerConnection mbsc = client.getMBeanServerConnection();
final ObjectName mbean = ObjectName.getInstance(":type=Simple");
mbsc.createMBean(Simple.class.getName(), mbean);
System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
final Listener li = new Listener();
mbsc.addNotificationListener(mbean, li, null, null);
System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
mbsc.invoke(mbean, "emitNotification", null, null);
System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
synchronized(li) {
while (li.received < 1) {
li.wait();
}
}
if (li.received != 1) {
throw new RuntimeException("Wait one notif but got: "+li.received);
}
System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");
System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
mbsc.removeNotificationListener(mbean, li);
// clean
client.close();
server.stop();
System.out.println("EmptyDomainNotificationTest-main: Bye.");
}
示例10: jmxCreate
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* create new Mbean and when set from ClassLoader Objectname
*
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxCreate(MBeanServerConnection jmxServerConnection, String name) throws Exception {
String error = null;
Object argsA[] = null;
String sigA[] = null;
if (args != null) {
argsA = new Object[args.size()];
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());
}
}
}
if (classLoader != null && !"".equals(classLoader)) {
if (isEcho()) {
handleOutput("create MBean " + name + " from class " + className + " with classLoader " + classLoader);
}
if (args == null)
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader));
else
jmxServerConnection.createMBean(className, new ObjectName(name), new ObjectName(classLoader), argsA,
sigA);
} else {
if (isEcho()) {
handleOutput("create MBean " + name + " from class " + className);
}
if (args == null)
jmxServerConnection.createMBean(className, new ObjectName(name));
else
jmxServerConnection.createMBean(className, new ObjectName(name), argsA, sigA);
}
return error;
}
示例11: register
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
/**
* Create and register a new singleton instance of the ScanManager
* MBean in the given {@link MBeanServerConnection}.
* @param mbs The MBeanServer in which the new singleton instance
* should be created.
* @throws JMException The MBeanServer connection raised an exception
* while trying to instantiate and register the singleton MBean
* instance.
* @throws IOException There was a connection problem while trying to
* communicate with the underlying MBeanServer.
* @return A proxy for the registered MBean.
**/
public static ScanManagerMXBean register(MBeanServerConnection mbs)
throws IOException, JMException {
final ObjectInstance moi =
mbs.createMBean(ScanManager.class.getName(),SCAN_MANAGER_NAME);
final ScanManagerMXBean proxy =
JMX.newMXBeanProxy(mbs,moi.getObjectName(),
ScanManagerMXBean.class,true);
return proxy;
}