All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JavaGroups.RemoteMethodCall

java.lang.Object
   |
   +----JavaGroups.MethodCall
           |
           +----JavaGroups.RemoteMethodCall

public class RemoteMethodCall
extends MethodCall
Allows to send method invocations to all (or a subset) of the members of a group. Uses SyncCall to wait for the first or the first N responses. Converts response back to an object or, in the case of an exception, throws it.

The example code below shows how a client can invoke a remote method call on all members of a group and print the first result returned:

 import java.util.*;
 import JavaGroups.channel.*;
 public class RemoteMethodCallTest {
public static void main(String args[]) { Channel channel; RemoteMethodCall m; Object ret; try { channel=new EnsChannel("MethodInvokerTest", null); channel.Connect(5000); m=new RemoteMethodCall(channel, "Divide", new Integer(3), new Integer(4)); ret=m.SendGetFirst(5000); // wait for maximum 5 seconds System.out.println( ret != null ? ret : "Response is null"); } catch(Exception e) { System.err.println(e); } finally { channel.Disconnect(); channel.Destroy(); } }
}

The code first creates a channel and connects to it. Then (in bold letters) a RemoteMethodCall object is created which uses the channel to send messages and receive responses. (Actually, a SyncCall object is used to send a message synchronously and wait for the first (or the first N) responses). Method SendGetFirst sends the method call (as a Message) to all members of the group, converts the first reponse message to an object and returns it to the caller. Method SendGetN does essentially the same, but returns N results (e.g. waits for all groups members to respond). Note that N=0 does not wait for a response.

In the example a method called "Divide" will be called with two arguments.

The corresponding code for the server side (dispatching of message to method and returning of result(s) can written using an instance of MethodInvoker.

If an asynchronous (oneway) remote method call is wanted, method SendGetN can be used by setting expected_responses to 0. In this case, no responses will be returned (even if the method itself does return a result).

See Also:
MethodInvoker, Dispatcher

Constructor Index

 o RemoteMethodCall(Transport)
 o RemoteMethodCall(Transport, String)
 o RemoteMethodCall(Transport, String, Object)
 o RemoteMethodCall(Transport, String, Object, Object)
 o RemoteMethodCall(Transport, String, Object, Object, Object)
 o RemoteMethodCall(Transport, String, String)
 o RemoteMethodCall(Transport, String, String, Object)
 o RemoteMethodCall(Transport, String, String, Object, Object)
 o RemoteMethodCall(Transport, String, String, Object, Object, Object)

Method Index

 o main(String[])
 o Send(Object, boolean, long)
 o SendGetFirst(long)
 o SendGetN(int, long)
Invokes a method on all members of the group and returns more than one response.

Constructors

 o RemoteMethodCall
 public RemoteMethodCall(Transport t)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         String funclet_name)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         Object arg1)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         String funclet_name,
                         Object arg1)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         Object arg1,
                         Object arg2)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         String funclet_name,
                         Object arg1,
                         Object arg2)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         Object arg1,
                         Object arg2,
                         Object arg3)
 o RemoteMethodCall
 public RemoteMethodCall(Transport t,
                         String name,
                         String funclet_name,
                         Object arg1,
                         Object arg2,
                         Object arg3)

Methods

 o Send
 public Object Send(Object dest,
                    boolean oneway,
                    long timeout) throws Exception
 o SendGetFirst
 public Object SendGetFirst(long timeout) throws Exception
 o SendGetN
 public Vector SendGetN(int expected_responses,
                        long timeout) throws Exception
Invokes a method on all members of the group and returns more than one response. (Note that N should not be greater than the size of the group, or at least the timeout should be sety to greater than 0, otherwise the call waits forever). All responses are converted to objects and returned in a vector. If any method call threw an exception, the vector will contain it instead of a normal object. It is the caller's duty to check whether there are any exceptions present in the vector.

SendGetN(0, 0) can be used to send a method call to all members without expecting any responses

 o main
 public static void main(String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index