org.jgroups.stack
Class Protocol

java.lang.Object
  extended by org.jgroups.stack.Protocol
Direct Known Subclasses:
AUTH, BARRIER, BSH, COMPRESS, COUNTER, DAISYCHAIN, DELAY, DELAY_JOIN_REQ, DISCARD, DISCARD_PAYLOAD, Discovery, DUPL, ENCRYPT, EXAMPLE, Executing, FC, FD, FD_ALL, FD_SIMPLE, FD_SOCK, FlowControl, FLUSH, FORWARD_TO_COORD, FRAG, FRAG2, GMS, HDRS, HTOTAL, Locking, MERGE2, MERGE3, NAKACK, NAKACK2, PDC, PRIO, ProtocolStack, RATE_LIMITER, RELAY, RELAY2, RSVP, SCOPE, SEQUENCER, SHUFFLE, SIZE, STABLE, STATE_TRANSFER, STATS, STOMP, StreamingStateTransfer, SUPERVISOR, TOA, TP, TP.ProtocolAdapter, TRACE, UNICAST, UNICAST2, VERIFY_SUSPECT

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.

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 !

Author:
Bela Ban

Field Summary
protected  Protocol down_prot
           
protected  boolean ergonomics
           
protected  short id
           
protected  Log log
           
protected  java.lang.String name
          The name of the protocol.
protected  ProtocolStack stack
           
protected  boolean stats
           
protected  Protocol up_prot
           
 
Constructor Summary
Protocol()
           
 
Method Summary
 void destroy()
          This method is called on a Channel.close().
 java.lang.Object down(Event evt)
          An event is to be sent down the stack.
 java.util.Map<java.lang.String,java.lang.Object> dumpStats()
           
 void enableStats(boolean flag)
           
protected  java.util.List<java.lang.Object> getConfigurableObjects()
          After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional objects which need to be configured.
 Protocol getDownProtocol()
           
 java.util.List<java.lang.Integer> getDownServices()
          Returns all services provided by protocols below the current protocol
 short getId()
           
 short[] getIdsAbove()
          Returns the protocol IDs of all protocols above this one (excluding the current protocol)
 java.lang.String getLevel()
           
 java.lang.String getName()
           
 ProtocolStack getProtocolStack()
           
 SocketFactory getSocketFactory()
          Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down
 ThreadFactory getThreadFactory()
          Supposed to be overwritten by subclasses.
protected  TP getTransport()
           
 Protocol getUpProtocol()
           
 java.util.List<java.lang.Integer> getUpServices()
          Returns all services provided by the protocols above the current protocol
 java.lang.Object getValue(java.lang.String name)
           
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 boolean isErgonomics()
           
 java.lang.String printStats()
           
 java.util.List<java.lang.Integer> providedDownServices()
          List of events that are provided to layers below (they will be handled when sent down below)
 java.util.List<java.lang.Integer> providedUpServices()
          List of events that are provided to layers above (they will be handled when sent down from above)
 java.util.List<java.lang.Integer> requiredDownServices()
          List of events that are required to be answered by some layer below
 java.util.List<java.lang.Integer> requiredUpServices()
          List of events that are required to be answered by some layer above
 void resetStatistics()
           
 void resetStats()
           
 void setDownProtocol(Protocol prot)
           
 void setErgonomics(boolean ergonomics)
           
 void setId(short id)
           
 void setLevel(java.lang.String level)
          Sets the level of a logger.
 void setProtocolStack(ProtocolStack s)
           
 void setSocketFactory(SocketFactory factory)
          Sets a SocketFactory.
 void setUpProtocol(Protocol prot)
           
 Protocol setValue(java.lang.String name, java.lang.Object value)
           
 Protocol setValues(java.util.Map<java.lang.String,java.lang.Object> values)
           
 void start()
          This method is called on a Channel.connect(String).
 boolean statsEnabled()
           
 void stop()
          This method is called on a Channel.disconnect().
 java.lang.Object up(Event evt)
          An event was received from the layer below.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

up_prot

protected Protocol up_prot

down_prot

protected Protocol down_prot

stack

protected ProtocolStack stack

stats

protected boolean stats

ergonomics

protected boolean ergonomics

name

protected java.lang.String name
The name of the protocol. Is by default set to the protocol's classname. This property should rarely need to be set, e.g. only in cases where we want to create more than 1 protocol of the same class in the same stack


id

protected short id

log

protected final Log log
Constructor Detail

Protocol

public Protocol()
Method Detail

setLevel

public void setLevel(java.lang.String level)
Sets the level of a logger. This method is used to dynamically change the logging level of a running system, e.g. via JMX. The appender of a level needs to exist.

Parameters:
level - The new level. Valid values are "fatal", "error", "warn", "info", "debug", "trace" (capitalization not relevant)

getLevel

public java.lang.String getLevel()

isErgonomics

public boolean isErgonomics()

setErgonomics

public void setErgonomics(boolean ergonomics)

getProtocolStack

public ProtocolStack getProtocolStack()

statsEnabled

public boolean statsEnabled()

enableStats

public void enableStats(boolean flag)

getName

public java.lang.String getName()

getId

public short getId()

setId

public void setId(short id)

getUpProtocol

public Protocol getUpProtocol()

getDownProtocol

public Protocol getDownProtocol()

setUpProtocol

public void setUpProtocol(Protocol prot)

setDownProtocol

public void setDownProtocol(Protocol prot)

setProtocolStack

public void setProtocolStack(ProtocolStack s)

getValue

public java.lang.Object getValue(java.lang.String name)

setValues

public Protocol setValues(java.util.Map<java.lang.String,java.lang.Object> values)

setValue

public Protocol setValue(java.lang.String name,
                         java.lang.Object value)

getConfigurableObjects

protected java.util.List<java.lang.Object> getConfigurableObjects()
After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional objects which need to be configured. This callback allows a protocol developer to configure those other objects. This call is guaranteed to be invoked after the protocol itself has been configured. See AUTH for an example.

Returns:

getIdsAbove

public short[] getIdsAbove()
Returns the protocol IDs of all protocols above this one (excluding the current protocol)


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:

getSocketFactory

public SocketFactory getSocketFactory()
Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down

Returns:
SocketFactory

setSocketFactory

public void setSocketFactory(SocketFactory factory)
Sets a SocketFactory. Socket factories are typically provided by the transport (TP) or TP.ProtocolAdapter

Parameters:
factory -

resetStatistics

public void resetStatistics()

resetStats

public void resetStats()

printStats

public java.lang.String printStats()

dumpStats

public java.util.Map<java.lang.String,java.lang.Object> dumpStats()

init

public void init()
          throws java.lang.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:
java.lang.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 java.lang.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:
java.lang.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 java.util.List<java.lang.Integer> requiredUpServices()
List of events that are required to be answered by some layer above


requiredDownServices

public java.util.List<java.lang.Integer> requiredDownServices()
List of events that are required to be answered by some layer below


providedUpServices

public java.util.List<java.lang.Integer> providedUpServices()
List of events that are provided to layers above (they will be handled when sent down from above)


providedDownServices

public java.util.List<java.lang.Integer> providedDownServices()
List of events that are provided to layers below (they will be handled when sent down below)


getDownServices

public final java.util.List<java.lang.Integer> getDownServices()
Returns all services provided by protocols below the current protocol


getUpServices

public final java.util.List<java.lang.Integer> getUpServices()
Returns all services provided by the protocols above the current protocol


up

public java.lang.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 java.lang.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().



Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.