org.jgroups.blocks

Class MessageDispatcher

Implemented Interfaces:
RequestHandler
Known Direct Subclasses:
RpcDispatcher

public class MessageDispatcher
extends java.lang.Object
implements 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.

Author:
Bela Ban

Field Summary

protected PullPushAdapter
adapter
protected Channel
channel
protected boolean
concurrent_processing
Process items on the queue concurrently (RequestCorrelator).
protected RequestCorrelator
corr
protected boolean
deadlock_detection
protected Serializable
id
protected Address
local_addr
protected Log
log
protected Vector
members
protected MembershipListener
membership_listener
protected MessageListener
msg_listener
protected org.jgroups.blocks.MessageDispatcher.ProtocolAdapter
prot_adapter
protected RequestHandler
req_handler
protected org.jgroups.blocks.MessageDispatcher.TransportAdapter
transport_adapter

Constructor Summary

MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2)
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, boolean deadlock_detection)
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, boolean deadlock_detection, boolean concurrent_processing)
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler)
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean deadlock_detection)
MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean deadlock_detection, boolean concurrent_processing)
MessageDispatcher(PullPushAdapter adapter, Serializable id, MessageListener l, MembershipListener l2)
MessageDispatcher(PullPushAdapter adapter, Serializable id, MessageListener l, MembershipListener l2, RequestHandler req_handler)
MessageDispatcher(PullPushAdapter adapter, Serializable id, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean concurrent_processing)

Method Summary

void
castMessage(Vector dests, long req_id, Message msg, RspCollector coll)
Multicast a message request to all members in dests and receive responses via the RspCollector interface.
RspList
castMessage(Vector dests, Message msg, int mode, long timeout)
Cast a message to all members, and wait for mode responses.
void
done(long req_id)
Object
handle(Message msg)
void
send(Message msg)
Object
sendMessage(Message msg, int mode, long timeout)
Sends a message to a single member (destination = msg.dest) and returns the response.
void
setConcurrentProcessing(boolean flag)
void
setDeadlockDetection(boolean flag)
void
setMembershipListener(MembershipListener l)
void
setMessageListener(MessageListener l)
void
setRequestHandler(RequestHandler rh)
void
start()
void
stop()

Field Details

adapter

protected PullPushAdapter adapter


channel

protected Channel channel


concurrent_processing

protected boolean concurrent_processing
Process items on the queue concurrently (RequestCorrelator). The default is to wait until the processing of an item has completed before fetching the next item from the queue. Note that setting this to true may destroy the properties of a protocol stack, e.g total or causal order may not be guaranteed. Set this to true only if you know what you're doing !


corr

protected RequestCorrelator corr


deadlock_detection

protected boolean deadlock_detection


id

protected Serializable id


local_addr

protected Address local_addr


log

protected Log log


members

protected Vector members


membership_listener

protected MembershipListener membership_listener


msg_listener

protected MessageListener msg_listener


prot_adapter

protected org.jgroups.blocks.MessageDispatcher.ProtocolAdapter prot_adapter


req_handler

protected RequestHandler req_handler


transport_adapter

protected org.jgroups.blocks.MessageDispatcher.TransportAdapter transport_adapter

Constructor Details

MessageDispatcher

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


MessageDispatcher

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


MessageDispatcher

public MessageDispatcher(Channel channel,
                         MessageListener l,
                         MembershipListener l2,
                         boolean deadlock_detection,
                         boolean concurrent_processing)


MessageDispatcher

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


MessageDispatcher

public MessageDispatcher(Channel channel,
                         MessageListener l,
                         MembershipListener l2,
                         RequestHandler req_handler,
                         boolean deadlock_detection)


MessageDispatcher

public MessageDispatcher(Channel channel,
                         MessageListener l,
                         MembershipListener l2,
                         RequestHandler req_handler,
                         boolean deadlock_detection,
                         boolean concurrent_processing)


MessageDispatcher

public MessageDispatcher(PullPushAdapter adapter,
                         Serializable id,
                         MessageListener l,
                         MembershipListener l2)


MessageDispatcher

public MessageDispatcher(PullPushAdapter adapter,
                         Serializable id,
                         MessageListener l,
                         MembershipListener l2,
                         RequestHandler req_handler)


MessageDispatcher

public MessageDispatcher(PullPushAdapter adapter,
                         Serializable id,
                         MessageListener l,
                         MembershipListener l2,
                         RequestHandler req_handler,
                         boolean concurrent_processing)

Method Details

castMessage

public void castMessage(Vector dests,
                        long req_id,
                        Message msg,
                        RspCollector coll)
Multicast a message request to all members in dests and receive responses via the RspCollector interface. When done receiving the required number of responses, the caller has to call done(req_id) on the underlyinh RequestCorrelator, so that the resources allocated to that request can be freed.

Parameters:
dests - The list of members from which to receive responses. Null means all members
req_id - The ID of the request. Used by the underlying RequestCorrelator to correlate responses with requests
msg - The request to be sent
coll - The sender needs to provide this interface to collect responses. Call will return immediately if this is null


castMessage

public RspList castMessage(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 the 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.


done

public void done(long req_id)


handle

public Object handle(Message msg)
Specified by:
handle in interface RequestHandler


send

public void send(Message msg)
            throws ChannelNotConnectedException,
                   ChannelClosedException


sendMessage

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


setConcurrentProcessing

public void setConcurrentProcessing(boolean flag)


setDeadlockDetection

public void setDeadlockDetection(boolean flag)


setMembershipListener

public void setMembershipListener(MembershipListener l)


setMessageListener

public void setMessageListener(MessageListener l)


setRequestHandler

public void setRequestHandler(RequestHandler rh)


start

public void start()


stop

public void stop()


Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.