public class JChannel extends Channel
Channel.State
Modifier and Type | Field and Description |
---|---|
protected java.util.List<AddressGenerator> |
address_generators |
protected java.lang.String |
cluster_name |
protected java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> |
config |
static java.lang.String |
DEFAULT_PROTOCOL_STACK
The default protocol stack used by the default constructor
|
protected boolean |
flush_supported
True if a flush protocol is available, false otherwise (set by CONFIG event from FLUSH protocol)
|
protected Address |
local_addr |
protected View |
my_view |
protected java.lang.String |
name |
protected DiagnosticsHandler.ProbeHandler |
probe_handler |
protected ProtocolStack |
prot_stack |
protected long |
received_bytes |
protected long |
received_msgs |
protected long |
sent_bytes |
protected long |
sent_msgs |
protected Promise<StateTransferResult> |
state_promise |
protected boolean |
state_transfer_supported
True if a state transfer protocol is available, false otherwise (set by CONFIG event from STATE_TRANSFER protocol)
|
protected boolean |
stats
Collect statistics
|
channel_listeners, discard_own_messages, log, receiver, socket_factory, state, up_handler
Constructor and Description |
---|
JChannel()
Constructs a
JChannel instance with the protocol stack
specified by the DEFAULT_PROTOCOL_STACK member. |
JChannel(boolean create_protocol_stack)
Creates a JChannel without a protocol stack; used for programmatic creation of channel and protocol stack
|
JChannel(java.util.Collection<Protocol> protocols)
Creates a channel from an array of protocols.
|
JChannel(org.w3c.dom.Element properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified XML element.
|
JChannel(java.io.File properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified file.
|
JChannel(java.io.InputStream input)
Creates a channel with a configuration based on an input stream.
|
JChannel(JChannel ch)
Creates a channel with the same configuration as the channel passed to this constructor.
|
JChannel(Protocol... protocols)
Creates a channel from an array of protocols.
|
JChannel(ProtocolStackConfigurator configurator)
Constructs a JChannel with the protocol stack configuration contained by the protocol stack configurator parameter.
|
JChannel(java.lang.String props)
Constructs a JChannel instance with the protocol stack configuration based upon the specified properties parameter.
|
JChannel(java.net.URL properties)
Constructs a JChannel instance with the protocol stack configuration indicated by the specified URL.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_close(boolean disconnect)
Disconnects and closes the channel.
|
protected void |
_connect(Event connect_event) |
protected boolean |
_preConnect(java.lang.String cluster_name) |
void |
addAddressGenerator(AddressGenerator address_generator)
Sets the new
AddressGenerator . |
protected void |
checkClosed()
health check
throws a ChannelClosed exception if the channel is closed |
protected void |
checkClosedOrNotConnected() |
void |
close()
Destroys the channel and its associated resources (e.g., the protocol stack).
|
void |
connect(java.lang.String cluster_name)
Connects the channel to a group.
|
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.
|
void |
connect(java.lang.String cluster_name,
Address target,
long timeout,
boolean useFlushIfPresent)
Connects this channel to a group and gets a state from a specified state provider.
This method invokes
connect() and then getState .
If the FLUSH protocol is in the channel's stack definition, only one flush round is executed for both connecting and
fetching the state rather than two flushes if we invoke connect and getState in succession. |
protected void |
connect(java.lang.String cluster_name,
boolean useFlushIfPresent)
Connects the channel to a group.
|
void |
disconnect()
Disconnects the channel if it is connected.
|
java.lang.Object |
down(Event evt)
Sends an event down the protocol stack.
|
protected java.util.Map<java.lang.String,java.lang.Long> |
dumpChannelStats() |
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats()
Returns a map of statistics of the various protocols and of the channel itself.
|
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name) |
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name,
java.util.List<java.lang.String> attrs) |
java.lang.String |
dumpTimerQueue() |
void |
enableStats(boolean stats) |
boolean |
flushSupported() |
protected Address |
generateAddress() |
Address |
getAddress()
Returns the channel's own address.
|
java.lang.String |
getAddressAsString() |
java.lang.String |
getAddressAsUUID() |
AddressGenerator |
getAddressGenerator()
Deprecated.
Doesn't make any sense as there's list of address generators, will be removed in 4.0
|
java.lang.String |
getClusterName()
Returns the cluster name of the group of which the channel is a member.
|
java.lang.String |
getName()
Returns the logical name of this channel if set.
|
java.lang.String |
getName(Address member)
Returns the logical name of a given member.
|
int |
getNumberOfTasksInTimer() |
java.lang.String |
getProperties()
Returns the protocol stack configuration in string format.
|
ProtocolStack |
getProtocolStack()
Returns the protocol stack
|
long |
getReceivedBytes() |
long |
getReceivedMessages() |
long |
getSentBytes() |
long |
getSentMessages() |
void |
getState(Address target,
long timeout)
Retrieves the full state from the target member.
|
void |
getState(Address target,
long timeout,
boolean useFlushIfPresent)
Retrieves state from the target member.
|
protected void |
getState(Address target,
long timeout,
java.util.concurrent.Callable<java.lang.Boolean> flushInvoker) |
protected TimeScheduler |
getTimer() |
int |
getTimerThreads() |
static java.lang.String |
getVersion() |
View |
getView()
Gets the current view.
|
java.lang.String |
getViewAsString() |
protected void |
init()
Initializes all variables.
|
protected void |
init(JChannel ch) |
protected void |
init(ProtocolStackConfigurator configurator) |
protected java.lang.Object |
invokeCallback(int type,
java.lang.Object arg) |
JChannel |
name(java.lang.String name)
Names a channel, same as
Channel.setName(String) |
java.lang.String |
printProtocolSpec(boolean include_properties)
Returns a pretty-printed form of all the protocols.
|
JChannel |
receiver(Receiver r) |
boolean |
removeAddressGenerator(AddressGenerator address_generator) |
void |
resetStats() |
void |
send(Address dst,
byte[] buf)
Sends a message.
|
void |
send(Address dst,
byte[] buf,
int offset,
int length)
Sends a message to a destination.
|
void |
send(Address dst,
java.lang.Object obj)
Helper method to create a Message with given parameters and invoke
Channel.send(Message) . |
void |
send(Message msg)
Sends a message.
|
protected void |
setAddress()
Generates new UUID and sets local address.
|
void |
setAddressGenerator(AddressGenerator address_generator)
Deprecated.
|
void |
setName(java.lang.String name)
Sets the logical name for the channel.
|
void |
setProtocolStack(ProtocolStack stack) |
void |
startFlush(boolean automatic_resume)
Performs the flush of the cluster, ie.
|
void |
startFlush(java.util.List<Address> flushParticipants,
boolean automatic_resume)
Performs the flush of the cluster but only for the specified flush participants.
|
protected void |
startStack(java.lang.String cluster_name) |
boolean |
statsEnabled() |
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.
|
protected void |
stopStack(boolean stop,
boolean destroy) |
java.lang.String |
toString(boolean details) |
java.lang.Object |
up(Event evt)
Callback method
Called by the ProtocolStack when a message is received. |
void |
up(MessageBatch batch)
Callback invoked by the protocol stack to deliver a message batch
|
addChannelListener, clearChannelListeners, getDiscardOwnMessages, getReceiver, getSocketFactory, getState, getUpHandler, isClosed, isConnected, isConnecting, isOpen, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, removeChannelListener, setDiscardOwnMessages, setReceiver, setSocketFactory, setUpHandler
public static final java.lang.String DEFAULT_PROTOCOL_STACK
protected Address local_addr
protected java.util.List<AddressGenerator> address_generators
protected java.lang.String name
protected java.lang.String cluster_name
protected View my_view
protected ProtocolStack prot_stack
protected final Promise<StateTransferResult> state_promise
protected boolean state_transfer_supported
protected volatile boolean flush_supported
protected final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> config
protected boolean stats
protected long sent_msgs
protected long received_msgs
protected long sent_bytes
protected long received_bytes
protected final DiagnosticsHandler.ProbeHandler probe_handler
public JChannel(boolean create_protocol_stack)
create_protocol_stack
- If true, the default configuration will be used. If false, no protocol stack
will be createdpublic JChannel() throws java.lang.Exception
JChannel
instance with the protocol stack
specified by the DEFAULT_PROTOCOL_STACK
member.java.lang.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(java.io.File properties) throws java.lang.Exception
properties
- A file containing a JGroups XML protocol stack configuration.java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(org.w3c.dom.Element properties) throws java.lang.Exception
properties
- An XML element containing a JGroups XML protocol stack configuration.java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.net.URL properties) throws java.lang.Exception
properties
- A URL pointing to a JGroups XML protocol stack configuration.java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.lang.String props) throws java.lang.Exception
props
- A file containing a JGroups XML configuration, a URL pointing to an XML configuration, or an old
style plain configuration string.java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.io.InputStream input) throws java.lang.Exception
input
- An input stream, pointing to a streamed configurationjava.lang.Exception
public JChannel(ProtocolStackConfigurator configurator) throws java.lang.Exception
All of the public constructors of this class eventually delegate to this method.
configurator
- A protocol stack configurator containing a JGroups protocol stack configuration.java.lang.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(Protocol... protocols) throws java.lang.Exception
close()
, the protocol
list should not be reused, ie. new JChannel(protocols) would reuse the same protocol list, and this
might lead to problems !protocols
- The list of protocols, from bottom to top, ie. the first protocol in the list is the transport,
the last the top protocoljava.lang.Exception
public JChannel(java.util.Collection<Protocol> protocols) throws java.lang.Exception
close()
, the protocol
list should not be reused, ie. new JChannel(protocols) would reuse the same protocol list, and this
might lead to problems !protocols
- The list of protocols, from bottom to top, ie. the first protocol in the list is the transport,
the last the top protocoljava.lang.Exception
public JChannel(JChannel ch) throws java.lang.Exception
ch
- java.lang.Exception
public ProtocolStack getProtocolStack()
getProtocolStack
in class Channel
public void setProtocolStack(ProtocolStack stack)
public java.lang.String getProperties()
getProperties
in class Channel
public boolean statsEnabled()
public void enableStats(boolean stats)
public void resetStats()
public long getSentMessages()
public long getSentBytes()
public long getReceivedMessages()
public long getReceivedBytes()
public int getNumberOfTasksInTimer()
public int getTimerThreads()
public java.lang.String dumpTimerQueue()
public java.lang.String printProtocolSpec(boolean include_properties)
public void connect(java.lang.String cluster_name) throws java.lang.Exception
Channel
All channels with the same name form a group, that means all messages sent to the group will be received by all channels connected to the same cluster name.
protected void connect(java.lang.String cluster_name, boolean useFlushIfPresent) throws java.lang.Exception
java.lang.Exception
connect(String)
public void connect(java.lang.String cluster_name, Address target, long timeout) throws java.lang.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 Channel
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 connect(java.lang.String cluster_name, Address target, long timeout, boolean useFlushIfPresent) throws java.lang.Exception
connect()
and then getState
.
If the FLUSH protocol is in the channel's stack definition, only one flush round is executed for both connecting and
fetching the state rather than two flushes if we invoke connect
and getState
in succession.
If the channel is already connected, an error message will be printed to the error log.
If the channel is closed a ChannelClosed exception will be thrown.cluster_name
- The cluster name to connect to. Cannot be null.target
- The state provider. If null, the state will be fetched from the coordinator, unless this channel
is the coordinator.timeout
- The timeout for the state transfer.java.lang.Exception
- The protocol stack cannot be started, or the JOIN failedjava.lang.IllegalStateException
- The channel is closed or disconnectedStateTransferException
- State transfer was not successfulpublic void disconnect()
Channel
disconnect
in class Channel
Channel.connect(String)
public void close()
Channel
ChannelClosed
exception (or
results in a null operation). It is a null operation if the channel is already closed.
If the channel is connected to a group, disconnect()
will be called first.
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
Channel
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name, java.util.List<java.lang.String> attrs)
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name)
protected java.util.Map<java.lang.String,java.lang.Long> dumpChannelStats()
public void send(Message msg) throws java.lang.Exception
Channel
null
address sends the message to all
group members.
public void send(Address dst, java.lang.Object obj) throws java.lang.Exception
Channel
Channel.send(Message)
.send
in class Channel
dst
- Destination address for message. If null, message will be sent to all current group
membersobj
- A serializable object. Will be marshalled into the byte buffer of the Message. If it
is not serializable, an exception will be thrownjava.lang.Exception
- exception thrown if message sending was not successfulpublic void send(Address dst, byte[] buf) throws java.lang.Exception
Channel
Channel.send(Address,byte[],int,int)
for detailspublic void send(Address dst, byte[] buf, int offset, int length) throws java.lang.Exception
Channel
send
in class Channel
dst
- The destination address. If null, the message will be sent to all cluster nodes (=
group members)buf
- The buffer to be sentoffset
- The offset into the bufferlength
- The length of the data to be sent. Has to be <= buf.length - offset. This will send
length
bytes starting at offset
java.lang.Exception
- If send() failedpublic View getView()
Channel
connect()
. The result of calling this method on an unconnected channel is
implementation defined (may return null). Calling this method on a closed channel returns a
null view.public java.lang.String getViewAsString()
public static java.lang.String getVersion()
public Address getAddress()
Channel
send()
operation.getAddress
in class Channel
public java.lang.String getAddressAsString()
public java.lang.String getAddressAsUUID()
public java.lang.String getName()
Channel
public java.lang.String getName(Address member)
Channel
public void setName(java.lang.String name)
Channel
public JChannel name(java.lang.String name)
Channel
Channel.setName(String)
public java.lang.String getClusterName()
Channel
connect()
. Calling this method on a closed channel
returns null
.getClusterName
in class Channel
@Deprecated public AddressGenerator getAddressGenerator()
AddressGenerator
in the list, or null if none is set@Deprecated public void setAddressGenerator(AddressGenerator address_generator)
addAddressGenerator(org.jgroups.stack.AddressGenerator)
insteadpublic void addAddressGenerator(AddressGenerator address_generator)
AddressGenerator
. New addresses will be generated using the new generator. This
should not be done while a channel is connected, but before connecting.address_generator
- public boolean removeAddressGenerator(AddressGenerator address_generator)
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
in class Channel
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 getState(Address target, long timeout, boolean useFlushIfPresent) throws java.lang.Exception
getState(Address,long)
for details.java.lang.Exception
protected boolean _preConnect(java.lang.String cluster_name) throws java.lang.Exception
java.lang.Exception
protected void _connect(Event connect_event) throws java.lang.Exception
java.lang.Exception
protected void getState(Address target, long timeout, java.util.concurrent.Callable<java.lang.Boolean> flushInvoker) throws java.lang.Exception
java.lang.Exception
public java.lang.Object up(Event evt)
evt
- the event carrying the message from the protocol stackpublic void up(MessageBatch batch)
public java.lang.Object down(Event evt)
send(Message)
, if the event is a message,
no checks are performed whether the channel is closed or disconnected.public java.lang.String toString(boolean details)
protected java.lang.Object invokeCallback(int type, java.lang.Object arg)
protected final void init(ProtocolStackConfigurator configurator) throws java.lang.Exception
java.lang.Exception
protected final void init(JChannel ch) throws java.lang.Exception
java.lang.Exception
protected void init()
protected void startStack(java.lang.String cluster_name) throws java.lang.Exception
java.lang.Exception
protected void setAddress()
protected Address generateAddress()
protected void checkClosed()
protected void checkClosedOrNotConnected()
protected void _close(boolean disconnect)
this.disconnect
if the disconnect parameter is true
ProtocolStack.stop
on the protocol stack
ProtocolStack.destroy
on the protocol stack
protected void stopStack(boolean stop, boolean destroy)
public boolean flushSupported()
flushSupported
in class Channel
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
in class Channel
automatic_resume
- if true call Channel.stopFlush()
after the flushjava.lang.Exception
Util.startFlush(Channel, List, int, long, long)
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
in class Channel
automatic_resume
- if true call Channel.stopFlush()
after the flushjava.lang.Exception
Channel.startFlush(boolean)
,
Util.startFlush(Channel, List, int, long, long)
public void stopFlush()
Channel
stopFlush
in class Channel
Channel.startFlush(boolean)
,
Channel.startFlush(List, boolean)
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.
protected TimeScheduler getTimer()
Copyright © 1998-2020 Red Hat. All Rights Reserved.