All protocols inherit indirectly or directly from JavaGroups.JavaStack.Protocol. A Protocol defines the default behavior for all protocol layers, it for example sets up the incoming and outgoing queues, creates the two threads that pass messages between queues and maintains a reference to the layer above and below the current layer. All behavior can be overridden in subclasses, it is for example possible to write a protocol layer that does not use threads and queues altogether. The innards of a Protocol layer are shown in fig. 4.2.
Each protocol contains the following variables:
The processing for the down_handler is the same, except that messages travel down the stack. The 2 threads are started and stopped by methods StartInternal and StopInternal, which are called by the Configurator (see 4.1.5) when a stack is created and destroyed.
By overriding methods StartInternal and StopInternal, subclasses can govern the creation of the 2 threads: if both methods are empty, then no threads will be created, and the ReceiveUpEvent / ReceiveDownEvent methods will have to call Up / Down directly.
The default mechanism guarantees that messages are received in FIFO order, and that at most 1 down and 1 up message is handled in a protocol layer at the same time. Therefore, a message Q passed down the stack after P will never 'pass' P, i.e. if any layer receives both P and Q, then P will always be received before Q (unless a layer discards either or bother of the two messages).
There are 2 subclasses of Protocol: MessageProtocol (cf. 4.3.1) and RpcProtocol (cf. 4.3.2): whereas both enable peer communication between layers of different JChannel protocol stack instances, the former uses (synchronous) message passing to do so, while the latter employs (synchronous) remote method invocation.