Class ProtocolStack
- All Implemented Interfaces:
Lifecycle
- Direct Known Subclasses:
ForkProtocolStack
The ProtocolStack makes use of the Configurator to setup and initialize stacks, and to destroy them again when not needed anymore
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Protocolprotected JChannelprotected static final Stringprotected final DiagnosticsHandler.ProbeHandlerprotected booleanprotected ProtocolFields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot -
Constructor Summary
ConstructorsConstructorDescriptionUsed for programmatic creation of ProtocolStackProtocolStack(JChannel channel) -
Method Summary
Modifier and TypeMethodDescriptionaddProtocol(Protocol prot) Adds a protocol at the tail of the protocol listaddProtocols(List<Protocol> prots) Adds a list of protocolsaddProtocols(Protocol... prots) Adds a list of protocolsbottomProtocol(Protocol bottom) protected static voidcallAfterCreationHook(Protocol prot, String classname) private voidcheckAndSwitchTop(Protocol oldTop, Protocol newTop) protected ProtocolcreateProtocol(String classname) voiddestroy()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.<T extends Protocol>
TfindProtocol(Class<? extends Protocol> clazz) final <T extends Protocol>
TfindProtocol(Class<? extends Protocol>... classes) Finds the first protocol of a list and returns it.<T extends Protocol>
TfindProtocol(String name) Returns a given protocol or null if not foundstatic <T extends Protocol>
TfindProtocol(Protocol start, boolean down, Class<? extends Protocol> clazz) findProtocols(String regexp) <T extends Protocol>
TgetName()Returns all protocols in a list, from top to bottom.Returns the bottom most protocolvoidinit()Called after a protocol has been created and before the protocol is started.static voidvoidinitProtocolStack(List<ProtocolConfiguration> configs) Calls @link{Protocol.init()} in all protocols, from bottom to topvoidinitProtocolStack(List<ProtocolConfiguration> configs, ProtocolHook afterCreationHook) voidinsertProtocol(Protocol prot, ProtocolStack.Position position, Class<? extends Protocol> neighbor_prot) final voidinsertProtocol(Protocol prot, ProtocolStack.Position position, Class<? extends Protocol>... neighbor_prots) voidinsertProtocol(Protocol prot, ProtocolStack.Position position, String neighbor_prot) Inserts an already created (and initialized) protocol into the protocol list.voidinsertProtocolAtTop(Protocol prot) voidinsertProtocolInStack(Protocol prot, Protocol neighbor, ProtocolStack.Position position) printProtocolSpec(boolean include_properties) Prints the names of the protocols, from the bottom to top.private StringprintProtocolSpecAsPlainString(boolean print_props) <T extends Protocol>
TremoveProtocol(Class<? extends Protocol> prot) final <T extends Protocol>
TremoveProtocol(Class<? extends Protocol>... protocols) <T extends Protocol>
TremoveProtocol(String prot_name) Removes a protocol from the stack.<T extends Protocol>
TremoveProtocol(T prot) final ProtocolStackremoveProtocols(Class<? extends Protocol>... protocols) removeProtocols(String... protocols) voidreplaceProtocol(Protocol existing_prot, Protocol new_prot) Replaces one protocol instance with another.setChannel(JChannel ch) voidsetup(List<ProtocolConfiguration> configs) voidsetup(List<ProtocolConfiguration> configs, ProtocolHook afterCreationHook) voidStart all protocols.voidIterates through all the protocols from top to bottom and does the following: Waits until all messages in the down queue have been flushed (ie., size is 0) Calls stop() on the protocoltopProtocol(Protocol top) An event was received from the protocol below.A single message was received.voidup(MessageBatch batch) Sends up a multiple messages in aMessageBatch.Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, toString
-
Field Details
-
max_list_print_size
- See Also:
-
top_prot
-
bottom_prot
-
channel
-
stopped
protected volatile boolean stopped -
props_handler
-
-
Constructor Details
-
ProtocolStack
- Throws:
Exception
-
ProtocolStack
public ProtocolStack()Used for programmatic creation of ProtocolStack
-
-
Method Details
-
topProtocol
-
bottomProtocol
-
getChannel
-
setChannel
-
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
Returns the bottom most protocol- Overrides:
getTransportin classProtocol
-
dumpStats
-
dumpStats
-
printProtocolSpec
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
-
printProtocolSpecAsPlainString
-
printProtocolSpecAsPlainString
-
getProps
-
setup
- Throws:
Exception
-
setup
public void setup(List<ProtocolConfiguration> configs, ProtocolHook afterCreationHook) throws Exception - Throws:
Exception
-
addProtocol
Adds a protocol at the tail of the protocol list- Parameters:
prot-- Returns:
- Since:
- 2.11
-
addProtocols
Adds a list of protocols- Parameters:
prots-- Returns:
- Since:
- 2.11
-
addProtocols
Adds a list of protocols- Parameters:
prots-- Returns:
- Since:
- 2.1
-
insertProtocol
public void insertProtocol(Protocol prot, ProtocolStack.Position 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.
-
insertProtocolInStack
public void insertProtocolInStack(Protocol prot, Protocol neighbor, ProtocolStack.Position position) -
checkAndSwitchTop
-
insertProtocol
public void insertProtocol(Protocol prot, ProtocolStack.Position position, Class<? extends Protocol> neighbor_prot) throws Exception - Throws:
Exception
-
insertProtocol
@SafeVarargs public final void insertProtocol(Protocol prot, ProtocolStack.Position position, Class<? extends Protocol>... neighbor_prots) throws Exception - Throws:
Exception
-
insertProtocolAtTop
-
removeProtocol
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.
-
removeProtocols
-
removeProtocols
-
removeProtocol
@SafeVarargs public final <T extends Protocol> T removeProtocol(Class<? extends Protocol>... protocols) -
removeProtocol
-
removeProtocol
-
findProtocol
Returns a given protocol or null if not found -
findProtocols
-
getBottomProtocol
-
getTopProtocol
-
findProtocol
-
findProtocol
-
findProtocol
Finds the first protocol of a list and returns it. Returns null if no protocol can be found- Parameters:
classes- A list of protocol classes to find- Returns:
- Protocol The protocol found
-
replaceProtocol
Replaces one protocol instance with another. Should be done before the stack is connected- Parameters:
existing_prot-new_prot-- Throws:
Exception
-
createProtocol
- Throws:
Exception
-
init
Description copied from class:ProtocolCalled 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. -
initProtocolStack
Calls @link{Protocol.init()} in all protocols, from bottom to top- Throws:
Exception
-
initProtocolStack
public void initProtocolStack(List<ProtocolConfiguration> configs, ProtocolHook afterCreationHook) throws Exception - Throws:
Exception
-
initComponents
- Throws:
Exception
-
destroy
public void destroy()Description copied from class:ProtocolThis method is called on aJChannel.close(). Does some cleanup; after the call, the VM will terminate -
startStack
Start all protocols. TheProtocol.start()method is called in each protocol, from bottom to top. Each protocol can perform some initialization, e.g. create a multicast socket- Throws:
Exception
-
stopStack
Iterates through all the protocols from top to bottom and does the following:- Waits until all messages in the down queue have been flushed (ie., size is 0)
- Calls stop() on the protocol
-
getName
-
up
Description copied from class:ProtocolAn 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
Description copied from class:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up. -
up
Description copied from class:ProtocolSends 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
Protocol.accept(Message)), and - if true - callsProtocol.up(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. -
down
Description copied from class:ProtocolAn 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
Description copied from class:ProtocolA 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. -
down
Description copied from class:ProtocolPasses 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. -
callAfterCreationHook
- Throws:
Exception
-