Class ProtocolStack

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.stack.ProtocolStack
All Implemented Interfaces:
Transport

public class ProtocolStack extends Protocol implements Transport
A ProtocolStack manages a number of protocols layered above each other. It creates all protocol classes, initializes them and, when ready, starts all of them, beginning with the bottom most protocol. It also dispatches messages received from the stack to registered objects (e.g. channel, GMP) and sends messages sent by those objects down the stack.

The ProtocolStack makes use of the Configurator to setup and initialize stacks, and to destroy them again when not needed anymore

Version:
$Id: ProtocolStack.java,v 1.59.2.9.2.1 2009/03/31 16:34:13 belaban Exp $
Author:
Bela Ban
  • Field Details

  • Constructor Details

  • Method Details

    • getThreadFactory

      public ThreadFactory getThreadFactory()
      Deprecated.
      Description copied from class: Protocol
      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
      Overrides:
      getThreadFactory in class Protocol
      Returns:
    • getTimerThreadFactory

      @Deprecated public static ThreadFactory getTimerThreadFactory()
      Deprecated.
    • setThreadFactory

      public void setThreadFactory(ThreadFactory f)
      Deprecated.
      Parameters:
      f -
    • setTimerThreadFactory

      public static void setTimerThreadFactory(ThreadFactory f)
      Parameters:
      f -
    • getLocks

      public Map<Thread,ReentrantLock> getLocks()
    • getChannel

      public Channel getChannel()
    • getTimerThreads

      public int getTimerThreads()
      Deprecated.
      Use TP.getTimer() to fetch the timer and call getCorePoolSize() directly
      Returns:
    • getProtocols

      public Vector<Protocol> getProtocols()
      Returns all protocols in a list, from top to bottom. These are not copies of protocols, so modifications will affect the actual instances !
    • getTransport

      public TP getTransport()
      Returns the bottom most protocol
      Overrides:
      getTransport in class Protocol
    • getSingletonTransports

      public static ConcurrentMap<String,Tuple<TP,Short>> getSingletonTransports()
    • dumpStats

      public Map<String,Object> dumpStats()
      Overrides:
      dumpStats in class Protocol
      Returns:
      Mapinvalid input: '<'String,Mapinvalid input: '<'key,val>>
    • dumpStats

      public Map<String,Object> dumpStats(String protocol_name)
    • dumpTimerQueue

      public String dumpTimerQueue()
      Deprecated.
      Use TP.getTimer() instead to fetch the timer from the transport and then invoke the method on it
      Returns:
    • printProtocolSpec

      public String printProtocolSpec(boolean include_properties)
      Prints the names of the protocols, from the bottom to top. If include_properties is true, the properties for each protocol will also be printed.
    • printProtocolSpecAsXML

      public String printProtocolSpecAsXML()
    • printProtocolSpecAsPlainString

      public String printProtocolSpecAsPlainString()
    • setup

      public void setup() throws Exception
      Throws:
      Exception
    • createProtocol

      public Protocol createProtocol(String prot_spec) throws Exception
      Creates a new protocol given the protocol specification.
      Parameters:
      prot_spec - The specification of the protocol. Same convention as for specifying a protocol stack. An exception will be thrown if the class cannot be created. Example:
      "VERIFY_SUSPECT(timeout=1500)"
      Note that no colons (:) have to be specified
      Returns:
      Protocol The newly created protocol
      Throws:
      Exception - Will be thrown when the new protocol cannot be created
    • insertProtocol

      public void insertProtocol(Protocol prot, int position, String neighbor_prot) throws Exception
      Inserts an already created (and initialized) protocol into the protocol list. Sets the links to the protocols above and below correctly and adjusts the linked list of protocols accordingly. Note that this method may change the value of top_prot or bottom_prot.
      Parameters:
      prot - The protocol to be inserted. Before insertion, a sanity check will ensure that none of the existing protocols have the same name as the new protocol.
      position - Where to place the protocol with respect to the neighbor_prot (ABOVE, BELOW)
      neighbor_prot - The name of the neighbor protocol. An exception will be thrown if this name is not found
      Throws:
      Exception - Will be thrown when the new protocol cannot be created, or inserted.
    • insertProtocol

      public void insertProtocol(Protocol prot, int position, Class<? extends Protocol> neighbor_prot) throws Exception
      Throws:
      Exception
    • insertProtocol

      public void insertProtocol(Protocol prot, int position, Protocol neighbor_prot) throws Exception
      Throws:
      Exception
    • removeProtocol

      public Protocol removeProtocol(String prot_name) throws Exception
      Removes a protocol from the stack. Stops the protocol and readjusts the linked lists of protocols.
      Parameters:
      prot_name - The name of the protocol. Since all protocol names in a stack have to be unique (otherwise the stack won't be created), the name refers to just 1 protocol.
      Throws:
      Exception - Thrown if the protocol cannot be stopped correctly.
    • findProtocol

      public Protocol findProtocol(String name)
      Returns a given protocol or null if not found
    • findProtocol

      public Protocol findProtocol(Class<?> clazz)
    • destroy

      public void destroy()
      Description copied from class: Protocol
      This method is called on a Channel.close(). Does some cleanup; after the call the VM will terminate
      Overrides:
      destroy in class Protocol
    • startStack

      public void startStack(String cluster_name) throws Exception
      Start all layers. The Protocol.start() method is called in each protocol, from top to bottom. Each layer can perform some initialization, e.g. create a multicast socket
      Throws:
      Exception
    • stopStack

      public void stopStack(String cluster_name)
      Iterates through all the protocols from top to bottom and does the following:
      1. Waits until all messages in the down queue have been flushed (ie., size is 0)
      2. Calls stop() on the protocol
    • flushEvents

      public void flushEvents()
      Deprecated.
      Not needed anymore, just left in here for backwards compatibility with JBoss AS
    • send

      public void send(Message msg) throws Exception
      Specified by:
      send in interface Transport
      Throws:
      Exception
    • receive

      public Object receive(long timeout) throws Exception
      Specified by:
      receive in interface Transport
      Throws:
      Exception
    • getName

      public String getName()
      Specified by:
      getName in class Protocol
    • up

      public Object up(Event evt)
      Description copied from class: Protocol
      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().
      Overrides:
      up in class Protocol
    • down

      public Object down(Event evt)
      Description copied from class: Protocol
      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().
      Overrides:
      down in class Protocol