public class ForkChannel extends JChannel implements ChannelListener
Channel.State
限定符和类型 | 字段和说明 |
---|---|
protected static java.lang.reflect.Field[] |
copied_fields |
protected java.lang.String |
fork_channel_id |
protected Channel |
main_channel |
address_generators, 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
构造器和说明 |
---|
ForkChannel(Channel main_channel,
java.lang.String fork_stack_id,
java.lang.String fork_channel_id,
boolean create_fork_if_absent,
int position,
java.lang.Class<? extends Protocol> neighbor,
Protocol... protocols)
Creates a new fork-channel from a main-channel.
|
ForkChannel(Channel main_channel,
java.lang.String fork_stack_id,
java.lang.String fork_channel_id,
Protocol... protocols)
Creates a new fork-channel from a main-channel.
|
限定符和类型 | 方法和说明 |
---|---|
void |
addAddressGenerator(AddressGenerator address_generator)
Sets the new
AddressGenerator . |
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(java.lang.String cluster_name)
Connects the fork-channel, which will be operational after this.
|
void |
connect(java.lang.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.
|
java.lang.Object |
down(Event evt)
Sends an event down the protocol stack.
|
protected static FORK |
getFORK(Channel ch,
int position,
java.lang.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(java.lang.String name)
Names a channel, same as
Channel.setName(String) |
protected void |
nullFields() |
void |
send(Message msg)
Sends a message.
|
protected void |
setHeader(Message msg) |
protected void |
setLocalAddress(Address local_addr) |
void |
setName(java.lang.String name)
Sets the logical name for the channel.
|
void |
startFlush(boolean automatic_resume)
Performs the flush of the cluster, ie. all pending application messages are flushed out of the cluster and
all members ack their reception.
|
void |
startFlush(java.util.List<Address> flushParticipants,
boolean automatic_resume)
Performs the flush of the cluster but only for the specified flush participants.
|
void |
stopFlush()
Stops the current flush of the cluster.
|
void |
stopFlush(java.util.List<Address> flushParticipants)
Stops the current flush of the cluster for the specified flush participants.
|
_close, _connect, _preConnect, checkClosed, checkClosedOrNotConnected, connect, connect, dumpChannelStats, dumpStats, dumpStats, dumpStats, dumpTimerQueue, enableStats, flushSupported, generateAddress, 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, printProtocolSpec, receiver, removeAddressGenerator, resetStats, send, send, send, setAddress, setAddressGenerator, setProtocolStack, startStack, statsEnabled, stopStack, toString, up, up
addChannelListener, clearChannelListeners, getDiscardOwnMessages, getReceiver, getSocketFactory, getState, getUpHandler, isClosed, isConnected, isConnecting, isOpen, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, removeChannelListener, setDiscardOwnMessages, setReceiver, setSocketFactory, setUpHandler
protected final Channel main_channel
protected final java.lang.String fork_channel_id
protected static final java.lang.reflect.Field[] copied_fields
public ForkChannel(Channel main_channel, java.lang.String fork_stack_id, java.lang.String fork_channel_id, boolean create_fork_if_absent, int position, java.lang.Class<? extends Protocol> neighbor, Protocol... protocols) throws java.lang.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.java.lang.Exception
public ForkChannel(Channel main_channel, java.lang.String fork_stack_id, java.lang.String fork_channel_id, Protocol... protocols) throws java.lang.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.java.lang.Exception
public void setName(java.lang.String name)
Channel
public JChannel name(java.lang.String name)
Channel
Channel.setName(String)
public void channelConnected(Channel channel)
ChannelListener
channelConnected
在接口中 ChannelListener
channel
- the channel that has been connectedpublic void channelDisconnected(Channel channel)
ChannelListener
channelDisconnected
在接口中 ChannelListener
channel
- the disconnected channelpublic void channelClosed(Channel channel)
ChannelListener
channelClosed
在接口中 ChannelListener
channel
- the closed channelpublic void connect(java.lang.String cluster_name) throws java.lang.Exception
public void connect(java.lang.String cluster_name, Address target, long timeout) throws java.lang.Exception
Channel
This method essentially invokes
If the channel is closed an exception will be thrown.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.
connect
在类中 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.java.lang.Exception
- Connecting to the cluster or state transfer was not successfuljava.lang.IllegalStateException
- The channel is closed and therefore cannot be usedpublic void disconnect()
disconnect
在类中 JChannel
Channel.connect(String)
public void close()
public java.lang.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 java.lang.Exception
Channel
null
address sends the message to all
group members.
public void startFlush(java.util.List<Address> flushParticipants, boolean automatic_resume) throws java.lang.Exception
Channel
Channel.stopFlush(List)
method with the same list of members used in
Channel.startFlush(List, boolean)
.startFlush
在类中 JChannel
automatic_resume
- if true call Channel.stopFlush()
after the flushjava.lang.Exception
Channel.startFlush(boolean)
,
Util.startFlush(Channel, List, int, long, long)
public void startFlush(boolean automatic_resume) throws java.lang.Exception
Channel
Channel.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.startFlush
在类中 JChannel
automatic_resume
- if true call Channel.stopFlush()
after the flushjava.lang.Exception
Util.startFlush(Channel, List, int, long, long)
public void stopFlush()
Channel
public void stopFlush(java.util.List<Address> flushParticipants)
Channel
It is an obligation of the application to invoke the matching
Channel.startFlush(List, boolean)
method with the same list of members prior to invocation of
this method.
public void getState(Address target, long timeout) throws java.lang.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
在类中 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 receivedjava.lang.IllegalStateException
- The channel was closed or disconnected, or the flush (if present) failedStateTransferException
- raised if there was a problem during the state transferjava.lang.Exception
MessageListener.getState(java.io.OutputStream)
,
MessageListener.setState(java.io.InputStream)
public void addAddressGenerator(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.addAddressGenerator
在类中 JChannel
protected void setLocalAddress(Address local_addr)
protected static FORK getFORK(Channel ch, int position, java.lang.Class<? extends Protocol> neighbor, boolean create_fork_if_absent) throws java.lang.Exception
java.lang.Exception
protected static ForkProtocolStack getForkStack(Protocol prot)
protected void setHeader(Message msg)
protected void copyFields()
protected void nullFields()