Package org.jgroups.fork
Class ForkProtocolStack
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.stack.ProtocolStack
-
- org.jgroups.fork.ForkProtocolStack
-
public class ForkProtocolStack extends ProtocolStack
Protocol stack which maintains the mapping between fork-channel IDs and ForkChannels- Since:
- 3.4
- Author:
- Bela Ban
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jgroups.stack.ProtocolStack
ProtocolStack.Position
-
-
Field Summary
Fields Modifier and Type Field Description protected int
connects
protected java.util.concurrent.ConcurrentMap<java.lang.String,JChannel>
fork_channels
protected java.lang.String
fork_stack_id
protected int
inits
protected Address
local_addr
protected java.util.List<Protocol>
protocols
protected UnknownForkHandler
unknownForkHandler
-
Fields inherited from class org.jgroups.stack.ProtocolStack
bottom_prot, channel, max_list_print_size, props_handler, stopped, top_prot
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description ForkProtocolStack(UnknownForkHandler unknownForkHandler, java.util.List<Protocol> protocols, java.lang.String fork_stack_id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
This method is called on aJChannel.close()
.java.lang.Object
down(Event evt)
An event is to be sent down the stack.java.lang.Object
down(Message msg)
A message is sent down the stack.JChannel
get(java.lang.String fork_channel_id)
int
getConnects()
java.util.concurrent.ConcurrentMap<java.lang.String,JChannel>
getForkChannels()
int
getInits()
java.util.List<Protocol>
getProtocols()
Returns all protocols in a list, from top to bottom.UnknownForkHandler
getUnknownForkHandler()
ForkProtocolStack
incrInits()
void
init()
Called after instance has been created (null constructor) and before protocol is started.JChannel
putIfAbsent(java.lang.String id, JChannel fc)
void
remove(java.lang.String fork_channel_id)
void
setLocalAddress(Address addr)
void
setUnknownForkHandler(UnknownForkHandler ufh)
void
startStack()
Start all protocols.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 protocoljava.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.void
up(MessageBatch batch)
Sends up a multiple messages in aMessageBatch
.-
Methods inherited from class org.jgroups.stack.ProtocolStack
addProtocol, addProtocols, addProtocols, bottomProtocol, callAfterCreationHook, copyProtocols, createProtocol, dumpStats, dumpStats, dumpStats, findProtocol, findProtocol, findProtocol, findProtocols, getBottomProtocol, getChannel, getName, getTopProtocol, getTransport, initProtocolStack, insertProtocol, insertProtocol, insertProtocol, insertProtocolAtTop, insertProtocolInStack, printProtocolSpec, printProtocolSpecAsPlainString, printProtocolSpecAsXML, removeProtocol, removeProtocol, removeProtocol, removeProtocol, removeProtocols, removeProtocols, replaceProtocol, setChannel, setup, setup, topProtocol
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getProtocolStack, getSocketFactory, getThreadFactory, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop
-
-
-
-
Field Detail
-
local_addr
protected Address local_addr
-
fork_stack_id
protected final java.lang.String fork_stack_id
-
fork_channels
protected final java.util.concurrent.ConcurrentMap<java.lang.String,JChannel> fork_channels
-
unknownForkHandler
protected UnknownForkHandler unknownForkHandler
-
protocols
protected final java.util.List<Protocol> protocols
-
inits
protected int inits
-
connects
protected int connects
-
-
Constructor Detail
-
ForkProtocolStack
public ForkProtocolStack(UnknownForkHandler unknownForkHandler, java.util.List<Protocol> protocols, java.lang.String fork_stack_id)
-
-
Method Detail
-
getForkChannels
public java.util.concurrent.ConcurrentMap<java.lang.String,JChannel> getForkChannels()
-
get
public JChannel get(java.lang.String fork_channel_id)
-
remove
public void remove(java.lang.String fork_channel_id)
-
getInits
public int getInits()
-
getConnects
public int getConnects()
-
setUnknownForkHandler
public void setUnknownForkHandler(UnknownForkHandler ufh)
-
getUnknownForkHandler
public UnknownForkHandler getUnknownForkHandler()
-
down
public java.lang.Object down(Event evt)
Description copied from class:Protocol
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()
.- Overrides:
down
in classProtocolStack
-
down
public java.lang.Object down(Message msg)
Description copied from class:Protocol
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.- Overrides:
down
in classProtocolStack
-
setLocalAddress
public void setLocalAddress(Address addr)
-
getProtocols
public java.util.List<Protocol> getProtocols()
Description copied from class:ProtocolStack
Returns all protocols in a list, from top to bottom. These are not copies of protocols, so modifications will affect the actual instances !- Overrides:
getProtocols
in classProtocolStack
-
incrInits
public ForkProtocolStack incrInits()
-
init
public void init() throws java.lang.Exception
Description copied from class:Protocol
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.- Overrides:
init
in classProtocolStack
- Throws:
java.lang.Exception
- Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception
-
startStack
public void startStack() throws java.lang.Exception
Description copied from class:ProtocolStack
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- Overrides:
startStack
in classProtocolStack
- Throws:
java.lang.Exception
-
stopStack
public void stopStack(java.lang.String cluster)
Description copied from class:ProtocolStack
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
- Overrides:
stopStack
in classProtocolStack
-
destroy
public void destroy()
Description copied from class:Protocol
This method is called on aJChannel.close()
. Does some cleanup; after the call the VM will terminate- Overrides:
destroy
in classProtocolStack
-
up
public java.lang.Object up(Event evt)
Description copied from class:Protocol
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()
.- Overrides:
up
in classProtocolStack
-
up
public java.lang.Object up(Message msg)
Description copied from class:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.- Overrides:
up
in classProtocolStack
-
up
public void up(MessageBatch batch)
Description copied from class:Protocol
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 (callingProtocol.accept(org.jgroups.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. usingMessageBatch.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.- Overrides:
up
in classProtocolStack
- Parameters:
batch
- The message batch
-
-