Class Protocol

java.lang.Object
org.jgroups.stack.Protocol
Direct Known Subclasses:
AUTH, AUTOCONF, BARRIER, BSH, CAUSAL, COMPRESS, DELAY, DELAY_JOIN_REQ, DISCARD, DISCARD_PAYLOAD, Discovery, DUMMY_TP, DUPL, ENCRYPT, EXAMPLE, FC, FD, FD_ALL, FD_SIMPLE, FD_SOCK, FLUSH, FRAG, FRAG2, GMS, HDRS, HTOTAL, JMS, MERGE2, MERGE3, MERGEFAST, NAKACK, PARTITION, PERF_TP, ProtocolStack, SEQUENCER, SFC, SHUFFLE, SIZE, SMACK, STABLE, STATE_TRANSFER, STATS, STREAMING_STATE_TRANSFER, TP, TP.ProtocolAdapter, TRACE, UNICAST, VERIFY_SUSPECT, VIEW_SYNC

public abstract class Protocol extends 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.

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 !

Version:
$Id: Protocol.java,v 1.54.2.1 2008/05/22 13:23:04 belaban Exp $
Author:
Bela Ban
  • Field Details

    • props

      protected final Properties props
    • up_prot

      protected Protocol up_prot
    • down_prot

      protected Protocol down_prot
    • stack

      protected ProtocolStack stack
    • stats

      protected boolean stats
    • log

      protected final org.apache.commons.logging.Log log
  • Constructor Details

    • Protocol

      public Protocol()
  • Method Details

    • setProperties

      public boolean setProperties(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"
       
    • setPropertiesInternal

      public boolean setPropertiesInternal(Properties props)
      Called by Configurator. Removes 2 properties which are used by the Protocol directly and then calls setProperties(), which might invoke the setProperties() method of the actual protocol instance.
    • getProperties

      public Properties getProperties()
    • getProtocolStack

      public ProtocolStack getProtocolStack()
    • getTransport

      protected TP getTransport()
    • getThreadFactory

      public ThreadFactory getThreadFactory()
      Supposed to be overwritten by subclasses. Usually the transport returns a valid non-null thread factory, but thread factories can also be created by individual protocols
      Returns:
    • upThreadEnabled

      public boolean upThreadEnabled()
      Deprecated.
      up_thread was removed
      Returns:
      false by default
    • downThreadEnabled

      public boolean downThreadEnabled()
      Deprecated.
      down thread was removed
      Returns:
      boolean False by default
    • statsEnabled

      public boolean statsEnabled()
    • enableStats

      public void enableStats(boolean flag)
    • resetStats

      public void resetStats()
    • printStats

      public String printStats()
    • dumpStats

      public Map<String,Object> dumpStats()
    • init

      public void init() throws Exception
      Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
    • start

      public void start() throws Exception
      This method is called on a 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.
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so Channel.connect(String) will throw an exception
    • stop

      public void stop()
      This method is called on a 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 flushed
    • destroy

      public void destroy()
      This method is called on a Channel.close(). Does some cleanup; after the call the VM will terminate
    • requiredUpServices

      public Vector<Integer> requiredUpServices()
      List of events that are required to be answered by some layer above.
      Returns:
      Vector (of Integers)
    • requiredDownServices

      public Vector<Integer> requiredDownServices()
      List of events that are required to be answered by some layer below.
      Returns:
      Vector (of Integers)
    • providedUpServices

      public Vector<Integer> 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 Vector<Integer> providedDownServices()
      List of events that are provided to layers below (they will be handled when sent down from below).
      Returns:
      Vectorinvalid input: '<'Integer (of Integers)
    • getName

      public abstract 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)
    • up

      public Object 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 down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
    • down

      public Object 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 down_prot.down(). 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 up_prot.up().