KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > marshall > InactiveRegionAwareRpcDispatcher


1 package org.jboss.cache.marshall;
2
3 import org.jgroups.Channel;
4 import org.jgroups.MembershipListener;
5 import org.jgroups.Message;
6 import org.jgroups.MessageListener;
7 import org.jgroups.blocks.MethodCall;
8 import org.jgroups.blocks.PullPushAdapter;
9 import org.jgroups.blocks.RpcDispatcher;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * Extends {@link org.jgroups.blocks.RpcDispatcher} and adds the possibility that the marshaller may throw {@link org.jboss.cache.marshall.InactiveRegionException}s.
15  *
16  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani</a>
17  * @since 2.0.0
18  */

19 public class InactiveRegionAwareRpcDispatcher extends RpcDispatcher
20 {
21    public InactiveRegionAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object JavaDoc server_obj)
22    {
23       super(channel, l, l2, server_obj);
24    }
25
26    public InactiveRegionAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object JavaDoc server_obj, boolean deadlock_detection)
27    {
28       super(channel, l, l2, server_obj, deadlock_detection);
29    }
30
31    public InactiveRegionAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object JavaDoc server_obj, boolean deadlock_detection, boolean concurrent_processing)
32    {
33       super(channel, l, l2, server_obj, deadlock_detection, concurrent_processing);
34    }
35
36    public InactiveRegionAwareRpcDispatcher(PullPushAdapter adapter, Serializable JavaDoc id, MessageListener l, MembershipListener l2, Object JavaDoc server_obj)
37    {
38       super(adapter, id, l, l2, server_obj);
39    }
40
41    /**
42     * Message contains MethodCall. Execute it against *this* object and return result.
43     * Use MethodCall.invoke() to do this. Return result.
44     */

45    @Override JavaDoc
46    public Object JavaDoc handle(Message req)
47    {
48       Object JavaDoc body = null;
49       org.jgroups.blocks.MethodCall method_call;
50
51       if (server_obj == null)
52       {
53          if (log.isErrorEnabled()) log.error("no method handler is registered. Discarding request.");
54          return null;
55       }
56
57       if (req == null || req.getLength() == 0)
58       {
59          if (log.isErrorEnabled()) log.error("message or message buffer is null");
60          return null;
61       }
62
63       try
64       {
65          body = req_marshaller != null ? req_marshaller.objectFromByteBuffer(req.getBuffer()) : req.getObject();
66       }
67       catch (Throwable JavaDoc e)
68       {
69          if (e instanceof InactiveRegionException)
70          {
71             if (log.isTraceEnabled()) log.trace("Exception from marshaller: " + e.getMessage());
72             return null;
73          }
74
75          if (log.isErrorEnabled()) log.error("exception marshalling object", e);
76          return e;
77       }
78
79       if (body == null || !(body instanceof MethodCall))
80       {
81          if (log.isErrorEnabled()) log.error("message does not contain a MethodCall object");
82          return null;
83       }
84
85       method_call = (MethodCall) body;
86
87       try
88       {
89          if (log.isTraceEnabled())
90             log.trace("[sender=" + req.getSrc() + "], method_call: " + method_call);
91
92          return method_call.invoke(server_obj);
93       }
94       catch (Throwable JavaDoc x)
95       {
96          return x;
97       }
98    }
99 }
100
Popular Tags