public class ForkChannel extends JChannel implements ChannelListener
Channel.State
Modifier and Type | Field and Description |
---|---|
protected static Field[] |
copied_fields |
protected String |
fork_channel_id |
protected Channel |
main_channel |
address_generator, cluster_name, config, DEFAULT_PROTOCOL_STACK, flush_supported, local_addr, my_view, name, probe_handler, prot_stack, received_bytes, received_msgs, sent_bytes, sent_msgs, state_promise, state_transfer_supported, stats
channel_listeners, discard_own_messages, log, receiver, socket_factory, state, up_handler
Constructor and Description |
---|
ForkChannel(Channel main_channel,
String fork_stack_id,
String fork_channel_id,
boolean create_fork_if_absent,
int position,
Class<? extends Protocol> neighbor,
Protocol... protocols)
Creates a new fork-channel from a main-channel.
|
ForkChannel(Channel main_channel,
String fork_stack_id,
String fork_channel_id,
Protocol... protocols)
Creates a new fork-channel from a main-channel.
|
Modifier and Type | Method and Description |
---|---|
void |
channelClosed(Channel channel)
Channel has been closed notification callback
|
void |
channelConnected(Channel channel)
Channel has been connected notification callback
|
void |
channelDisconnected(Channel channel)
Channel has been disconnected notification callback
|
void |
close()
Closes the fork-channel, essentially setting its state to CLOSED.
|
void |
connect(String cluster_name)
Connects the fork-channel, which will be operational after this.
|
void |
connect(String cluster_name,
Address target,
long timeout)
Connects this channel to a group and gets a state from a specified state provider.
|
protected void |
copyFields()
Copies state from main-channel to this fork-channel
|
void |
disconnect()
Removes the fork-channel from the fork-stack's hashmap and resets its state.
|
Object |
down(Event evt)
Sends an event down the protocol stack.
|
protected static FORK |
getFORK(Channel ch,
int position,
Class<? extends Protocol> neighbor,
boolean create_fork_if_absent) |
protected static ForkProtocolStack |
getForkStack(Protocol prot) |
void |
getState(Address target,
long timeout)
Retrieves the full state from the target member.
|
JChannel |
name(String name)
Names a channel, same as
Channel.setName(String) |
protected void |
nullFields() |
void |
send(Message msg)
Sends a message.
|
void |
setAddressGenerator(AddressGenerator address_generator)
Sets the new
AddressGenerator . |
protected void |
setHeader(Message msg) |
protected void |
setLocalAddress(Address local_addr) |
void |
setName(String name)
Sets the logical name for the channel.
|
void |
startFlush(boolean automatic_resume)
Will perform a flush of the system, ie.
|
void |
startFlush(List<Address> flushParticipants,
boolean automatic_resume)
Performs a partial flush in a cluster for flush participants.
|
void |
stopFlush() |
void |
stopFlush(List<Address> flushParticipants) |
_close, _connect, _preConnect, checkClosed, checkClosedOrNotConnected, connect, connect, dumpChannelStats, dumpStats, dumpStats, dumpStats, dumpTimerQueue, enableStats, flushSupported, getAddress, getAddressAsString, getAddressAsUUID, getAddressGenerator, getClusterName, getName, getName, getNumberOfTasksInTimer, getProperties, getProtocolStack, getReceivedBytes, getReceivedMessages, getSentBytes, getSentMessages, getState, getState, getTimer, getTimerThreads, getVersion, getView, getViewAsString, init, init, init, invokeCallback, isConnected, isOpen, printProtocolSpec, receiver, resetStats, send, send, send, setAddress, setProtocolStack, startStack, statsEnabled, stopStack, toString, up, up
addChannelListener, clearChannelListeners, getDiscardOwnMessages, getReceiver, getSocketFactory, getState, getUpHandler, isClosed, isConnecting, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, removeChannelListener, setDiscardOwnMessages, setReceiver, setSocketFactory, setUpHandler
protected final Channel main_channel
protected final String fork_channel_id
protected static final Field[] copied_fields
public ForkChannel(Channel main_channel, String fork_stack_id, String fork_channel_id, boolean create_fork_if_absent, int position, Class<? extends Protocol> neighbor, Protocol... protocols) throws Exception
connect(String)
needs to be called to send and receive messages.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.ABOVE
or
ProtocolStack.BELOW
are 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.Exception
public ForkChannel(Channel main_channel, String fork_stack_id, String fork_channel_id, Protocol... protocols) throws Exception
connect(String)
needs to be called to send and receive messages. If FORK is not found in the stack, an exception will be thrown.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.Exception
public void setName(String name)
Channel
public JChannel name(String name)
Channel
Channel.setName(String)
public void channelConnected(Channel channel)
ChannelListener
channelConnected
in interface ChannelListener
channel
- the channel that has been connectedpublic void channelDisconnected(Channel channel)
ChannelListener
channelDisconnected
in interface ChannelListener
channel
- the disconnected channelpublic void channelClosed(Channel channel)
ChannelListener
channelClosed
in interface ChannelListener
channel
- the closed channelpublic void connect(String cluster_name) throws Exception
connect
in class JChannel
cluster_name
- Ignored, will be the same as the main-channel's cluster nameException
IllegalStateException
- The channel is closedpublic void connect(String cluster_name, Address target, long timeout) throws Exception
Channel
connect and getState methods 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 invoke connect and getState in succession.
If the channel is closed an exception will be thrown.
connect
in class JChannel
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.Exception
- Connecting to the cluster or state transfer was not successfulIllegalStateException
- The channel is closed and therefore cannot be usedpublic void disconnect()
disconnect
in class JChannel
Channel.connect(String)
public void close()
public Object down(Event evt)
JChannel
JChannel.send(Message)
, if the event is a message,
no checks are performed whether the channel is closed or disconnected.public void send(Message msg) throws Exception
Channel
null
address sends the message to all
group members.
send
in class JChannel
msg
- The message to be sent. Destination and buffer should be set. A null destination
means to send to all group members.IllegalStateException
- thrown if the channel is disconnected or closedException
public void startFlush(List<Address> flushParticipants, boolean automatic_resume) throws Exception
Channel
startFlush
in class JChannel
automatic_resume
- if true call Channel.stopFlush()
after the flushException
Channel.startFlush(boolean)
public void startFlush(boolean automatic_resume) throws Exception
Channel
Channel.stopFlush()
is called.
In case of flush collisions, a random sleep time backoff algorithm is employed and the flush
is reattempted for numberOfAttempts. Therefore this method is guaranteed to return after
timeout x numberOfAttempts milliseconds.startFlush
in class JChannel
automatic_resume
- if true call Channel.stopFlush()
after the flushException
public void getState(Address target, long timeout) throws Exception
Channel
State transfer is initiated by invoking getState on this channel. The state provider in turn
invokes MessageListener.getState(java.io.OutputStream)
callback and sends a state to
this node, the state receiver. After the state arrives to the state receiver
MessageListener.setState(java.io.InputStream)
callback is invoked to install the
state.
getState
in class JChannel
target
- The state provider. If null the coordinator is used by defaulttimeout
- The number of milliseconds to wait for the operation to complete successfully. 0
waits until the state has been receivedIllegalStateException
- The channel was closed or disconnected, or the flush (if present) failedStateTransferException
- raised if there was a problem during the state transferException
MessageListener.getState(java.io.OutputStream)
,
MessageListener.setState(java.io.InputStream)
public void setAddressGenerator(AddressGenerator address_generator)
JChannel
AddressGenerator
. New addresses will be generated using the new generator. This
should not be done while a channel is connected, but before connecting.setAddressGenerator
in class JChannel
protected void setLocalAddress(Address local_addr)
protected static FORK getFORK(Channel ch, int position, Class<? extends Protocol> neighbor, boolean create_fork_if_absent) throws Exception
Exception
protected static ForkProtocolStack getForkStack(Protocol prot)
protected void setHeader(Message msg)
protected void copyFields()
protected void nullFields()
Copyright © 2013 JBoss, a division of Red Hat. All rights reserved.