Thanks for your help, i found the example, and work perfectly in local lan
but after i deploy the mbean to the remote machine, and the client is within a
firewall, the callback does not work, how should i fix this problem?
| package com.gsms.jmx.rolling;
|
| import javax.management.*;
| import javax.management.MBeanServer;
| import javax.management.ObjectName;
| import org.jboss.mx.util.MBeanProxy;
| import org.jboss.mx.util.MBeanServerLocator;
| import javax.naming.InitialContext;
| import javax.naming.Context;
| import java.util.Hashtable;
| import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
| import java.io.Serializable;
| import org.jboss.jmx.adaptor.rmi.RMINotificationListener;
| import java.rmi.RemoteException;
| import java.rmi.server.UnicastRemoteObject;
| import javax.ejb.*;
| import org.jboss.jmx.connector.notification.ClientNotificationListener;
| import
org.jboss.jmx.connector.notification.RMIClientNotificationListenerInterface;
| import java.rmi.Remote;
|
| public class TestMBean implements Serializable {
|
| public static class Listener implements RMINotificationListener{
| public Listener() throws RemoteException {
| UnicastRemoteObject.exportObject(this);
| }
|
| public void handleNotification(Notification event, Object handback) {
| System.out.println("handleNotification, event: " + event);
| }
| }
|
| public TestMBean() {
|
| }
|
| public static Hashtable initContext() {
| Hashtable props = new Hashtable();
| props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
| props.put(Context.PROVIDER_URL, "203.194.245.101:1099");
| props.put("java.naming.rmi.security.manager", "no");
| props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
| props.put(Context.SECURITY_PRINCIPAL, "guest");
| props.put(Context.SECURITY_CREDENTIALS, "guest");
| return props;
| }
|
| public static void doSomething() throws Exception {
| InitialContext ctx = new InitialContext(initContext()); // From
jndi.properties
| RMIAdaptor server = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");
| ObjectName name = new ObjectName("acme.com:service=HelloWorld");
| MBeanInfo info = server.getMBeanInfo(name);
| System.out.println("Object name: " + info.getClassName());
| System.out.println("Object info: " + info);
| MBeanOperationInfo[] opInfo = info.getOperations();
| System.out.println("Object Operations: ");
|
| for(int o = 0; o < opInfo.length; o ++)
| {
| MBeanOperationInfo op = opInfo[o];
| String returnType = op.getReturnType();
| String opName = op.getName();
| System.out.print(" + "+returnType+" "+opName+"(");
| MBeanParameterInfo[] params = op.getSignature();
| for(int p = 0; p < params.length; p ++)
| {
| MBeanParameterInfo paramInfo = params[p];
| String pname = paramInfo.getName();
| String type = paramInfo.getType();
| if( pname.equals(type) )
| System.out.print(type);
| else
| System.out.print(type+" "+name);
| if( p < params.length-1 )
| System.out.print(',');
| }
| System.out.println(")");
| }
|
| // Register as a notification listener
| Listener listener = new Listener();
| server.addNotificationListener(name, listener, null, null);
|
| while(true){
| try {
| Thread.sleep(100);
| } catch (InterruptedException ex) {
| ex.printStackTrace(System.err);
| }
| }
|
| // Listener listener = new Listener();
| // server.addNotificationListener(new
ObjectName("acme.com:service=HelloWorld"), listener, null,
| // new Long(System.currentTimeMillis()));
| // MBeanServerConnection server = (MBeanServerConnection)
ctx.lookup("jmx/invoker/RMIAdaptor");
| // System.out.println(server.getAttribute(new
ObjectName("acme.com:service=HelloWorld"), "Message"));
| // server.invoke(new ObjectName("acme.com:service=HelloWorld"),
"printMessage", new Object[0], new String[0]);
|
| }
|
| public static void main(String[] args) {
| try {
| TestMBean.doSomething();
| } catch (Exception ex) {
| ex.printStackTrace(System.err);
| }
| }
|
| }
|
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3867233#3867233
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3867233
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user