public abstract class MessageProtocol extends Protocol implements RequestHandler
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 Message
s, 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.
Modifier and Type | Field and Description |
---|---|
protected RequestCorrelator |
_corr |
protected java.util.Vector |
members |
down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, stats, up_handler, up_prot, up_queue, up_thread, up_thread_prio
Constructor and Description |
---|
MessageProtocol() |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
start()
This method is called on a
Channel.connect(String) . |
void |
stop()
This method is called on a
Channel.disconnect() . |
void |
up(Event evt)
Handle an event coming from the layer above
|
protected void |
updateView(View new_view) |
destroy, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, passDown, passUp, printStats, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, resetStats, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setUpProtocol, startDownHandler, startUpHandler, statsEnabled, stopInternal, upThreadEnabled
protected RequestCorrelator _corr
protected final java.util.Vector members
public void start() throws java.lang.Exception
Protocol
Channel.connect(String)
. Starts work.
Protocols are connected and queues are ready to receive events.
Will be called from bottom to top. This call will replace
the START and START_OK events.start
in class Protocol
java.lang.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack
to fail, so Channel.connect(String)
will throw an exceptionpublic void stop()
Protocol
Channel.disconnect()
. Stops work (e.g. by closing multicast socket).
Will be called from top to bottom. This means that at the time of the method invocation the
neighbor protocol below is still working. This method will replace the
STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that
when this method is called all messages in the down queue will have been flushedpublic RspList castMessage(java.util.Vector dests, Message msg, int mode, long timeout)
mode
responses. The responses are
returned in a response list, where each response is associated with its sender.
Uses GroupRequest
.
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 membersmode
- Defined in GroupRequest
. The number of responses to wait for:
timeout
- If 0: wait forever. Otherwise, wait for mode
responses
or timeout time.Object
and associated
to its sender.public java.lang.Object sendMessage(Message msg, int mode, long timeout) throws TimeoutException, SuspectedException
TimeoutException
SuspectedException
public java.lang.Object handle(Message req)
handle
in interface RequestHandler
public final void up(Event evt)
public final void down(Event evt)
protected void updateView(View new_view)
protected boolean handleUpEvent(Event evt)
protected boolean handleDownEvent(Event evt)
Copyright ? 1998-2006 Bela Ban. All Rights Reserved.