All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----JavaGroups.Dispatcher
Note that an object that has not previously called Join() is nevertheless able to send messages to the group members and receive responses, but requests dispatched to the group members will not be dispatched to it.
The Dispatcher
class is a replacement for classes RemoteMethodCall
(client side) and MethodInvoker
(server side). Instead of using 2 classes,
client-server applications can more conveniently be written using the dispatcher. Its main
advantage is that, instead of assuming 1 client and 1 server, it allows multiple clients
to issue requests and register to get their methods invoked. In one line, the dispatcher
is a more sophisticated class offering the combined interfaces of both
RemotemethodCall
and MethodInvoker
and allows multiple objects
to be registered.
The example code below shows an application that acts both in the client role by sending multicasts to all members, and in the server role by registering its object for methods to be invoked on it:
import java.util.*; import JavaGroups.channel.*;
public class DispatcherTestChannel {
public Date GetDate() {return new Date();}
public static void main(String args[]) { DispatcherTestChannel obj1; Dispatcher disp=new Dispatcher(); Object result;
try { obj1=new DispatcherTestChannel(); disp.Join("GroupA", obj1); while(true) { result=(Date)disp.SendGetFirst("GroupA", "GetDate", null, 3000); if(result != null) System.out.println("Received response: " + result); Thread.currentThread().sleep(2000); } } catch(Exception e) { System.err.println(e); } }
}
public Dispatcher(ChannelFactory f, String default_properties)
public void SetMethodLookup(MethodLookup lookup)HoldRequests
public void HoldRequests(String channel_name)ReleaseRequests
public void ReleaseRequests(String channel_name)Destroy
public void Destroy()GetNumMembers
public int GetNumMembers(String channel_name)GetMembers
public Vector GetMembers(String channel_name)AddFunclet
public void AddFunclet(String channel_name, Object target, String funclet_name, Object funclet)CreateChannel
public void CreateChannel(String channel_name, String properties) throws Exception
public synchronized void Join(String channel_name, Object joiner)
Adds the object to the ChannelEntry's object list. Every message received by the channel, that is a request, will be dispatched to all objects in the list.
public synchronized void Leave(String channel_name, Object leaver)
public void SetMembershipListener(String channel_name, MembershipListener l)GetAddress
public Object GetAddress(String channel_name)SendGetFirst
public Object SendGetFirst(String channel_name, MethodCall method_call, long timeout) throws Exception
public Vector SendGetN(String channel_name, MethodCall method_call, int expected_responses, long timeout) throws ExceptionSend
public Object Send(String channel_name, Object dest, MethodCall method_call, boolean oneway, long timeout) throws Exception
public Object Send(String channel_name, Object dest, String method_name, boolean oneway, long timeout) throws ExceptionSend
public Object Send(String channel_name, Object dest, String method_name, Object arg1, boolean oneway, long timeout) throws ExceptionSend
public Object Send(String channel_name, Object dest, String method_name, Object arg1, Object arg2, boolean oneway, long timeout) throws ExceptionSend
public Object Send(String channel_name, Object dest, String method_name, Object arg1, Object arg2, Object arg3, boolean oneway, long timeout) throws ExceptionSendGetFirst
public Object SendGetFirst(String channel_name, String method_name, long timeout) throws Exception
public Object SendGetFirst(String channel_name, String method_name, Object arg1, long timeout) throws ExceptionSendGetFirst
public Object SendGetFirst(String channel_name, String method_name, Object arg1, Object arg2, long timeout) throws ExceptionSendGetFirst
public Object SendGetFirst(String channel_name, String method_name, Object arg1, Object arg2, Object arg3, long timeout) throws ExceptionSendGetN
public Vector SendGetN(String channel_name, String method_name, int expected_responses, long timeout) throws ExceptionSendGetN
public Vector SendGetN(String channel_name, String method_name, Object arg1, int expected_responses, long timeout) throws ExceptionSendGetN
public Vector SendGetN(String channel_name, String method_name, Object arg1, Object arg2, int expected_responses, long timeout) throws ExceptionSendGetN
public Vector SendGetN(String channel_name, String method_name, Object arg1, Object arg2, Object arg3, int expected_responses, long timeout) throws Exception
All Packages Class Hierarchy This Package Previous Next Index