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 intconnectsprotected java.util.concurrent.ConcurrentMap<java.lang.String,JChannel>fork_channelsprotected java.lang.Stringfork_stack_idprotected intinitsprotected Addresslocal_addrprotected java.util.List<Protocol>protocolsprotected UnknownForkHandlerunknownForkHandler-
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 voiddestroy()This method is called on aJChannel.close().java.lang.Objectdown(Event evt)An event is to be sent down the stack.java.lang.Objectdown(Message msg)A message is sent down the stack.JChannelget(java.lang.String fork_channel_id)intgetConnects()java.util.concurrent.ConcurrentMap<java.lang.String,JChannel>getForkChannels()intgetInits()java.util.List<Protocol>getProtocols()Returns all protocols in a list, from top to bottom.UnknownForkHandlergetUnknownForkHandler()ForkProtocolStackincrInits()voidinit()Called after instance has been created (null constructor) and before protocol is started.JChannelputIfAbsent(java.lang.String id, JChannel fc)voidremove(java.lang.String fork_channel_id)voidsetLocalAddress(Address addr)voidsetUnknownForkHandler(UnknownForkHandler ufh)voidstartStack()Start all protocols.voidstopStack(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.Objectup(Event evt)An event was received from the protocol below.java.lang.Objectup(Message msg)A single message was received.voidup(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: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().- Overrides:
downin classProtocolStack
-
down
public java.lang.Object down(Message msg)
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.- Overrides:
downin classProtocolStack
-
setLocalAddress
public void setLocalAddress(Address addr)
-
getProtocols
public java.util.List<Protocol> getProtocols()
Description copied from class:ProtocolStackReturns all protocols in a list, from top to bottom. These are not copies of protocols, so modifications will affect the actual instances !- Overrides:
getProtocolsin classProtocolStack
-
incrInits
public ForkProtocolStack incrInits()
-
init
public void init() throws java.lang.ExceptionDescription 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.- Overrides:
initin 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.ExceptionDescription copied from class:ProtocolStackStart 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:
startStackin classProtocolStack- Throws:
java.lang.Exception
-
stopStack
public void stopStack(java.lang.String cluster)
Description copied from class:ProtocolStackIterates 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:
stopStackin classProtocolStack
-
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- Overrides:
destroyin classProtocolStack
-
up
public java.lang.Object up(Event evt)
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().- Overrides:
upin classProtocolStack
-
up
public java.lang.Object up(Message msg)
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.- Overrides:
upin classProtocolStack
-
up
public void up(MessageBatch batch)
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 (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:
upin classProtocolStack- Parameters:
batch- The message batch
-
-