KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > oneway > OnewayServerInvocationHandler


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.oneway;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.List JavaDoc;
11 import javax.management.MBeanServer JavaDoc;
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 /**
20  * MockServerInvocationHandler
21  *
22  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
23  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
24  * @version $Revision: 1.3 $
25  */

26 public class OnewayServerInvocationHandler implements ServerInvocationHandler
27 {
28    private ServerInvoker invoker;
29    private List JavaDoc listeners = new ArrayList JavaDoc();
30    private static final Logger log = Logger.getLogger(OnewayServerInvocationHandler.class);
31
32    private Object JavaDoc lastParam = null;
33
34    /**
35     * set the invoker that owns this handler
36     *
37     * @param invoker
38     */

39    public void setInvoker(ServerInvoker invoker)
40    {
41       this.invoker = invoker;
42    }
43
44    /**
45     * set the mbean server that the handler can reference
46     *
47     * @param server
48     */

49    public void setMBeanServer(MBeanServer JavaDoc server)
50    {
51    }
52
53    public Object JavaDoc invoke(InvocationRequest invocation)
54          throws Throwable JavaDoc
55    {
56       Object JavaDoc param = invocation.getParameter();
57       String JavaDoc methodName = "";
58       Object JavaDoc[] params = null;
59       String JavaDoc[] 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 JavaDoc("Unknown invocation payload (" + param + "). " +
70                              "Should be instance of RemoteInvocation.");
71       }
72
73       Object JavaDoc 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