All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JavaGroups.Dispatcher

java.lang.Object
   |
   +----JavaGroups.Dispatcher

public class Dispatcher
extends Object
A Dispatcher maintains a number of channels and allows clients to join one or more of those channels, and send and receive messages to/from channels. When an object joins a channel (given the channel name), it will be dispatched all messages received on that channel in the form of method invocations. Note that in order to receive all messages, an object should implement the methods required by the group (application-specific). It may itself invoke methods on all members of the channel (a channel is nothing else than a group !).

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); } }
}

See Also:
RemoteMethodCall, MethodInvoker

Constructor Index

 o Dispatcher(ChannelFactory, String)

Method Index

 o AddFunclet(String, Object, String, Object)
 o CreateChannel(String, String)
By default, all channels are created only when needed, using the default properties specified when creating the Dispatcher.
 o Destroy()
 o GetAddress(String)
 o GetMembers(String)
 o GetNumMembers(String)
 o HoldRequests(String)
 o Join(String, Object)
Creates a new ChannelEntry (if not yet present) and increments its use count.
 o Leave(String, Object)
Removes the object from the corresponding ChannelEntry's object list and decrements the use count.
 o ReleaseRequests(String)
 o Send(String, Object, MethodCall, boolean, long)
Sends a synchronous method call (in the form of a message) to 'dest' and returns the response.
 o Send(String, Object, String, boolean, long)
 o Send(String, Object, String, Object, boolean, long)
 o Send(String, Object, String, Object, Object, boolean, long)
 o Send(String, Object, String, Object, Object, Object, boolean, long)
 o SendGetFirst(String, MethodCall, long)
Send message, add req id in message correlation table and send request
 o SendGetFirst(String, String, long)
Sends the message via the corresponding ChannelEntry and adds it to the MessageCorrelator table.
 o SendGetFirst(String, String, Object, long)
 o SendGetFirst(String, String, Object, Object, long)
 o SendGetFirst(String, String, Object, Object, Object, long)
 o SendGetN(String, MethodCall, int, long)
 o SendGetN(String, String, int, long)
 o SendGetN(String, String, Object, int, long)
 o SendGetN(String, String, Object, Object, int, long)
 o SendGetN(String, String, Object, Object, Object, int, long)
 o SetMembershipListener(String, MembershipListener)
 o SetMethodLookup(MethodLookup)

Constructors

 o Dispatcher
 public Dispatcher(ChannelFactory f,
                   String default_properties)

Methods

 o SetMethodLookup
 public void SetMethodLookup(MethodLookup lookup)
 o HoldRequests
 public void HoldRequests(String channel_name)
 o ReleaseRequests
 public void ReleaseRequests(String channel_name)
 o Destroy
 public void Destroy()
 o GetNumMembers
 public int GetNumMembers(String channel_name)
 o GetMembers
 public Vector GetMembers(String channel_name)
 o AddFunclet
 public void AddFunclet(String channel_name,
                        Object target,
                        String funclet_name,
                        Object funclet)
 o CreateChannel
 public void CreateChannel(String channel_name,
                           String properties) throws Exception
By default, all channels are created only when needed, using the default properties specified when creating the Dispatcher. This method can be used to create a channel beforehand, and giving it special properties different from the default one.

 o Join
 public synchronized void Join(String channel_name,
                               Object joiner)
Creates a new ChannelEntry (if not yet present) and increments its use count. When the ChannelEntry is not yet present a new ChannelEntry will be created with an accompanying channel which is then connected to.

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.

 o Leave
 public synchronized void Leave(String channel_name,
                                Object leaver)
Removes the object from the corresponding ChannelEntry's object list and decrements the use count. When the use count is 0, the channel in the ChannelEntry will be disconnected and destroyed and the ChannelEntry removed.

 o SetMembershipListener
 public void SetMembershipListener(String channel_name,
                                   MembershipListener l)
 o GetAddress
 public Object GetAddress(String channel_name)
 o SendGetFirst
 public Object SendGetFirst(String channel_name,
                            MethodCall method_call,
                            long timeout) throws Exception
Send message, add req id in message correlation table and send request

 o SendGetN
 public Vector SendGetN(String channel_name,
                        MethodCall method_call,
                        int expected_responses,
                        long timeout) throws Exception
 o Send
 public Object Send(String channel_name,
                    Object dest,
                    MethodCall method_call,
                    boolean oneway,
                    long timeout) throws Exception
Sends a synchronous method call (in the form of a message) to 'dest' and returns the response. Timeout of 0 means block forever.

 o Send
 public Object Send(String channel_name,
                    Object dest,
                    String method_name,
                    boolean oneway,
                    long timeout) throws Exception
 o Send
 public Object Send(String channel_name,
                    Object dest,
                    String method_name,
                    Object arg1,
                    boolean oneway,
                    long timeout) throws Exception
 o Send
 public Object Send(String channel_name,
                    Object dest,
                    String method_name,
                    Object arg1,
                    Object arg2,
                    boolean oneway,
                    long timeout) throws Exception
 o Send
 public Object Send(String channel_name,
                    Object dest,
                    String method_name,
                    Object arg1,
                    Object arg2,
                    Object arg3,
                    boolean oneway,
                    long timeout) throws Exception
 o SendGetFirst
 public Object SendGetFirst(String channel_name,
                            String method_name,
                            long timeout) throws Exception
Sends the message via the corresponding ChannelEntry and adds it to the MessageCorrelator table. Blocks until response is received. Converts response to Object and returns it.

 o SendGetFirst
 public Object SendGetFirst(String channel_name,
                            String method_name,
                            Object arg1,
                            long timeout) throws Exception
 o SendGetFirst
 public Object SendGetFirst(String channel_name,
                            String method_name,
                            Object arg1,
                            Object arg2,
                            long timeout) throws Exception
 o SendGetFirst
 public Object SendGetFirst(String channel_name,
                            String method_name,
                            Object arg1,
                            Object arg2,
                            Object arg3,
                            long timeout) throws Exception
 o SendGetN
 public Vector SendGetN(String channel_name,
                        String method_name,
                        int expected_responses,
                        long timeout) throws Exception
 o SendGetN
 public Vector SendGetN(String channel_name,
                        String method_name,
                        Object arg1,
                        int expected_responses,
                        long timeout) throws Exception
 o SendGetN
 public Vector SendGetN(String channel_name,
                        String method_name,
                        Object arg1,
                        Object arg2,
                        int expected_responses,
                        long timeout) throws Exception
 o SendGetN
 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