org.jgroups.stack
public abstract class Protocol extends Object
up()
,
Down
and getName
. Layers are stacked in a certain order to form
a protocol stack. Events are passed from lower
layers to upper ones and vice versa. E.g. a Message received by the UDP layer at the bottom
will be passed to its higher layer as an Event. That layer will in turn pass the Event to
its layer and so on, until a layer handles the Message and sends a response or discards it,
the former resulting in another Event being passed down the stack.
Each layer has 2 FIFO queues, one for up Events and one for down Events. When an Event is
received by a layer (calling the internal upcall ReceiveUpEvent
), it is placed
in the up-queue where it will be retrieved by the up-handler thread which will invoke method
Up
of the layer. The same applies for Events traveling down the stack. Handling
of the up-handler and down-handler threads and the 2 FIFO queues is donw by the Protocol
class, subclasses will almost never have to override this behavior.
The important thing to bear in mind is that Events have to passed on between layers in FIFO order which is guaranteed by the Protocol implementation and must be guranteed by subclasses implementing their on Event queuing.
Note that each class implementing interface Protocol MUST provide an empty, public constructor !
Field Summary | |
---|---|
protected DownHandler | down_handler |
protected Protocol | down_prot |
protected Queue | down_queue |
protected boolean | down_thread |
protected int | down_thread_prio |
protected Log | log |
protected ProtocolObserver | observer |
protected Properties | props |
protected ProtocolStack | stack |
protected boolean | stats |
protected boolean | trace |
protected UpHandler | up_handler |
protected Protocol | up_prot |
protected Queue | up_queue |
protected boolean | up_thread |
protected int | up_thread_prio |
protected boolean | warn |
Method Summary | |
---|---|
void | destroy()
This method is called on a close.
|
void | down(Event evt)
An event is to be sent down the stack. |
boolean | downThreadEnabled() |
Map | dumpStats() |
void | enableStats(boolean flag) |
Protocol | getDownProtocol() |
Queue | getDownQueue() |
abstract String | getName() |
Properties | getProperties() |
Protocol | getUpProtocol() |
Queue | getUpQueue() |
protected boolean | handleSpecialDownEvent(Event evt) These are special internal events that should not be handled by protocols |
void | init()
Called after instance has been created (null constructor) and before protocol is started.
|
boolean | isTrace() |
boolean | isWarn() |
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)
Causes the event to be forwarded to the next layer up in the hierarchy. |
String | printStats() |
Vector | providedDownServices() List of events that are provided to layers below (they will be handled when sent down from
below). |
Vector | providedUpServices() List of events that are provided to layers above (they will be handled when sent down from
above). |
protected void | receiveDownEvent(Event evt)
Internal method, should not be called by clients. |
protected void | receiveUpEvent(Event evt)
Internal method, should not be called by clients. |
Vector | requiredDownServices() List of events that are required to be answered by some layer below. |
Vector | requiredUpServices() List of events that are required to be answered by some layer above. |
void | resetStats() |
void | setDownProtocol(Protocol down_prot) |
void | setObserver(ProtocolObserver observer) |
boolean | setProperties(Properties props)
Configures the protocol initially. |
boolean | setPropertiesInternal(Properties props) Called by Configurator. |
void | setProtocolStack(ProtocolStack stack) |
void | setTrace(boolean trace) |
void | setUpProtocol(Protocol up_prot) |
void | setWarn(boolean warn) |
void | start()
This method is called on a connect. |
void | startDownHandler() Used internally. |
void | startUpHandler() Used internally. |
boolean | statsEnabled() |
void | stop()
This method is called on a disconnect. |
void | stopInternal() Used internally. |
void | up(Event evt)
An event was received from the layer below. |
boolean | upThreadEnabled() |
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()
.Returns: boolean True: the event should be passed further down the stack. False: the event should be discarded (not passed down the stack)
Throws: Exception Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
Down
(when done).Up
(when done).Returns: Vector (of Integers)
Returns: Vector (of Integers)
Returns: Vector (of Integers)
Returns: Vector (of Integers)
"loopback=false;unicast_inport=4444"
Throws: Exception Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so connect will throw an exception
passDown()
or c) the event (or another event) is sent up
the stack using passUp()
.