JavaGroups.JavaStack
Class Protocol

java.lang.Object
  |
  +--JavaGroups.JavaStack.Protocol
Direct Known Subclasses:
DELAY, DISCARD, DUMMY, EXAMPLE, FD, FD_RAND, FRAG, HDRS, LOSS, MERGE, MessageDispatcher, MessageProtocol, NAKACK, PIGGYBACK, PING, PRINTMETHODS, PRINTOBJS, ProtocolStack, QUEUE, STATE_TRANSFER, TOTAL, TRACE, TUNNEL, UDP, UNICAST, UNIFORM, VIEW_ENFORCER

public abstract class Protocol
extends java.lang.Object

The Protocol class provides a set of common services for protocol layers. Each layer has to be a subclass of Protocol and override a number of methods (typically just 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 !


Constructor Summary
Protocol()
           
 
Method Summary
 void Down(Event evt)
          An event is to be sent down the stack.
 Protocol GetDownProtocol()
           
abstract  java.lang.String GetName()
           
 java.util.Properties GetProperties()
           
 Protocol GetUpProtocol()
           
 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.
 java.util.Vector ProvidedDownServices()
          List of events that are provided to layers below (they will be handled when sent down from below).
 java.util.Vector ProvidedUpServices()
          List of events that are provided to layers above (they will be handled when sent down from above).
 java.util.Vector RequiredDownServices()
          List of events that are required to be answered by some layer below.
 java.util.Vector RequiredUpServices()
          List of events that are required to be answered by some layer above.
 void Reset()
          Used when new member joins (new stack needs to start from a defined point), typically just resetting its state.
 void SetDownProtocol(Protocol down_prot)
           
 boolean SetProperties(java.util.Properties props)
          Configures the protocol initially.
 void SetProtocolStack(ProtocolStack stack)
           
 void SetUpProtocol(Protocol up_prot)
           
 void StartDownHandler()
          Used internally.
 void StartUpHandler()
          Used internally.
 void StopInternal()
          Used internally.
 void Up(Event evt)
          An event was received from the layer below.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Protocol

public Protocol()
Method Detail

SetProperties

public boolean SetProperties(java.util.Properties props)
Configures the protocol initially. A configuration string consists of name=value items, separated by a ';' (semicolon), e.g.:
 "loopback=false;unicast_inport=4444"
 

GetProperties

public java.util.Properties GetProperties()

RequiredUpServices

public java.util.Vector RequiredUpServices()
List of events that are required to be answered by some layer above.
Returns:
Vector (of Integers)

RequiredDownServices

public java.util.Vector RequiredDownServices()
List of events that are required to be answered by some layer below.
Returns:
Vector (of Integers)

ProvidedUpServices

public java.util.Vector ProvidedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above).
Returns:
Vector (of Integers)

ProvidedDownServices

public java.util.Vector ProvidedDownServices()
List of events that are provided to layers below (they will be handled when sent down from below).
Returns:
Vector (of Integers)

GetName

public abstract java.lang.String GetName()

GetUpProtocol

public Protocol GetUpProtocol()

GetDownProtocol

public Protocol GetDownProtocol()

SetUpProtocol

public void SetUpProtocol(Protocol up_prot)

SetDownProtocol

public void SetDownProtocol(Protocol down_prot)

SetProtocolStack

public void SetProtocolStack(ProtocolStack stack)

StartUpHandler

public void StartUpHandler()
Used internally. If overridden, call parent's method first

StartDownHandler

public void StartDownHandler()
Used internally. If overridden, call parent's method first

StopInternal

public void StopInternal()
Used internally. If overridden, call parent's method first

Reset

public void Reset()
Used when new member joins (new stack needs to start from a defined point), typically just resetting its state. For example, a sliding window protocol used for negative acknowledgement would reset its lower mark to 0 again.

PassUp

public void PassUp(Event evt)
Causes the event to be forwarded to the next layer up in the hierarchy. Typically called by the implementation of Up (when done).

PassDown

public 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).

Up

public void Up(Event evt)
An event was received from the layer below. Usually the current layer will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally the event is either a) discarded, or b) an event is sent down the stack using PassDown or c) the event (or another event) is sent up the stack using PassUp.

Down

public void Down(Event evt)
An event is to be sent down the stack. The layer may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the layer may need to add a header to it (or do nothing at all) before sending it down the stack using 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.