Package org.jgroups.stack
Class ProtocolStack
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.stack.ProtocolStack
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classKeeps track of the number os times init()/destroy() and start()/stop have been called. -
Field Summary
Fields -
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 protocolscopyProtocols(ProtocolStack targetStack) protected ProtocolcreateProtocol(String classname) voiddestroy()This method is called on aChannel.close().An event is to be sent down the stack.Deprecated.findProtocol(Class<?> clazz) findProtocol(Class<?>... classes) Finds the first protocol of a list and returns it.findProtocol(String name) Returns a given protocol or null if not foundvoidDeprecated.getName()All protocol names have to be unique !Returns all protocols in a list, from top to bottom.static ConcurrentMap<String, Tuple<TP, ProtocolStack.RefCounter>> Deprecated.UseProtocol.getThreadFactory()insteadstatic ThreadFactoryDeprecated.intDeprecated.UseTP.getTimer()to fetch the timer and call getCorePoolSize() directlyReturns the bottom most protocolvoidinit()Called after instance has been created (null constructor) and before protocol is started.voidvoidinsertProtocol(Protocol prot, int position, Class<? extends Protocol> neighbor_prot) voidinsertProtocol(Protocol prot, int position, Class<? extends Protocol>... neighbor_prots) voidinsertProtocol(Protocol prot, int position, String neighbor_prot) Inserts an already created (and initialized) protocol into the protocol list.voidinsertProtocolAtTop(Protocol prot) voidinsertProtocolInStack(Protocol prot, Protocol neighbor, int position) printProtocolSpec(boolean include_properties) Prints the names of the protocols, from the bottom to top.receive(long timeout) removeProtocol(Class prot) removeProtocol(Class... protocols) removeProtocol(String prot_name) Removes a protocol from the stack.voidvoidsetChannel(JChannel ch) voidDeprecated.UseProtocol.getThreadFactory()insteadstatic voidDeprecated.voidsetup(List<ProtocolConfiguration> configs) voidsetup(ProtocolStack stack) voidstartStack(String cluster_name, Address local_addr) Start all layers.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 protocolAn event was received from the layer below.Methods inherited from class org.jgroups.stack.Protocol
downThreadEnabled, enableStats, getConfigurableObjects, getDownProtocol, getId, getLevel, getProperties, getProtocolStack, getSocketFactory, getUpProtocol, getValue, isErgonomics, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProperties, setPropertiesInternal, setProperty, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, start, statsEnabled, stop, upThreadEnabled
-
Field Details
-
ABOVE
public static final int ABOVE- See Also:
-
BELOW
public static final int BELOW- See Also:
-
-
Constructor Details
-
ProtocolStack
- Throws:
ChannelException
-
ProtocolStack
public ProtocolStack()Used for programmatic creation of ProtocolStack
-
-
Method Details
-
getChannel
-
setChannel
-
getThreadFactory
Deprecated.UseProtocol.getThreadFactory()insteadDescription copied from class:ProtocolSupposed 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- Overrides:
getThreadFactoryin classProtocol- Returns:
-
getTimerThreadFactory
Deprecated. -
setThreadFactory
Deprecated.UseProtocol.getThreadFactory()instead- Parameters:
f-
-
setTimerThreadFactory
Deprecated.- Parameters:
f-
-
getTimerThreads
public int getTimerThreads()Deprecated.UseTP.getTimer()to fetch the timer and call getCorePoolSize() directly- Returns:
-
getProtocols
Returns all protocols in a list, from top to bottom. These are not copies of protocols, so modifications will affect the actual instances ! -
copyProtocols
public List<Protocol> copyProtocols(ProtocolStack targetStack) throws IllegalAccessException, InstantiationException -
getTransport
Returns the bottom most protocol- Overrides:
getTransportin classProtocol
-
getSingletonTransports
-
dumpStats
-
dumpStats
-
dumpStats
-
dumpTimerQueue
Deprecated.UseTP.getTimer()instead to fetch the timer from the transport and then invoke the method on it- Returns:
-
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
-
setup
- Throws:
Exception
-
setup
- 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
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
-
insertProtocol
public void insertProtocol(Protocol prot, int position, Class<? extends Protocol> neighbor_prot) throws Exception - Throws:
Exception
-
insertProtocol
public void insertProtocol(Protocol prot, int 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.- Throws:
Exception- Thrown if the protocol cannot be stopped correctly.
-
removeProtocol
-
removeProtocol
-
findProtocol
Returns a given protocol or null if not found -
getBottomProtocol
-
getTopProtocol
-
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
-
createProtocol
- Throws:
Exception
-
init
Description copied from class:ProtocolCalled 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. -
initProtocolStack
- Throws:
Exception
-
destroy
public void destroy()Description copied from class:ProtocolThis method is called on aChannel.close(). Does some cleanup; after the call the VM will terminate -
startStack
Start all layers. TheProtocol.start()method is called in each protocol, from top to bottom. Each layer 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
-
flushEvents
public void flushEvents()Deprecated.Not needed anymore, just left in here for backwards compatibility with JBoss AS -
send
-
receive
-
getName
Description copied from class:ProtocolAll protocol names have to be unique ! -
up
Description copied from class:ProtocolAn 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
Description copied from class:ProtocolAn 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().
-
TP.getTimer()instead to fetch the timer from the transport and then invoke the method on it