public class JChannel extends Object implements Closeable
Receiver
in setReceiver(Receiver)
and implementing the MessageListener.receive(Message)
callback,
or extending ReceiverAdapter
and overriding the ReceiverAdapter.receive(Message)
method.Modifier and Type | Class and Description |
---|---|
static class |
JChannel.State |
Modifier and Type | Field and Description |
---|---|
protected List<AddressGenerator> |
address_generators |
protected Set<ChannelListener> |
channel_listeners |
protected String |
cluster_name |
protected boolean |
discard_own_messages |
protected boolean |
flush_supported |
protected Address |
local_addr |
protected Log |
log |
protected String |
name |
protected DiagnosticsHandler.ProbeHandler |
probe_handler |
protected ProtocolStack |
prot_stack |
protected long |
received_bytes |
protected long |
received_msgs |
protected Receiver |
receiver |
protected long |
sent_bytes |
protected long |
sent_msgs |
protected JChannel.State |
state |
protected Promise<StateTransferResult> |
state_promise |
protected boolean |
state_transfer_supported |
protected boolean |
stats |
protected UpHandler |
up_handler |
protected View |
view |
Constructor and Description |
---|
JChannel()
Creates a
JChannel with the default stack |
JChannel(boolean create_protocol_stack)
Creates a JChannel without a protocol stack; used for programmatic creation of channel and protocol stack
|
JChannel(Collection<Protocol> protocols)
Deprecated.
Use
JChannel(List) instead |
JChannel(Element properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified XML element.
|
JChannel(File file)
Constructs a JChannel instance with the protocol stack configuration contained in 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(List<Protocol> protocols)
Creates a channel from a list of protocols.
|
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(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 JChannel |
_close(boolean disconnect) |
protected JChannel |
_connect(Event connect_event) |
protected boolean |
_preConnect(String cluster_name) |
JChannel |
addAddressGenerator(AddressGenerator address_generator)
Sets the new
AddressGenerator . |
JChannel |
addChannelListener(ChannelListener listener)
Adds a ChannelListener that will be notified when a connect, disconnect or close occurs
|
Address |
address() |
protected JChannel |
checkClosed() |
protected JChannel |
checkClosedOrNotConnected() |
JChannel |
clearChannelListeners() |
void |
close()
Destroys the channel and its associated resources (e.g.
|
String |
clusterName() |
JChannel |
connect(String cluster_name)
Joins the cluster.
|
JChannel |
connect(String cluster_name,
Address target,
long timeout)
Joins the cluster and gets the state from a specified state provider.
|
JChannel |
connect(String cluster_name,
Address target,
long timeout,
boolean useFlushIfPresent)
Joins the cluster 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.
If the channel is closed a ChannelClosed exception will be thrown. |
protected JChannel |
connect(String cluster_name,
boolean useFlushIfPresent)
Connects the channel to a cluster.
|
protected Address |
determineCoordinator() |
JChannel |
disconnect()
Leaves the cluster (disconnects the channel if it is connected).
|
Object |
down(Event evt)
Sends an event down the protocol stack.
|
Object |
down(Message msg) |
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) |
boolean |
flushSupported() |
protected Address |
generateAddress() |
Address |
getAddress() |
String |
getAddressAsString() |
String |
getAddressAsUUID() |
String |
getClusterName() |
boolean |
getDiscardOwnMessages() |
String |
getName() |
String |
getProperties()
Returns the protocol stack configuration in string format.
|
ProtocolStack |
getProtocolStack() |
long |
getReceivedBytes() |
long |
getReceivedMessages() |
Receiver |
getReceiver() |
long |
getSentBytes() |
long |
getSentMessages() |
String |
getState() |
JChannel |
getState(Address target,
long timeout)
Retrieves the full state from the target member.
|
JChannel |
getState(Address target,
long timeout,
boolean useFlushIfPresent)
Retrieves state from the target member.
|
protected JChannel |
getState(Address target,
long timeout,
Callable<Boolean> flushInvoker) |
boolean |
getStats() |
protected TimeScheduler |
getTimer() |
UpHandler |
getUpHandler() |
static String |
getVersion() |
View |
getView() |
String |
getViewAsString() |
protected JChannel |
init()
Initializes all variables.
|
protected JChannel |
init(JChannel ch) |
protected JChannel |
init(ProtocolStackConfigurator configurator) |
protected Object |
invokeCallback(int type,
Object arg) |
boolean |
isClosed() |
boolean |
isConnected() |
boolean |
isConnecting() |
boolean |
isOpen() |
String |
name() |
JChannel |
name(String name) |
protected JChannel |
notifyChannelClosed(JChannel c) |
protected JChannel |
notifyChannelConnected(JChannel c) |
protected JChannel |
notifyChannelDisconnected(JChannel c) |
protected JChannel |
notifyListeners(Consumer<ChannelListener> func,
String msg) |
String |
printProtocolSpec(boolean include_props)
Dumps all protocols in string format.
|
JChannel |
receiver(Receiver r) |
boolean |
removeAddressGenerator(AddressGenerator address_generator) |
JChannel |
removeChannelListener(ChannelListener listener) |
JChannel |
resetStats() |
JChannel |
send(Address dst,
byte[] buf)
Sends a message.
|
JChannel |
send(Address dst,
byte[] buf,
int offset,
int length)
Sends a message to a destination.
|
JChannel |
send(Address dst,
Object obj)
Helper method to create a Message with given parameters and invoke
send(Message) . |
JChannel |
send(Message msg)
Sends a message.
|
protected JChannel |
setAddress()
Generates and sets local_addr.
|
JChannel |
setDiscardOwnMessages(boolean flag) |
JChannel |
setName(String name)
Sets the logical name for the channel.
|
JChannel |
setReceiver(Receiver r) |
JChannel |
setStats(boolean stats) |
JChannel |
setUpHandler(UpHandler h) |
ProtocolStack |
stack() |
JChannel |
startFlush(boolean automatic_resume)
Performs the flush of the cluster, ie.
|
JChannel |
startFlush(List<Address> flushParticipants,
boolean automatic_resume)
Performs the flush of the cluster but only for the specified flush participants.
All pending messages are flushed out but only for the flush participants.
|
protected JChannel |
startStack(String cluster_name) |
boolean |
stats() |
JChannel |
stats(boolean stats) |
JChannel |
stopFlush()
Stops the current flush round.
|
JChannel |
stopFlush(List<Address> flushParticipants)
Stops the current flush of the cluster for the specified flush participants.
|
protected JChannel |
stopStack(boolean stop,
boolean destroy) |
String |
toString(boolean details) |
Object |
up(Event evt)
Callback method
Called by the ProtocolStack when a message is received. |
Object |
up(Message msg) |
JChannel |
up(MessageBatch batch)
Callback invoked by the protocol stack to deliver a message batch
|
View |
view() |
protected Receiver receiver
protected Address local_addr
protected String name
protected String cluster_name
protected View view
protected volatile JChannel.State state
protected ProtocolStack prot_stack
protected UpHandler up_handler
protected Set<ChannelListener> channel_listeners
protected final Log log
protected List<AddressGenerator> address_generators
protected final Promise<StateTransferResult> state_promise
protected boolean state_transfer_supported
protected volatile boolean flush_supported
protected final DiagnosticsHandler.ProbeHandler probe_handler
protected long sent_msgs
protected long received_msgs
protected long sent_bytes
protected long received_bytes
protected boolean stats
protected boolean discard_own_messages
public JChannel(boolean create_protocol_stack)
create_protocol_stack
- If true, the default config is used. If false, no protocol stack is createdpublic JChannel() throws Exception
JChannel
with the default stackException
public JChannel(File file) throws Exception
file
- A file containing a JGroups XML protocol stack configuration.Exception
public JChannel(Element properties) throws Exception
properties
- An XML element containing a JGroups XML protocol stack configuration.Exception
public JChannel(URL properties) throws Exception
properties
- A URL pointing to a JGroups XML protocol stack configuration.Exception
public JChannel(String props) throws Exception
props
- A file containing a JGroups XML configuration or a URL pointing to an XML configurationException
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
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
@Deprecated public JChannel(Collection<Protocol> protocols) throws Exception
JChannel(List)
insteadclose()
, 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 JChannel(List<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 Receiver getReceiver()
public Address getAddress()
public Address address()
public String getName()
public String name()
public String clusterName()
public View getView()
public View view()
public ProtocolStack getProtocolStack()
public ProtocolStack stack()
public UpHandler getUpHandler()
public boolean getStats()
public boolean stats()
public JChannel setStats(boolean stats)
public JChannel stats(boolean stats)
public boolean getDiscardOwnMessages()
public JChannel setDiscardOwnMessages(boolean flag)
public boolean flushSupported()
public String getAddressAsString()
public String getAddressAsUUID()
public JChannel setName(String name)
public String getClusterName()
public String getViewAsString()
public String getState()
public boolean isOpen()
public boolean isConnected()
public boolean isConnecting()
public boolean isClosed()
public long getSentMessages()
public long getSentBytes()
public long getReceivedMessages()
public long getReceivedBytes()
public static String getVersion()
public JChannel addChannelListener(ChannelListener listener)
public JChannel removeChannelListener(ChannelListener listener)
public JChannel clearChannelListeners()
public JChannel 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 String getProperties()
"UDP:PING:FDALL:STABLE:NAKACK2:UNICAST3:FRAG2:GMS"
public JChannel resetStats()
public String printProtocolSpec(boolean include_props)
public Map<String,Object> dumpStats()
public JChannel connect(String cluster_name) throws Exception
cluster_name
- The name of the cluster to joinException
- The protocol stack cannot be startedIllegalStateException
- The channel is closedprotected JChannel connect(String cluster_name, boolean useFlushIfPresent) throws Exception
Exception
public JChannel connect(String cluster_name, Address target, long timeout) throws Exception
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.
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 JChannel 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 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 JChannel disconnect()
connect(String)
public void close()
ChannelClosed
exception (or results in a null operation).
It is a no-op if the channel is already closed.
If the channel is connected to a cluster, disconnect()
will be called first.close
in interface Closeable
close
in interface AutoCloseable
public JChannel send(Message msg) throws Exception
null
address sends the message to all cluster members.
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 JChannel send(Address dst, Object obj) throws Exception
send(Message)
.dst
- destination address for the message. If null, the message will be sent to all cluster 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 JChannel send(Address dst, byte[] buf) throws Exception
send(Address,byte[],int,int)
for detailsdst
- destination address for the message. If null, the message will be sent to all cluster membersbuf
- buffer message payloadException
- exception thrown if the message sending was not successfulpublic JChannel send(Address dst, byte[] buf, int offset, int length) throws Exception
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
- thrown if send() failedpublic JChannel getState(Address target, long timeout) throws Exception
The state transfer is initiated by invoking getState() on this channel. The state provider in turn invokes the
StateListener.getState(java.io.OutputStream)
callback and sends the state to this node, the state receiver.
After the state arrives at the state receiver, the StateListener.setState(java.io.InputStream)
callback
is invoked to install the state.
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 forever 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
StateListener.getState(java.io.OutputStream)
,
StateListener.setState(java.io.InputStream)
public JChannel getState(Address target, long timeout, boolean useFlushIfPresent) throws Exception
getState(Address,long)
for detailsException
public JChannel startFlush(boolean automatic_resume) throws Exception
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.automatic_resume
- if true call stopFlush()
after the flushException
public JChannel startFlush(List<Address> flushParticipants, boolean automatic_resume) throws Exception
stopFlush(List)
method with the same list of members used in startFlush(List, boolean)
.automatic_resume
- if true call stopFlush()
after the flushException
public JChannel stopFlush()
public JChannel stopFlush(List<Address> flushParticipants)
startFlush(List, boolean)
method with the
same list of members prior to invocation of this method.flushParticipants
- the flush participantspublic Object down(Event evt)
send(Message)
, if the event is a message,
no checks are performed whether the channel is closed or disconnected. Note that this method is not typically
used by applications.evt
- the message to send down, encapsulated in an eventpublic Object up(Event evt)
evt
- the event carrying the message from the protocol stackpublic JChannel up(MessageBatch batch)
public String toString(boolean details)
protected JChannel getState(Address target, long timeout, Callable<Boolean> flushInvoker) throws Exception
Exception
protected final JChannel init(ProtocolStackConfigurator configurator) throws Exception
Exception
protected JChannel init()
protected JChannel setAddress()
protected Address generateAddress()
protected JChannel checkClosed()
protected JChannel checkClosedOrNotConnected()
protected JChannel _close(boolean disconnect)
protected JChannel stopStack(boolean stop, boolean destroy)
protected Address determineCoordinator()
protected TimeScheduler getTimer()
protected JChannel notifyListeners(Consumer<ChannelListener> func, String msg)
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.