1 7 package org.jboss.test.remoting.oneway; 8 9 import java.util.ArrayList ; 10 import java.util.List ; 11 import javax.management.MBeanServer ; 12 import org.jboss.logging.Logger; 13 import org.jboss.remoting.InvocationRequest; 14 import org.jboss.remoting.ServerInvocationHandler; 15 import org.jboss.remoting.ServerInvoker; 16 import org.jboss.remoting.callback.InvokerCallbackHandler; 17 import org.jboss.remoting.invocation.RemoteInvocation; 18 19 26 public class OnewayServerInvocationHandler implements ServerInvocationHandler 27 { 28 private ServerInvoker invoker; 29 private List listeners = new ArrayList (); 30 private static final Logger log = Logger.getLogger(OnewayServerInvocationHandler.class); 31 32 private Object lastParam = null; 33 34 39 public void setInvoker(ServerInvoker invoker) 40 { 41 this.invoker = invoker; 42 } 43 44 49 public void setMBeanServer(MBeanServer server) 50 { 51 } 52 53 public Object invoke(InvocationRequest invocation) 54 throws Throwable 55 { 56 Object param = invocation.getParameter(); 57 String methodName = ""; 58 Object [] params = null; 59 String [] sig = null; 60 61 if(param instanceof RemoteInvocation) 62 { 63 RemoteInvocation rminvo = (RemoteInvocation) param; 64 methodName = rminvo.getMethodName(); 65 params = rminvo.getParameters(); 66 } 67 else 68 { 69 throw new Exception ("Unknown invocation payload (" + param + "). " + 70 "Should be instance of RemoteInvocation."); 71 } 72 73 Object ret = null; 74 if(methodName.equals("saveInvocationParameter")) 75 { 76 if(params != null) 77 { 78 lastParam = params[0]; 79 ret = lastParam; 80 } 81 } 82 else if(methodName.equals("getLastInvocationParameter")) 83 { 84 ret = lastParam; 85 } 86 else 87 { 88 log.error("Expected parameter to be either 'saveInvocationParameter' or 'getLastInvocationParameter'."); 89 } 90 return ret; 91 } 92 93 94 public void addListener(InvokerCallbackHandler callbackHandler) 95 { 96 listeners.add(callbackHandler); 97 log.debug("added listener " + callbackHandler); 98 } 99 100 public void removeListener(InvokerCallbackHandler callbackHandler) 101 { 102 listeners.remove(callbackHandler); 103 log.debug("removed listener " + callbackHandler); 104 } 105 106 } 107 | Popular Tags |