org.javagroups.stack
Class MessageProtocol

java.lang.Object
  |
  +--org.javagroups.stack.Protocol
        |
        +--org.javagroups.stack.MessageProtocol
All Implemented Interfaces:
RequestHandler
Direct Known Subclasses:
MessageProtocolEXAMPLE, RpcProtocol

public abstract class MessageProtocol
extends Protocol
implements RequestHandler

Based on Protocol, but incorporates RequestCorrelator and GroupRequest: the latter can be used to mcast messages to all members and receive their reponses.

A protocol based on this template can send messages to all members and receive all, a single, n, or none responses. Requests directed towards the protocol can be handled by overriding method Handle.

Requests and responses are in the form of Messages, which would typically need to contain information pertaining to the request/response, e.g. in the form of objects contained in the message. To use remote method calls, use RpcProtocol instead.

Typical use of of a MessageProtocol would be when a protocol needs to interact with its peer protocols at each of the members' protocol stacks. A simple protocol like fragmentation, which does not need to interact with other instances of fragmentation, may simply subclass Protocol instead.

Author:
Bela Ban

Field Summary
protected  RequestCorrelator _corr
           
protected  java.util.Vector members
           
 
Fields inherited from class org.javagroups.stack.Protocol
down_handler, down_prot, down_queue, down_thread, observer, props, stack, up_handler, up_prot, up_queue, up_thread
 
Constructor Summary
MessageProtocol()
           
 
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)
          This message is not originated by this layer, therefore we can just pass it down without having to go through the request correlator.
 java.lang.Object handle(Message req)
          Processes a request destined for this layer.
protected  boolean handleDownEvent(Event evt)
          Handle down event.
protected  boolean handleUpEvent(Event evt)
          Handle up event.
 java.lang.Object sendMessage(Message msg, int mode, long timeout)
          Sends a message to a single member (destination = msg.dest) and returns the response.
protected  void start()
           
protected  void stop()
           
 void up(Event evt)
          Handle an event coming from the layer above
protected  void updateView(View new_view)
           
 
Methods inherited from class org.javagroups.stack.Protocol
getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, init, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setUpProtocol, startDownHandler, startUpHandler, stopInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_corr

protected RequestCorrelator _corr

members

protected java.util.Vector members
Constructor Detail

MessageProtocol

public MessageProtocol()
Method Detail

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 from which responses are expected. If it is null, replies from all members are expected. The request itself is multicast 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 TimeoutException,
                                    SuspectedException
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 req)
Processes a request destined for this layer. The return value is sent as response.
Specified by:
handle in interface RequestHandler

up

public final void up(Event evt)
Handle an event coming from the layer above
Overrides:
up in class Protocol

down

public final void down(Event evt)
This message is not originated by this layer, therefore we can just pass it down without having to go through the request correlator. We do this ONLY for messages !
Overrides:
down in class Protocol

updateView

protected void updateView(View new_view)

handleUpEvent

protected boolean handleUpEvent(Event evt)
Handle up event. Return false if it should not be passed up the stack.

handleDownEvent

protected boolean handleDownEvent(Event evt)
Handle down event. Return false if it should not be passed down the stack.

start

protected void start()

stop

protected void stop()


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.