org.jgroups.stack

Class ProtocolStack

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

Author:
Bela Ban

Field Summary

static int
ABOVE
static int
BELOW
TimeScheduler
timer

Fields inherited from class org.jgroups.stack.Protocol

down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, up_handler, up_prot, up_queue, up_thread, up_thread_prio

Constructor Summary

ProtocolStack(JChannel channel, String setup_string)

Method Summary

Protocol
createProtocol(String prot_spec)
Creates a new protocol given the protocol specification.
void
destroy()
void
down(Event evt)
Protocol
findProtocol(String name)
Returns a given protocol or null if not found
void
flushEvents()
Flushes all events currently in the down queues and returns when done.
String
getName()
Vector
getProtocols()
Returns all protocols in a list, from top to bottom.
void
insertProtocol(Protocol prot, int position, String neighbor_prot)
Inserts an already created (and initialized) protocol into the protocol list.
String
printProtocolSpec(boolean include_properties)
Prints the names of the protocols, from the bottom to top.
Object
receive(long timeout)
protected void
receiveUpEvent(Event evt)
void
removeProtocol(String prot_name)
Removes a protocol from the stack.
void
send(Message msg)
void
setup()
void
startDownHandler()
void
startStack()
Start all layers.
void
startUpHandler()
void
startWork()
Override with null functionality: we don't need any threads to be started !
void
stopInternal()
void
stopStack()
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
void
stopWork()
Override with null functionality: we don't need any threads to be started !
void
up(Event evt)

Methods inherited from class org.jgroups.stack.Protocol

destroy, down, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setUpProtocol, start, startDownHandler, startUpHandler, stop, stopInternal, up

Field Details

ABOVE

public static final int ABOVE
Field Value:
1

BELOW

public static final int BELOW
Field Value:
2

timer

public TimeScheduler timer

Constructor Details

ProtocolStack

public ProtocolStack(JChannel channel,
                     String setup_string)

Method Details

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

destroy

public void destroy()
Overrides:
destroy in interface Protocol

down

public void down(Event evt)
Overrides:
down in interface Protocol

findProtocol

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

flushEvents

public void flushEvents()
Flushes all events currently in the down queues and returns when done. This guarantees that all events sent before this call will have been handled.

getName

public String getName()
Overrides:
getName in interface Protocol

getProtocols

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

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

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.

receive

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

receiveUpEvent

protected void receiveUpEvent(Event evt)
Overrides:
receiveUpEvent in interface Protocol

removeProtocol

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

send

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

setup

public void setup()
            throws Exception

startDownHandler

public void startDownHandler()
Overrides:
startDownHandler in interface Protocol

startStack

public void startStack()
            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

startUpHandler

public void startUpHandler()
Overrides:
startUpHandler in interface Protocol

startWork

public void startWork()
Override with null functionality: we don't need any threads to be started !

stopInternal

public void stopInternal()
Overrides:
stopInternal in interface Protocol

stopStack

public void stopStack()
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

stopWork

public void stopWork()
Override with null functionality: we don't need any threads to be started !

up

public void up(Event evt)
Overrides:
up in interface Protocol

Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.