All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----JavaGroups.MethodCall | +----JavaGroups.RemoteMethodCall
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).
public RemoteMethodCall(Transport t)RemoteMethodCall
public RemoteMethodCall(Transport t, String name)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, String funclet_name)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, Object arg1)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, String funclet_name, Object arg1)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, Object arg1, Object arg2)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, String funclet_name, Object arg1, Object arg2)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, Object arg1, Object arg2, Object arg3)RemoteMethodCall
public RemoteMethodCall(Transport t, String name, String funclet_name, Object arg1, Object arg2, Object arg3)
public Object Send(Object dest, boolean oneway, long timeout) throws ExceptionSendGetFirst
public Object SendGetFirst(long timeout) throws ExceptionSendGetN
public Vector SendGetN(int expected_responses, long timeout) throws Exception
SendGetN(0, 0) can be used to send a method call to all members without expecting any responses
public static void main(String args[])
All Packages Class Hierarchy This Package Previous Next Index