Class ForkChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,ChannelListener
- Since:
- 3.4
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgroups.JChannel
JChannel.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Field[]protected final Stringprotected final JChannelFields inherited from class org.jgroups.JChannel
address_generators, channel_listeners, cluster_name, discard_own_messages, flush_supported, local_addr, log, name, probe_handler, prot_stack, receiver, state, state_promise, state_transfer_supported, stats, up_handler, view -
Constructor Summary
ConstructorsConstructorDescriptionForkChannel(JChannel main_channel, String fork_stack_id, String fork_channel_id, boolean create_fork_if_absent, ProtocolStack.Position position, Class<? extends Protocol> neighbor, Protocol... protocols) Creates a new fork-channel from a main-channel.ForkChannel(JChannel main_channel, String fork_stack_id, String fork_channel_id, Protocol... protocols) Creates a new fork-channel from a main-channel. -
Method Summary
Modifier and TypeMethodDescriptionaddAddressGenerator(AddressGenerator address_generator) Sets the newAddressGenerator.voidchannelClosed(JChannel channel) Channel has been closed notification callbackvoidchannelConnected(JChannel channel) Channel has been connected notification callbackvoidchannelDisconnected(JChannel channel) Channel has been disconnected notification callbackvoidclose()Closes the fork-channel, essentially setting its state to CLOSED.Connects the fork-channel, which will be operational after this.Joins the cluster and gets the state from a specified state provider.protected voidCopies state from main-channel to this fork-channelRemoves the fork-channel from the fork-stack's hashmap and resets its state.protected static FORKgetFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor, boolean create_fork_if_absent) Creates a new FORK protocol, or returns the existing one, or throws an exception.Retrieves the full state from the target member.protected voidSends a message.protected voidprotected ForkChannelsetLocalAddress(Address local_addr) Sets the logical name for the channel.startFlush(boolean automatic_resume) Performs the flush of the cluster, ie.startFlush(List<Address> flushParticipants, boolean automatic_resume) Performs the flush of the cluster but only for the specified flush participants.Stops the current flush round.Stops the current flush of the cluster for the specified flush participants.Methods inherited from class org.jgroups.JChannel
_close, _connect, _preConnect, addChannelListener, address, checkClosed, checkClosedOrNotConnected, cleanup, clearChannelListeners, clusterName, connect, connect, determineCoordinator, down, down, dumpStats, dumpStats, dumpStats, flushSupported, generateAddress, getAddress, getAddressAsString, getAddressAsUUID, getClusterName, getDiscardOwnMessages, getName, getProperties, getProtocolStack, getReceiver, getState, getState, getState, getStats, getUpHandler, getVersion, getView, getViewAsString, init, init, invokeCallback, isClosed, isConnected, isConnecting, isOpen, name, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, notifyListeners, printProtocolSpec, receiver, removeAddressGenerator, removeChannelListener, send, send, send, setAddress, setDiscardOwnMessages, setReceiver, setStats, setUpHandler, stack, startStack, stats, stats, stopStack, toString, toString, up, up, up, view
-
Field Details
-
main_channel
-
fork_channel_id
-
copied_fields
-
-
Constructor Details
-
ForkChannel
public ForkChannel(JChannel main_channel, String fork_stack_id, String fork_channel_id, boolean create_fork_if_absent, ProtocolStack.Position position, Class<? extends Protocol> neighbor, Protocol... protocols) throws Exception Creates a new fork-channel from a main-channel. The channel is unconnected andconnect(String)needs to be called to send and receive messages.- Parameters:
main_channel- The main-channel. The lifetime of the newly created channel will be less than or equal to the main-channelfork_stack_id- The ID to associate the fork-stack with in FORKfork_channel_id- The ID used to map fork-channel IDs to ForkChannels in the fork-channels protocol stackcreate_fork_if_absent- If true, and FORK doesn't exist, a new FORK protocol will be created and inserted into the main-stack at the given position. If false, and FORK doesn't exist, an exception will be thrownposition- The position at which the newly created FORK will be inserted.ProtocolStack.Position.ABOVEorProtocolStack.Position.BELOWare accepted. Ignored if create_fork_if_absent is false.neighbor- The class of the neighbor protocol below or above which the newly created FORK protocol will be inserted. Ignored if create_fork_if_absent is false.protocols- A list of protocols (from bottom to top !) to insert as the fork_stack in FORK under the given fork_stack_id. If the fork-stack with fork_stack_id already exists, an exception will be thrown. Can be null if no protocols should be added. This may be the case when an app only wants to use a ForkChannel to mux/demux messages, but doesn't need a different protocol stack.- Throws:
Exception
-
ForkChannel
public ForkChannel(JChannel main_channel, String fork_stack_id, String fork_channel_id, Protocol... protocols) throws Exception Creates a new fork-channel from a main-channel. The channel is unconnected andconnect(String)needs to be called to send and receive messages. If FORK is not found in the stack, an exception will be thrown.- Parameters:
main_channel- The main-channel. The lifetime of the newly created channel will be less than or equal to the main-channelfork_stack_id- The ID to associate the fork-stack with in FORKfork_channel_id- The ID used to map fork-channel IDs to ForkChannels in the fork-channels protocol stackprotocols- A list of protocols (from bottom to top !) to insert as the fork_stack in FORK under the given fork_stack_id. If the fork-stack with fork_stack_id already exists, an exception will be thrown. Can be null if no protocols should be added. This may be the case when an app only wants to use a ForkChannel to mux/demux messages, but doesn't need a different protocol stack.- Throws:
Exception
-
-
Method Details
-
setName
Description copied from class:JChannelSets the logical name for the channel. The name will stay associated with this channel for the channel's lifetime (until close() is called). This method must be called before calling connect() -
name
-
channelConnected
Description copied from interface:ChannelListenerChannel has been connected notification callback- Specified by:
channelConnectedin interfaceChannelListener- Parameters:
channel- the channel that has been connected
-
channelDisconnected
Description copied from interface:ChannelListenerChannel has been disconnected notification callback- Specified by:
channelDisconnectedin interfaceChannelListener- Parameters:
channel- the disconnected channel
-
channelClosed
Description copied from interface:ChannelListenerChannel has been closed notification callback- Specified by:
channelClosedin interfaceChannelListener- Parameters:
channel- the closed channel
-
connect
Connects the fork-channel, which will be operational after this. Note that the fork-channel will have the same state as the main-channel, ie. if the main-channel is disconnected, so will the fork-channel be, even if connect() was called. This connect() method essentially adds the fork-channel to the fork-stack's hashmap, ready to send/receive messages as soon as the main-channel has been connected.This method does not affect the main-channel.
-
connect
Description copied from class:JChannelJoins the cluster and gets the state from a specified state provider.This method essentially invokes
connectandgetStatemethods successively. If FLUSH protocol is in channel's stack definition only one flush is executed for both connecting and fetching state rather than two flushes if we invokeconnectandgetStatein succession.If the channel is closed an exception will be thrown.
- Overrides:
connectin classJChannel- Parameters:
cluster_name- the cluster name to connect to. Cannot be null.target- the state provider. If null state will be fetched from coordinator, unless this channel is coordinator.timeout- the timeout for state transfer.- Throws:
Exception- Connecting to the cluster or state transfer was not successful
-
disconnect
Removes the fork-channel from the fork-stack's hashmap and resets its state. Does not affect the main-channel- Overrides:
disconnectin classJChannel- See Also:
-
close
public void close()Closes the fork-channel, essentially setting its state to CLOSED. Note that - contrary to a regular channel - a closed fork-channel can be connected again: this means re-attaching the fork-channel to the main-channel -
down
-
send
Description copied from class:JChannelSends a message. The message contains- a destination address (Address). A
nulladdress sends the message to all cluster members. - a source address. Can be left empty as it will be assigned automatically
- a byte buffer. The message contents.
- several additional fields. They can be used by application programs (or patterns). E.g. a message ID, flags etc
- a destination address (Address). A
-
startFlush
public ForkChannel startFlush(List<Address> flushParticipants, boolean automatic_resume) throws Exception Description copied from class:JChannelPerforms the flush of the cluster but only for the specified flush participants.All pending messages are flushed out but only for the flush participants. The remaining members in the cluster are not included in the flush. The list of flush participants should be a proper subset of the current view.
If this flush is not automatically resumed it is an obligation of the application to invoke the matching
JChannel.stopFlush(List)method with the same list of members used inJChannel.startFlush(List, boolean).- Overrides:
startFlushin classJChannel- Parameters:
automatic_resume- if true callJChannel.stopFlush()after the flush- Throws:
Exception
-
startFlush
Description copied from class:JChannelPerforms the flush of the cluster, ie. all pending application messages are flushed out of the cluster and all members ack their reception. After this call returns, no member will be allowed to send any messages untilJChannel.stopFlush()is called.In the case of flush collisions (another member attempts flush at roughly the same time) start flush will fail by throwing an Exception. Applications can re-attempt flushing after certain back-off period.
JGroups provides a helper random sleep time backoff algorithm for flush using Util class.
- Overrides:
startFlushin classJChannel- Parameters:
automatic_resume- if true callJChannel.stopFlush()after the flush- Throws:
Exception
-
stopFlush
Description copied from class:JChannelStops the current flush round. Cluster members are unblocked and allowed to send new and pending messages -
stopFlush
Description copied from class:JChannelStops the current flush of the cluster for the specified flush participants. Flush participants are unblocked and allowed to send new and pending messages.It is an obligation of the application to invoke the matching
JChannel.startFlush(List, boolean)method with the same list of members prior to invocation of this method. -
getState
Description copied from class:JChannelRetrieves the full state from the target member.The state transfer is initiated by invoking getState() on this channel. The state provider in turn invokes the
Receiver.getState(java.io.OutputStream)callback and sends the state to this node, the state receiver. After the state arrives at the state receiver, theReceiver.setState(java.io.InputStream)callback is invoked to install the state. -
addAddressGenerator
Description copied from class:JChannelSets the newAddressGenerator. New addresses will be generated using the new generator. This should not be done while a channel is connected, but before connecting.- Overrides:
addAddressGeneratorin classJChannel- Parameters:
address_generator-
-
setLocalAddress
-
getFORK
protected static FORK getFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor, boolean create_fork_if_absent) throws Exception Creates a new FORK protocol, or returns the existing one, or throws an exception. Never returns null.- Throws:
Exception
-
setHeader
-
copyFields
protected void copyFields()Copies state from main-channel to this fork-channel -
nullFields
protected void nullFields()
-