public class ProtocolStack extends Protocol
The ProtocolStack makes use of the Configurator to setup and initialize stacks, and to destroy them again when not needed anymore
Modifier and Type | Class and Description |
---|---|
static class |
ProtocolStack.RefCounter
Keeps track of the number os times init()/destroy() and start()/stop have been called.
|
Modifier and Type | Field and Description |
---|---|
static int |
ABOVE |
static int |
BELOW |
protected Protocol |
bottom_prot |
protected JChannel |
channel |
protected static java.lang.String |
max_list_print_size |
protected DiagnosticsHandler.ProbeHandler |
props_handler |
protected static java.util.concurrent.ConcurrentMap<java.lang.String,Tuple<TP,ProtocolStack.RefCounter>> |
singleton_transports
Holds the shared transports, keyed by 'TP.singleton_name'.
|
protected boolean |
stopped |
protected Protocol |
top_prot |
after_creation_hook, down_prot, ergonomics, id, log, name, stack, stats, up_prot
Constructor and Description |
---|
ProtocolStack()
Used for programmatic creation of ProtocolStack
|
ProtocolStack(JChannel channel) |
Modifier and Type | Method and Description |
---|---|
ProtocolStack |
addProtocol(Protocol prot)
Adds a protocol at the tail of the protocol list
|
ProtocolStack |
addProtocols(java.util.List<Protocol> prots)
Adds a list of protocols
|
ProtocolStack |
addProtocols(Protocol... prots)
Adds a list of protocols
|
ProtocolStack |
bottomProtocol(Protocol bottom) |
protected static void |
callAfterCreationHook(Protocol prot,
java.lang.String classname) |
java.util.List<Protocol> |
copyProtocols(ProtocolStack targetStack) |
protected Protocol |
createProtocol(java.lang.String classname) |
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() |
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name) |
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name,
java.util.List<java.lang.String> attrs) |
Protocol |
findProtocol(java.lang.Class<?>... classes)
Finds the first protocol of a list and returns it.
|
Protocol |
findProtocol(java.lang.Class<?> clazz) |
Protocol |
findProtocol(java.lang.String name)
Returns a given protocol or null if not found
|
Protocol |
getBottomProtocol() |
JChannel |
getChannel() |
java.lang.String |
getName() |
java.util.List<Protocol> |
getProtocols()
Returns all protocols in a list, from top to bottom.
|
static java.util.concurrent.ConcurrentMap<java.lang.String,Tuple<TP,ProtocolStack.RefCounter>> |
getSingletonTransports() |
Protocol |
getTopProtocol() |
TP |
getTransport()
Returns the bottom most protocol
|
void |
init()
Called after instance has been created (null constructor) and before protocol is started.
|
void |
initProtocolStack() |
void |
insertProtocol(Protocol prot,
int position,
java.lang.Class<? extends Protocol>... neighbor_prots) |
void |
insertProtocol(Protocol prot,
int position,
java.lang.Class<? extends Protocol> neighbor_prot) |
void |
insertProtocol(Protocol prot,
int position,
java.lang.String neighbor_prot)
Inserts an already created (and initialized) protocol into the protocol list.
|
void |
insertProtocolAtTop(Protocol prot) |
void |
insertProtocolInStack(Protocol prot,
Protocol neighbor,
int position) |
java.lang.String |
printProtocolSpec(boolean include_properties)
Prints the names of the protocols, from the bottom to top.
|
java.lang.String |
printProtocolSpecAsPlainString() |
java.lang.String |
printProtocolSpecAsXML() |
Protocol |
removeProtocol(java.lang.Class... protocols) |
Protocol |
removeProtocol(java.lang.Class prot) |
Protocol |
removeProtocol(Protocol prot) |
Protocol |
removeProtocol(java.lang.String prot_name)
Removes a protocol from the stack.
|
void |
removeProtocols(java.lang.String... protocols) |
void |
replaceProtocol(Protocol existing_prot,
Protocol new_prot)
Replaces one protocol instance with another.
|
ProtocolStack |
setChannel(JChannel ch) |
void |
setup(java.util.List<ProtocolConfiguration> configs) |
void |
setup(ProtocolStack stack) |
void |
startStack(java.lang.String cluster,
Address local_addr)
Start all layers.
|
void |
stopStack(java.lang.String cluster)
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
|
ProtocolStack |
topProtocol(Protocol top) |
java.lang.Object |
up(Event evt)
An event was received from the layer below.
|
void |
up(MessageBatch batch)
Sends up a multiple messages in a
MessageBatch . |
accept, afterCreationHook, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getProtocolStack, getSocketFactory, getThreadFactory, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, start, statsEnabled, stop
public static final int ABOVE
public static final int BELOW
protected static final java.lang.String max_list_print_size
protected static final java.util.concurrent.ConcurrentMap<java.lang.String,Tuple<TP,ProtocolStack.RefCounter>> singleton_transports
protected Protocol top_prot
protected Protocol bottom_prot
protected JChannel channel
protected volatile boolean stopped
protected final DiagnosticsHandler.ProbeHandler props_handler
public ProtocolStack(JChannel channel) throws java.lang.Exception
java.lang.Exception
public ProtocolStack()
public ProtocolStack topProtocol(Protocol top)
public ProtocolStack bottomProtocol(Protocol bottom)
public JChannel getChannel()
public ProtocolStack setChannel(JChannel ch)
public java.util.List<Protocol> getProtocols()
public java.util.List<Protocol> copyProtocols(ProtocolStack targetStack) throws java.lang.IllegalAccessException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.InstantiationException
public TP getTransport()
getTransport
in class Protocol
public static java.util.concurrent.ConcurrentMap<java.lang.String,Tuple<TP,ProtocolStack.RefCounter>> getSingletonTransports()
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name)
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name, java.util.List<java.lang.String> attrs)
public java.lang.String printProtocolSpec(boolean include_properties)
public java.lang.String printProtocolSpecAsXML()
public java.lang.String printProtocolSpecAsPlainString()
public void setup(java.util.List<ProtocolConfiguration> configs) throws java.lang.Exception
java.lang.Exception
public void setup(ProtocolStack stack) throws java.lang.Exception
java.lang.Exception
public ProtocolStack addProtocol(Protocol prot)
prot
- public ProtocolStack addProtocols(Protocol... prots)
prots
- public ProtocolStack addProtocols(java.util.List<Protocol> prots)
prots
- public void insertProtocol(Protocol prot, int position, java.lang.String neighbor_prot) throws java.lang.Exception
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 foundjava.lang.Exception
- Will be thrown when the new protocol cannot be created, or inserted.public void insertProtocolInStack(Protocol prot, Protocol neighbor, int position)
public void insertProtocol(Protocol prot, int position, java.lang.Class<? extends Protocol> neighbor_prot) throws java.lang.Exception
java.lang.Exception
public void insertProtocol(Protocol prot, int position, java.lang.Class<? extends Protocol>... neighbor_prots) throws java.lang.Exception
java.lang.Exception
public void insertProtocolAtTop(Protocol prot)
public Protocol removeProtocol(java.lang.String prot_name)
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.java.lang.Exception
- Thrown if the protocol cannot be stopped correctly.public void removeProtocols(java.lang.String... protocols)
public Protocol removeProtocol(java.lang.Class... protocols)
public Protocol removeProtocol(java.lang.Class prot)
public Protocol findProtocol(java.lang.String name)
public Protocol getBottomProtocol()
public Protocol getTopProtocol()
public Protocol findProtocol(java.lang.Class<?> clazz)
public Protocol findProtocol(java.lang.Class<?>... classes)
classes
- A list of protocol classes to findpublic void replaceProtocol(Protocol existing_prot, Protocol new_prot) throws java.lang.Exception
existing_prot
- new_prot
- java.lang.Exception
protected Protocol createProtocol(java.lang.String classname) throws java.lang.Exception
java.lang.Exception
public void init() throws java.lang.Exception
Protocol
public void initProtocolStack() throws java.lang.Exception
java.lang.Exception
public void destroy()
Protocol
Channel.close()
.
Does some cleanup; after the call the VM will terminatepublic void startStack(java.lang.String cluster, Address local_addr) throws java.lang.Exception
Protocol.start()
method is called in each protocol,
from top to bottom.
Each layer can perform some initialization, e.g. create a multicast socketjava.lang.Exception
public void stopStack(java.lang.String cluster)
public java.lang.Object up(Event evt)
Protocol
down_prot.down()
or c) the event (or another event) is sent up
the stack using up_prot.up()
.public void up(MessageBatch batch)
Protocol
MessageBatch
. 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(org.jgroups.Message)
), and - if true - calls Protocol.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.getMatchingMessages(short,boolean)
), 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.public java.lang.Object down(Event evt)
Protocol
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()
.protected static void callAfterCreationHook(Protocol prot, java.lang.String classname) throws java.lang.Exception
java.lang.Exception
Copyright © 1998-2020 Red Hat. All Rights Reserved.