下面列出了javax.management.MBeanServerConnection#unregisterMBean ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Unregister MBean.
*
* @param jmxServerConnection Connection to the JMX server
* @param name The MBean name
* @return null (no error message to report other than exception)
* @throws Exception An error occurred
*/
protected String jmxUuregister(MBeanServerConnection jmxServerConnection,String name) throws Exception {
String error = null;
if(isEcho()) {
handleOutput("Unregister MBean " + name );
}
jmxServerConnection.unregisterMBean(
new ObjectName(name));
return error;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
/**
* Unregister Mbean
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxUuregister(MBeanServerConnection jmxServerConnection,String name) throws Exception {
String error = null;
if(isEcho()) {
handleOutput("Unregister MBean " + name );
}
jmxServerConnection.unregisterMBean(
new ObjectName(name));
return error;
}
public static void main(String[] args) throws Exception
{
// The address of the connector server
JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");
// Create and connect the connector client
JMXConnector cntor = JMXConnectorFactory.connect(url, null);
// The connection represent, on client-side, the remote MBeanServer
MBeanServerConnection connection = cntor.getMBeanServerConnection();
// The listener that will receive notifications from a remote MBean
NotificationListener listener = new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println(notification);
}
};
// The MBeanServerDelegate emits notifications about registration/unregistration of MBeans
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
connection.addNotificationListener(delegateName, listener, null, null);
// Give chance to the notification machinery to setup
Thread.sleep(1000);
// Now register a remote MBean, for example an MLet, so that the MBeanServerDelegate
// will emit notifications for its registration
ObjectName name = ObjectName.getInstance("examples:mbean=mlet");
// First notification
connection.createMBean(MLet.class.getName(), name, null);
// Second notification
connection.unregisterMBean(name);
}
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);
}
}
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);
}
}
public static void main(String[] args) throws Exception
{
// This JMXServiceURL works only if the connector server is on the same host of
// the connector. If this is not the case, set the correct host name.
JMXServiceURL address = new JMXServiceURL("hessian", null, 8080, "/hessian");
// Connect a JSR 160 JMXConnector to the server side
JMXConnector connector = JMXConnectorFactory.connect(address);
// Retrieve an MBeanServerConnection that represent the MBeanServer
// the remote connector server is bound to
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Call the server side as if it is a local MBeanServer
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;
System.out.println(delegate.getImplementationVendor() + " is cool !");
// Register an MBean, and get notifications via the Hessian protocol
connection.addNotificationListener(delegateName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println("Got the following notification: " + notification);
}
}, null, null);
ObjectName timerName = ObjectName.getInstance("services:type=Timer");
connection.createMBean(Timer.class.getName(), timerName, null);
// Unregistering the MBean to get another notification
connection.unregisterMBean(timerName);
// Allow the unregistration notification to arrive before killing this JVM
Thread.sleep(1000);
connector.close();
}
/**
* Unregister Mbean
* @param jmxServerConnection
* @param name
* @return The value of the given named attribute
* @throws Exception
*/
protected String jmxUuregister(MBeanServerConnection jmxServerConnection,String name) throws Exception {
String error = null;
if(isEcho()) {
handleOutput("Unregister MBean " + name );
}
jmxServerConnection.unregisterMBean(
new ObjectName(name));
return error;
}
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);
}
}
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);
}
}
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);
}
}
public static void main(String[] args) throws Exception
{
// This JMXServiceURL works only if the connector server is in-VM with
// the connector. If this is not the case, set the correct host name.
JMXServiceURL address = new JMXServiceURL("soap", null, 8080, "/jmxconnector");
// Connect a JSR 160 JMXConnector to the server side
JMXConnector connector = JMXConnectorFactory.connect(address);
// Retrieve an MBeanServerConnection that represent the MBeanServer
// the remote connector server is bound to
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Call the server side as if it is a local MBeanServer
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;
System.out.println(delegate.getImplementationVendor() + " is cool !");
// Register an MBean, and get notifications via the SOAP protocol
connection.addNotificationListener(delegateName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println("Got the following notification: " + notification);
}
}, null, null);
ObjectName timerName = ObjectName.getInstance("services:type=Timer");
connection.createMBean(Timer.class.getName(), timerName, null);
// Unregistering the MBean to get another notification
connection.unregisterMBean(timerName);
// Allow the unregistration notification to arrive before killing this JVM
Thread.sleep(1000);
connector.close();
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
public static void main(String[] args) throws Exception
{
// Replace the value with the file path of your keystore.
// IMPORTANT: this should NOT be done in production environments, it is shown here just as an example.
System.setProperty("javax.net.ssl.trustStore", "<your-keystore>");
// This JMXServiceURL works only if the connector server is on the same host of
// the connector. If this is not the case, set the correct host name.
JMXServiceURL address = new JMXServiceURL("hessian+ssl", null, 8443, "/hessianssl");
// Connect a JSR 160 JMXConnector to the server side
JMXConnector connector = JMXConnectorFactory.connect(address);
// Retrieve an MBeanServerConnection that represent the MBeanServer
// the remote connector server is bound to
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Call the server side as if it is a local MBeanServer
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;
System.out.println(delegate.getImplementationVendor() + " is cool !");
// Register an MBean, and get notifications via the Hessian protocol
connection.addNotificationListener(delegateName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println("Got the following notification: " + notification);
}
}, null, null);
ObjectName timerName = ObjectName.getInstance("services:type=Timer");
connection.createMBean(Timer.class.getName(), timerName, null);
// Unregistering the MBean to get another notification
connection.unregisterMBean(timerName);
// Allow the unregistration notification to arrive before killing this JVM
Thread.sleep(1000);
connector.close();
}