This content has been marked as final.
Show 2 replies
-
1. Re: Remote Call and Remote Notification to mbean
starksm64 Feb 18, 2005 1:32 PM (in response to cycchow)There is an example org.jboss.chap2.xmbean.TestXMBean1 admin/devel guide examples that illustrates this. It used to have a section in the guide but was dropped when it was updated for 4.0.x for some reason. I have asked that it be restored to the guide, but the example is still there.
-
2. Re: Remote Call and Remote Notification to mbean
cycchow Feb 21, 2005 5:48 AM (in response to cycchow)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); } } }