|
1 |
| package net.sf.crispy.impl.jboss; |
|
2 |
| |
|
3 |
| import java.util.Hashtable; |
|
4 |
| import java.util.Map; |
|
5 |
| import java.util.Vector; |
|
6 |
| |
|
7 |
| import javax.management.MBeanServer; |
|
8 |
| |
|
9 |
| import net.sf.crispy.InvocationException; |
|
10 |
| import net.sf.crispy.util.Converter; |
|
11 |
| import net.sf.crispy.util.Invoker; |
|
12 |
| |
|
13 |
| import org.apache.commons.logging.Log; |
|
14 |
| import org.apache.commons.logging.LogFactory; |
|
15 |
| import org.jboss.remoting.InvocationRequest; |
|
16 |
| import org.jboss.remoting.ServerInvocationHandler; |
|
17 |
| import org.jboss.remoting.ServerInvoker; |
|
18 |
| import org.jboss.remoting.callback.InvokerCallbackHandler; |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public class JBossRemotingInvocationHandler implements ServerInvocationHandler { |
|
27 |
| |
|
28 |
| protected static final Log log = LogFactory.getLog (JBossRemotingInvocationHandler.class); |
|
29 |
| private Map services = new Hashtable(); |
|
30 |
| |
|
31 |
3
| public JBossRemotingInvocationHandler() {
|
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| } |
|
36 |
| |
|
37 |
3
| public void addService (String pvServiceInterface, Object pvServiceImpl) {
|
|
38 |
3
| services.put(pvServiceInterface, pvServiceImpl);
|
|
39 |
| } |
|
40 |
54
| public Object getService (String pvServiceInterface) {
|
|
41 |
54
| return services.get(pvServiceInterface);
|
|
42 |
| } |
|
43 |
1
| public Object removeService(String pvServiceInterface) {
|
|
44 |
1
| return services.remove(pvServiceInterface);
|
|
45 |
| } |
|
46 |
2
| public int serviceSize() {
|
|
47 |
2
| return services.size();
|
|
48 |
| } |
|
49 |
| |
|
50 |
54
| public Object invoke(InvocationRequest pvInvocation) throws Throwable {
|
|
51 |
54
| try {
|
|
52 |
54
| String lvClass = (String) pvInvocation.getRequestPayload().keySet().iterator().next();
|
|
53 |
54
| String lvMethod = (String) pvInvocation.getRequestPayload().get(lvClass);
|
|
54 |
| if (log.isDebugEnabled()) { log.debug("Invoke service: " + lvClass + " with method: " + lvMethod); } |
|
55 |
54
| Object lvObject = getService(lvClass);
|
|
56 |
0
| if (lvObject == null) { throw new InvocationException("For the class: " + lvClass + " can't find a register service!"); }
|
|
57 |
54
| Object lvResult = Invoker.invoke(lvObject, lvMethod, (Vector) pvInvocation.getParameter(), false, new Converter());
|
|
58 |
| if (log.isDebugEnabled()) { log.debug("Result invoke service " + lvClass + ": " + lvResult); } |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
52
| return lvResult;
|
|
63 |
| } catch (Exception e) { |
|
64 |
2
| return e;
|
|
65 |
| } |
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
2
| public void setMBeanServer(MBeanServer pvArg0) {
|
|
71 |
| |
|
72 |
| } |
|
73 |
| |
|
74 |
2
| public void setInvoker(ServerInvoker pvArg0) {
|
|
75 |
| |
|
76 |
| } |
|
77 |
| |
|
78 |
| |
|
79 |
1
| public void addListener(InvokerCallbackHandler pvArg0) {
|
|
80 |
| |
|
81 |
| } |
|
82 |
| |
|
83 |
1
| public void removeListener(InvokerCallbackHandler pvArg0) {
|
|
84 |
| |
|
85 |
| } |
|
86 |
| |
|
87 |
| } |