JavaGroups
Class MessageDispatcher

java.lang.Object
  |
  +--JavaGroups.JavaStack.Protocol
        |
        +--JavaGroups.MessageDispatcher
Direct Known Subclasses:
RpcDispatcher

public class MessageDispatcher
extends Protocol
implements UpHandler, RequestHandler

Used on top of channel to implement group requests. Client's Handle() method is called when request is received. Is the equivalent of RpcProtocol on the application instead of protocol level.


Constructor Summary
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2)
           
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler)
           
 
Method Summary
 RspList CastMessage(java.util.Vector dests, Message msg, int mode, long timeout)
          Cast a message to all members, and wait for mode responses.
 void Down(Event evt)
          An event is to be sent down the stack.
 void finalize()
           
 java.lang.String GetName()
           
 java.lang.Object Handle(Message msg)
           
 void PassDown(Event evt)
          Causes the event to be forwarded to the next layer down in the hierarchy.Typically called by the implementation of Down (when done).
 void PassUp(Event evt)
          Called by request correlator when message was not generated by it.
 void Send(Message msg)
           
 java.lang.Object SendMessage(Message msg, int mode, long timeout)
          Sends a message to a single member (destination = msg.dest) and returns the response.
 void SetMembershipListener(MembershipListener l)
           
 void SetMessageListener(MessageListener l)
           
 void SetRequestHandler(RequestHandler rh)
           
 void Start()
           
 void StartDownHandler()
          Used internally.
 void StartUpHandler()
          Used internally.
 void Stop()
           
 void StopInternal()
          Used internally.
 void Up(Event evt)
          Called by channel (we registered before) when event is received.
 
Methods inherited from class JavaGroups.JavaStack.Protocol
GetDownProtocol, GetProperties, GetUpProtocol, ProvidedDownServices, ProvidedUpServices, RequiredDownServices, RequiredUpServices, Reset, SetDownProtocol, SetProperties, SetProtocolStack, SetUpProtocol
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDispatcher

public MessageDispatcher(Channel channel,
                         MessageListener l,
                         MembershipListener l2)

MessageDispatcher

public MessageDispatcher(Channel channel,
                         MessageListener l,
                         MembershipListener l2,
                         RequestHandler req_handler)
Method Detail

finalize

public void finalize()

Start

public void Start()

Stop

public void Stop()

SetMessageListener

public void SetMessageListener(MessageListener l)

SetMembershipListener

public void SetMembershipListener(MembershipListener l)

SetRequestHandler

public void SetRequestHandler(RequestHandler rh)

Send

public void Send(Message msg)
          throws ChannelNotConnected,
                 ChannelClosed

CastMessage

public RspList CastMessage(java.util.Vector dests,
                           Message msg,
                           int mode,
                           long timeout)
Cast a message to all members, and wait for mode responses. The responses are returned in a response list, where each response is associated with its sender.

Uses GroupRequest.

Parameters:
dests - The members to which then message is to be sent. If it is null, then the message is sent to all members
msg - The message to be sent to n members
mode - Defined in GroupRequest. The number of responses to wait for:
  1. GET_FIRST: return the first response received.
  2. GET_ALL: wait for all responses (minus the ones from suspected members)
  3. GET_MAJORITY: wait for a majority of all responses (relative to the grp size)
  4. GET_ABS_MAJORITY: wait for majority (absolute, computed once)
  5. GET_N: wait for n responses (may block if n > group size)
  6. GET_NONE: wait for no responses, return immediately (non-blocking)
timeout - If 0: wait forever. Otherwise, wait for mode responses or timeout time.
Returns:
RspList A list of responses. Each response is an Object and associated to its sender.

SendMessage

public java.lang.Object SendMessage(Message msg,
                                    int mode,
                                    long timeout)
                             throws Timeout,
                                    Suspected
Sends a message to a single member (destination = msg.dest) and returns the response. The message's destination must be non-zero !

Handle

public java.lang.Object Handle(Message msg)
Specified by:
Handle in interface RequestHandler

GetName

public java.lang.String GetName()
Overrides:
GetName in class Protocol

StartUpHandler

public void StartUpHandler()
Description copied from class: Protocol
Used internally. If overridden, call parent's method first
Overrides:
StartUpHandler in class Protocol

StartDownHandler

public void StartDownHandler()
Description copied from class: Protocol
Used internally. If overridden, call parent's method first
Overrides:
StartDownHandler in class Protocol

StopInternal

public void StopInternal()
Description copied from class: Protocol
Used internally. If overridden, call parent's method first
Overrides:
StopInternal in class Protocol

PassUp

public void PassUp(Event evt)
Called by request correlator when message was not generated by it. We handle it and call the message listener's corresponding methods
Overrides:
PassUp in class Protocol

PassDown

public void PassDown(Event evt)
Description copied from class: Protocol
Causes the event to be forwarded to the next layer down in the hierarchy.Typically called by the implementation of Down (when done).
Overrides:
PassDown in class Protocol

Up

public void Up(Event evt)
Called by channel (we registered before) when event is received. This is the UpHandler interface.
Specified by:
Up in interface UpHandler
Overrides:
Up in class Protocol

Down

public void Down(Event evt)
Description copied from class: Protocol
An event is to be sent down the stack. The layer may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the layer may need to add a header to it (or do nothing at all) before sending it down the stack using PassDown. In case of a GET_ADDRESS event (which tries to retrieve the stack's address from one of the bottom layers), the layer may need to send a new response event back up the stack using PassUp.
Overrides:
Down in class Protocol