Package org.jgroups.stack
Class Protocol
java.lang.Object
org.jgroups.stack.Protocol
- Direct Known Subclasses:
AUTH,BARRIER,BSH,COMPRESS,DAISYCHAIN,DELAY,DELAY_JOIN_REQ,DISCARD,DISCARD_PAYLOAD,Discovery,DUPL,ENCRYPT,EXAMPLE,Executing,FC,FD,FD_ALL,FD_SIMPLE,FD_SOCK,FlowControl,FLUSH,FRAG,FRAG2,GMS,HDRS,HTOTAL,Locking,MERGE2,MERGE3,MERGEFAST,NAKACK,PERF_TP,PRIO,ProtocolStack,RATE_LIMITER,RELAY,SCOPE,SEQUENCER,SFC,SHUFFLE,SIZE,SMACK,STABLE,STATE_TRANSFER,STATS,STOMP,STREAMING_STATE_TRANSFER,TP,TP.ProtocolAdapter,TRACE,UNICAST,UNICAST2,VERIFY_SUSPECT,VIEW_SYNC
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()This method is called on aChannel.close().An event is to be sent down the stack.booleanDeprecated.down thread was removedvoidenableStats(boolean flag) After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional objects which need to be configured.shortgetId()getLevel()getName()All protocol names have to be unique !Deprecated.Use a getter to get the actual instance variableReturns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call downSupposed to be overwritten by subclasses.protected TPvoidinit()Called after instance has been created (null constructor) and before protocol is started.booleanList of events that are provided to layers below (they will be handled when sent down from below).List of events that are provided to layers above (they will be handled when sent down from above).List of events that are required to be answered by some layer below.List of events that are required to be answered by some layer above.voidvoidsetDownProtocol(Protocol down_prot) voidsetErgonomics(boolean ergonomics) voidsetId(short id) voidSets the level of a logger.protected booleansetProperties(Properties props) Deprecated.The properties are now set through the @Property annotation on the attribute or setterbooleansetPropertiesInternal(Properties props) Deprecated.Use a setter insteadvoidsetProperty(String key, String val) Deprecated.Use the corresponding setter insteadvoidsetProtocolStack(ProtocolStack stack) voidsetSocketFactory(SocketFactory factory) Sets a SocketFactory.voidsetUpProtocol(Protocol up_prot) voidstart()This method is called on aChannel.connect(String).booleanvoidstop()This method is called on aChannel.disconnect().An event was received from the layer below.booleanDeprecated.up_thread was removed
-
Field Details
-
up_prot
-
down_prot
-
stack
-
stats
protected boolean stats -
ergonomics
protected boolean ergonomics -
name
Deprecated.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
-
-
Constructor Details
-
Protocol
public Protocol()
-
-
Method Details
-
setLevel
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
-
isErgonomics
public boolean isErgonomics() -
setErgonomics
public void setErgonomics(boolean ergonomics) -
setProperties
Deprecated.The properties are now set through the @Property annotation on the attribute or setterConfigures the protocol initially. A configuration string consists of name=value items, separated by a ';' (semicolon), e.g.:"loopback=false;unicast_inport=4444"
-
setProperty
Deprecated.Use the corresponding setter insteadSets a property- Parameters:
key-val-
-
setPropertiesInternal
Deprecated.Use a setter insteadCalled 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. -
getValue
-
setValues
-
setValue
-
getProperties
Deprecated.Use a getter to get the actual instance variable- Returns:
-
getProtocolStack
-
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:
-
getTransport
-
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
Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call down- Returns:
- SocketFactory
-
setSocketFactory
Sets a SocketFactory. Socket factories are typically provided by the transport (TP) orTP.ProtocolAdapter- Parameters:
factory-
-
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
-
dumpStats
-
init
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
This method is called on aChannel.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, soChannel.connect(String)will throw an exception
-
stop
public void stop()This method is called on aChannel.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 aChannel.close(). Does some cleanup; after the call the VM will terminate -
requiredUpServices
List of events that are required to be answered by some layer above.- Returns:
- Vector (of Integers)
-
requiredDownServices
List of events that are required to be answered by some layer below.- Returns:
- Vector (of Integers)
-
providedUpServices
List of events that are provided to layers above (they will be handled when sent down from above).- Returns:
- Vector (of Integers)
-
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
All protocol names have to be unique ! -
getId
public short getId() -
setId
public void setId(short id) -
getUpProtocol
-
getDownProtocol
-
setUpProtocol
-
setDownProtocol
-
setProtocolStack
-
up
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 usingdown_prot.down()or c) the event (or another event) is sent up the stack usingup_prot.up(). -
down
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 usingdown_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 usingup_prot.up().
-