org.jgroups
public class JChannel extends Channel
Channel.State
Modifier and Type | Field and Description |
---|---|
protected AddressGenerator |
address_generator |
protected String |
cluster_name |
protected ConcurrentMap<String,Object> |
config |
static 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 Log |
log |
protected View |
my_view |
protected 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, 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(Element properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified XML element.
|
JChannel(File properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified file.
|
JChannel(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 a list of protocols.
|
JChannel(ProtocolStackConfigurator configurator)
Constructs a JChannel with the protocol stack configuration contained by the protocol stack configurator parameter.
|
JChannel(String props)
Constructs a JChannel instance with the protocol stack configuration based upon the specified properties parameter.
|
JChannel(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(String cluster_name) |
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(String cluster_name)
Connects the channel to a group.
|
void |
connect(String cluster_name,
Address target,
long timeout)
Connects this channel to a group and gets a state from a specified state provider.
|
void |
connect(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() |
protected void |
connect(String cluster_name,
boolean useFlushIfPresent)
Connects the channel to a group.
|
void |
disconnect()
Disconnects the channel if it is connected.
|
Object |
down(Event evt)
Sends an event down the protocol stack.
|
protected Map<String,Long> |
dumpChannelStats() |
Map<String,Object> |
dumpStats()
Returns a map of statistics of the various protocols and of the channel itself.
|
Map<String,Object> |
dumpStats(String protocol_name) |
Map<String,Object> |
dumpStats(String protocol_name,
List<String> attrs) |
String |
dumpTimerQueue() |
void |
enableStats(boolean stats) |
boolean |
flushSupported() |
Address |
getAddress()
Returns the channel's own address.
|
String |
getAddressAsString() |
String |
getAddressAsUUID() |
AddressGenerator |
getAddressGenerator()
Returns the current
AddressGenerator , or null if none is set |
String |
getClusterName()
Returns the cluster name of the group of which the channel is a member.
|
protected Log |
getLog() |
String |
getName()
Returns the logical name of this channel if set.
|
String |
getName(Address member)
Returns the logical name of a given member.
|
int |
getNumberOfTasksInTimer() |
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,
Callable<Boolean> flushInvoker) |
protected TimeScheduler |
getTimer() |
int |
getTimerThreads() |
static String |
getVersion() |
View |
getView()
Gets the current view.
|
String |
getViewAsString() |
protected void |
init()
Initializes all variables.
|
protected void |
init(JChannel ch) |
protected void |
init(ProtocolStackConfigurator configurator) |
protected Object |
invokeCallback(int type,
Object arg) |
boolean |
isConnected()
Deprecated.
|
boolean |
isOpen()
Deprecated.
|
JChannel |
name(String name) |
String |
printProtocolSpec(boolean include_properties)
Returns a pretty-printed form of all the protocols.
|
JChannel |
receiver(Receiver r) |
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,
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)
Sets the new
AddressGenerator . |
void |
setName(String name)
Sets the logical name for the channel.
|
void |
setProtocolStack(ProtocolStack stack) |
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.
|
protected void |
startStack(String cluster_name) |
boolean |
statsEnabled() |
void |
stopFlush() |
void |
stopFlush(List<Address> flushParticipants) |
protected void |
stopStack(boolean stop,
boolean destroy) |
String |
toString(boolean details) |
Object |
up(Event evt)
Callback method
Called by the ProtocolStack when a message is received. |
addChannelListener, clearChannelListeners, getDiscardOwnMessages, getReceiver, getSocketFactory, getState, getUpHandler, isClosed, isConnecting, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, removeChannelListener, setDiscardOwnMessages, setReceiver, setSocketFactory, setUpHandler
public static final String DEFAULT_PROTOCOL_STACK
protected Address local_addr
protected AddressGenerator address_generator
protected String name
protected 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 ConcurrentMap<String,Object> config
protected final Log log
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 createdcreate_protocol_stack
- Creates the default stack if true, or no stack if falsepublic JChannel() throws Exception
JChannel
instance with the protocol stack
specified by the DEFAULT_PROTOCOL_STACK
member.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(File properties) throws Exception
properties
- A file containing a JGroups XML protocol stack configuration.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(Element properties) throws Exception
properties
- An XML element containing a JGroups XML protocol stack configuration.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(URL properties) throws Exception
properties
- A URL pointing to a JGroups XML protocol stack configuration.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(String props) throws Exception
props
- A file containing a JGroups XML configuration, a URL pointing to an XML configuration, or an old
style plain configuration string.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(InputStream input) throws Exception
input
- An input stream, pointing to a streamed configurationException
public JChannel(ProtocolStackConfigurator configurator) throws 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.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(Protocol... protocols) throws 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 protocolException
public ProtocolStack getProtocolStack()
getProtocolStack
in class Channel
public void setProtocolStack(ProtocolStack stack)
public String getProperties()
getProperties
in class Channel
public boolean statsEnabled()
public void enableStats(boolean stats)
@Deprecated public boolean isOpen()
Channel
@Deprecated public boolean isConnected()
Channel
isConnected
in class Channel
public void resetStats()
public long getSentMessages()
public long getSentBytes()
public long getReceivedMessages()
public long getReceivedBytes()
public int getNumberOfTasksInTimer()
public int getTimerThreads()
public String dumpTimerQueue()
public String printProtocolSpec(boolean include_properties)
public void connect(String cluster_name) throws 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.
connect
in class Channel
cluster_name
- The name of the channel to connect to.Exception
- The protocol stack cannot be startedIllegalStateException
- The channel is closedprotected void connect(String cluster_name, boolean useFlushIfPresent) throws Exception
Exception
connect(String)
public 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 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.Exception
- Connecting to the cluster or state transfer was not successfulIllegalStateException
- The channel is closed and therefore cannot be usedpublic void connect(String cluster_name, Address target, long timeout, boolean useFlushIfPresent) throws 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.Exception
- The protocol stack cannot be started, or the JOIN failedIllegalStateException
- 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 Map<String,Object> dumpStats()
Channel
public void send(Message msg) throws Exception
Channel
null
address sends the message to all
group members.
send
in class Channel
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 send(Address dst, Object obj) throws 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 thrownException
- exception thrown if message sending was not successfulpublic void send(Address dst, byte[] buf) throws Exception
Channel
Channel.send(Address,byte[],int,int)
for detailspublic void send(Address dst, byte[] buf, int offset, int length) throws 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
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 String getViewAsString()
public static String getVersion()
public Address getAddress()
Channel
send()
operation.getAddress
in class Channel
public String getAddressAsString()
public String getAddressAsUUID()
public String getName()
Channel
public String getName(Address member)
Channel
public void setName(String name)
Channel
public String getClusterName()
Channel
connect()
. Calling this method on a closed channel
returns null
.getClusterName
in class Channel
public AddressGenerator getAddressGenerator()
AddressGenerator
, or null if none is setpublic void setAddressGenerator(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 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 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 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 getState(Address target, long timeout, boolean useFlushIfPresent) throws Exception
getState(Address,long)
for details.Exception
protected void getState(Address target, long timeout, Callable<Boolean> flushInvoker) throws Exception
Exception
public Object up(Event evt)
evt
- the event carrying the message from the protocol stackpublic Object down(Event evt)
send(Message)
, if the event is a message,
no checks are performed whether the channel is closed or disconnected.public String toString(boolean details)
protected final void init(ProtocolStackConfigurator configurator) throws Exception
Exception
protected void init()
protected void setAddress()
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 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 Channel
automatic_resume
- if true call Channel.stopFlush()
after the flushException
public void startFlush(List<Address> flushParticipants, boolean automatic_resume) throws Exception
Channel
startFlush
in class Channel
automatic_resume
- if true call Channel.stopFlush()
after the flushException
Channel.startFlush(boolean)
protected TimeScheduler getTimer()
Copyright © 2015 JBoss, a division of Red Hat. All rights reserved.