next up previous contents
Next: Example Up: Building Blocks Previous: Example   Contents


RpcDispatcher

This class is derived from MessageDispatcher. It allows a programmer to invoke remote methods in all (or single) group members and optionally wait for the return value(s). An application will typically create a channel and layer the RpcDispatcher building block on top of it, which allows it to dispatch remote methods (client role) and at the same time be called by other members (server role).

Compared to MessageDispatcher, no handle() method needs to be implemented. Instead the methods to be called can be placed directly in the class using regular method definitions (see example below). The invoke remote method calls (unicast and multicast) the following methods are used (not all methods shown):

  public RspList callRemoteMethods(Vector dests, String method_name, int mode, long timeout;
  public RspList callRemoteMethods(Vector dests, String method_name, Object arg1, 
				   int mode, long timeout);
  public Object callRemoteMethod(Address dest, String method_name, int mode, long timeout);
  public Object callRemoteMethod(Address dest, String method_name, Object arg1,
                                 int mode, long timeout);

The family of callRemoteMethods() is invoked with a list of receiver addresses. If null, the method will be invoked in all group members (including the sender). Each call takes the name of the method to be invoked and the mode and timeout parameters, which are the same as for MessageDispatcher. Additionally, each method takes zero or more parameters: there are callRemoteMethods() methods with up to 3 arguments. As shown in the example above, the first 2 methods take zero and one parameters respectively.

The family of callRemoteMethod() methods takes almost the same parameters, except that there is only one destination address instead of a list. If the dest argument is null, the call will fail.

If a sender needs to use more than 3 arguments, it can use the generic versions of callRemoteMethod() and callRemoteMethods() which use a MethodCall4.1 instance rather than explicit arguments.

Java's Reflection API is used to find the correct method in the receiver according to the method name and number and types of supplied arguments. There is a runtime exception if a method cannot be resolved.



Subsections
next up previous contents
Next: Example Up: Building Blocks Previous: Example   Contents
Bela Ban 2002-11-16