Class Protocol
- All Implemented Interfaces:
Lifecycle
- Direct Known Subclasses:
AUTH,BARRIER,BATCH,BATCH2,CLEAR_FLAGS,COMPRESS,COUNTER,DAISYCHAIN,DELAY,DETECT_LOOPBACKS,DISCARD,DISCARD_PAYLOAD,Discovery,DROP,DUPL,Encrypt,EXAMPLE,FailureDetection,FD_HOST,FD_SOCK,FD_SOCK2,FlowControl,FLUSH,FORK,ForkProtocol,Fragmentation,GMS,HDRS,INJECT_VIEW,KeyExchange,Locking,MAKE_BATCH,MERGE3,MessageDispatcher.ProtocolAdapter,NAKACK2,NON_BLOCKING_SENDS,PDC,PERF,ProtocolStack,RATE,RATE_LIMITER,RATE_LIMITER2,RED,RELAY,REVERSE,RSVP,SEQUENCER,SEQUENCER2,SERIALIZE,SHUFFLE,SIZE,SNIFF,SOS,STABLE,STATE_TRANSFER,STATS,STOMP,StreamingStateTransfer,THREAD_COUNT,TIME,TP,TRACE,UNBATCH,UNICAST3,VERIFY_SUSPECT,VERIFY_SUSPECT2
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 be passed on between layers in FIFO order which is guaranteed by the Protocol implementation and must be guaranteed by subclasses implementing their on Event queuing.
Note that each class implementing interface Protocol MUST provide an empty, public constructor !
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanCalled by the default implementation ofup(org.jgroups.util.MessageBatch)for each message to determine if the message should be removed from the message batch (and handled by the current protocol) or not.<T extends Protocol>
Taddr()<T extends Protocol>
Tvoiddestroy()This method is called on aJChannel.close().An event is to be sent down the stack.A message is sent down the stack.Passes a message down asynchronously.voidenableStats(boolean flag) After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional component objects which need to be configured.<T extends Protocol>
TReturns all services provided by protocols below the current protocolshortgetId()short[]Returns the protocol IDs of all protocols above this one (excluding the current protocol)getLevel()getLog()getName()Returns the SocketFactory associated with this protocol, if overridden in a subclass, or passes the call downSupposed to be overwritten by subclasses.<T extends Protocol>
TReturns all services provided by the protocols above the current protocolvoidinit()Called after a protocol has been created and before the protocol is started.boolean<T extends Protocol>
TvoidCalled by the XML parser when subelements are found in the configuration of a protocol.policies()List of events that are provided to layers below (they will be handled when sent from down below)List of events that are provided to layers above (they will be handled when sent down from above)<T extends Protocol>
TList of events that are required to be answered by some layer belowList of events that are required to be answered by some layer abovevoidvoid<T extends Protocol>
TsetAddress(Address addr) <T extends Protocol>
TsetDownProtocol(Protocol prot) <T extends Protocol>
TsetErgonomics(boolean ergonomics) <T extends Protocol>
TsetId(short id) <T extends Protocol>
TSets the level of a logger.<T extends Protocol>
TsetPolicies(List<Policy> l) <T extends Protocol>
TvoidsetSocketFactory(SocketFactory factory) Sets a SocketFactory.<T extends Protocol>
TsetUpProtocol(Protocol prot) <T extends Protocol>
Tvoidstart()This method is called on aJChannel.connect(String); starts work.booleanvoidstop()Called on aJChannel.disconnect(); stops work (e.g.toString()An event was received from the protocol below.A single message was received.voidup(MessageBatch batch) Sends up a multiple messages in aMessageBatch.
-
Field Details
-
up_prot
-
down_prot
-
stack
-
stats
protected boolean stats -
ergonomics
protected boolean ergonomics -
after_creation_hook
-
id
protected short id -
local_addr
-
log
-
policies
-
-
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
-
level
-
getAddress
-
addr
-
addr
-
setAddress
-
isErgonomics
public boolean isErgonomics() -
setErgonomics
-
getProtocolStack
-
statsEnabled
public boolean statsEnabled() -
enableStats
public void enableStats(boolean flag) -
getName
-
getId
public short getId() -
setId
-
getUpProtocol
-
getDownProtocol
-
setUpProtocol
-
setDownProtocol
-
setProtocolStack
-
afterCreationHook
-
getLog
-
getPolicies
-
policies
-
setPolicies
-
addPolicy
-
removePolicy
-
getValue
-
setValue
-
getComponents
After configuring the protocol itself from the properties defined in the XML config, a protocol might have additional component 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.
-
parse
Called by the XML parser when subelements are found in the configuration of a protocol. This allows a protocol to define protocol-specific information and to parse it- Throws:
Exception
-
getIdsAbove
public short[] getIdsAbove()Returns the protocol IDs of all protocols above this one (excluding the current protocol) -
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)- Parameters:
factory-
-
resetStatistics
public void resetStatistics() -
resetStats
public void resetStats() -
init
Called after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent. -
start
This method is called on aJChannel.connect(String); starts work. Protocols are connected ready to receive events. Will be called from bottom to top.- Specified by:
startin interfaceLifecycle- Throws:
Exception- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soJChannel.connect(String)will throw an exception
-
stop
public void stop()Called on aJChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom. -
destroy
public void destroy()This method is called on aJChannel.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 -
requiredDownServices
List of events that are required to be answered by some layer below -
providedUpServices
List of events that are provided to layers above (they will be handled when sent down from above) -
providedDownServices
List of events that are provided to layers below (they will be handled when sent from down below) -
getDownServices
Returns all services provided by protocols below the current protocol -
getUpServices
Returns all services provided by the protocols above the current protocol -
down
An event is to be sent down the stack. A protocol 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 protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down(). -
down
A message is sent down the stack. Protocols may examine the message and do something (e.g. add a header) with it, before passing it down.- Since:
- 4.0
-
down
Passes a message down asynchronously. The sending is executed in the transport's thread pool. If the pool is full and the message is marked asMessage.TransientFlag.DONT_BLOCK, then it will be dropped, otherwise it will be sent on the caller's thread.- Parameters:
msg- The message to be sentasync- Whether to send the message asynchronously- Returns:
- A CompletableFuture of the result (or exception)
-
up
An event was received from the protocol below. Usually the current protocol 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(). -
up
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.- Since:
- 4.0
-
up
Sends up a multiple messages in aMessageBatch. The sender of the batch is always the same, and so is the destination (null == multicast messages). Messages in a batch can be OOB messages, regular messages, or mixed messages, although the transport itself will create initial MessageBatches that contain only either OOB or regular messages.The default processing below sends messages up the stack individually, based on a matching criteria (calling
accept(Message)), and - if true - callsup(org.jgroups.Event)for that message and removes the message. If the batch is not empty, it is passed up, or else it is dropped.Subclasses should check if there are any messages destined for them (e.g. using
MessageBatch.iterator(Predicate)), then possibly remove and process them and finally pass the batch up to the next protocol. Protocols can also modify messages in place, e.g. ENCRYPT could decrypt all encrypted messages in the batch, not remove them, and pass the batch up when done.- Parameters:
batch- The message batch
-
toString
-
accept
Called by the default implementation ofup(org.jgroups.util.MessageBatch)for each message to determine if the message should be removed from the message batch (and handled by the current protocol) or not.- Parameters:
msg- The message. Guaranteed to be non-null- Returns:
- True if the message should be handled by this protocol (will be removed from the batch), false if the
message should remain in the batch and be passed up.
The default implementation tries to find a header matching the current protocol's ID and returns true if there is a match, or false otherwise
-