JChannel
instead@Deprecated public class Channel extends Object implements Closeable
Receiver
in setReceiver(Receiver)
and implementing the
MessageListener.receive(Message)
callback.
A channel instance is created using the public constructor.
Various degrees of sophistication in message exchange can be achieved using building blocks on top of channels; e.g., light-weight groups, synchronous message invocation, or remote method calls. Channels are on the same abstraction level as sockets, and should really be simple to use. Higher-level abstractions are all built on top of channels.DatagramPacket
,
MulticastSocket
,
JChannel
Modifier and Type | Class and Description |
---|---|
static class |
Channel.State
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
addChannelListener(ChannelListener listener)
Deprecated.
Adds a ChannelListener instance that will be notified when a channel event such as connect,
disconnect or close occurs.
|
void |
clearChannelListeners()
Deprecated.
Clears all installed ChannelListener instances
|
void |
close()
Deprecated.
Destroys the channel and its associated resources (e.g., the protocol stack).
|
void |
connect(String cluster_name)
Deprecated.
Connects the channel to a group.
|
void |
connect(String cluster_name,
Address target,
long timeout)
Deprecated.
Connects this channel to a group and gets a state from a specified state provider.
|
void |
disconnect()
Deprecated.
Disconnects the channel if it is connected.
|
Object |
down(Event evt)
Deprecated.
Enables access to event mechanism of a channel and is normally not used by clients directly.
|
Map<String,Object> |
dumpStats()
Deprecated.
Returns a map of statistics of the various protocols and of the channel itself.
|
boolean |
flushSupported()
Deprecated.
|
Address |
getAddress()
Deprecated.
Returns the channel's own address.
|
String |
getClusterName()
Deprecated.
Returns the cluster name of the group of which the channel is a member.
|
boolean |
getDiscardOwnMessages()
Deprecated.
Returns true if this channel will discard its own messages, false otherwise
|
String |
getName()
Deprecated.
Returns the logical name of this channel if set.
|
String |
getName(Address member)
Deprecated.
Returns the logical name of a given member.
|
String |
getProperties()
Deprecated.
|
ProtocolStack |
getProtocolStack()
Deprecated.
|
Receiver |
getReceiver()
Deprecated.
Returns a receiver for this channel if it has been installed using
setReceiver(Receiver) , null otherwise |
SocketFactory |
getSocketFactory()
Deprecated.
|
String |
getState()
Deprecated.
|
void |
getState(Address target,
long timeout)
Deprecated.
Retrieves the full state from the target member.
|
UpHandler |
getUpHandler()
Deprecated.
Returns UpHandler installed for this channel
|
View |
getView()
Deprecated.
Gets the current view.
|
boolean |
isClosed()
Deprecated.
Determines whether the channel is in the closed state.
|
boolean |
isConnected()
Deprecated.
Determines whether the channel is connected to a group.
|
boolean |
isConnecting()
Deprecated.
Determines whether the channel is in the connecting state; this means
connect(String) has been
called, but hasn't returned yet |
boolean |
isOpen()
Deprecated.
Determines whether the channel is open; ie.
|
Channel |
name(String name)
Deprecated.
Names a channel, same as
setName(String) |
void |
removeChannelListener(ChannelListener listener)
Deprecated.
Removes a ChannelListener previously installed
|
void |
send(Address dst,
byte[] buf)
Deprecated.
Sends a message.
|
void |
send(Address dst,
byte[] buf,
int offset,
int length)
Deprecated.
Sends a message to a destination.
|
void |
send(Address dst,
Object obj)
Deprecated.
Helper method to create a Message with given parameters and invoke
send(Message) . |
void |
send(Message msg)
Deprecated.
Sends a message.
|
void |
setDiscardOwnMessages(boolean flag)
Deprecated.
When set to true, all messages sent by a member A will be discarded by A.
|
void |
setName(String name)
Deprecated.
Sets the logical name for the channel.
|
void |
setReceiver(Receiver r)
Deprecated.
Sets the receiver for this channel.
|
void |
setSocketFactory(SocketFactory factory)
Deprecated.
|
void |
setUpHandler(UpHandler up_handler)
Deprecated.
Sets this channel event handler to be a recipient off all events .
|
void |
startFlush(boolean automatic_resume)
Deprecated.
Performs the flush of the cluster, ie.
|
void |
startFlush(List<Address> flushParticipants,
boolean automatic_resume)
Deprecated.
Performs the flush of the cluster but only for the specified flush participants.
|
void |
stopFlush()
Deprecated.
Stops the current flush of the cluster.
|
void |
stopFlush(List<Address> flushParticipants)
Deprecated.
Stops the current flush of the cluster for the specified flush participants.
|
protected final JChannel ch
public Channel(JChannel ch)
public String getState()
public ProtocolStack getProtocolStack()
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
public void connect(String cluster_name) throws Exception
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.
cluster_name
- The name of the channel to connect to.Exception
- The protocol stack cannot be startedIllegalStateException
- The channel is closedpublic void 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 void disconnect()
connect(String)
public void close()
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.
close
in interface Closeable
close
in interface AutoCloseable
public boolean isOpen()
public boolean isConnected()
public boolean isConnecting()
connect(String)
has been
called, but hasn't returned yetpublic boolean isClosed()
public Map<String,Object> dumpStats()
public void send(Message msg) throws Exception
null
address sends the message to all
group 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 void send(Address dst, Object obj) throws Exception
send(Message)
.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
send(Address,byte[],int,int)
for detailsdst
- destination address for message. If null, message will be sent to all current group
membersbuf
- buffer message payloadException
- exception thrown if message sending was not successfulpublic void send(Address dst, byte[] buf, int offset, int length) throws Exception
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 Object down(Event evt)
evt
- sends an Event to a specific protocol layer and receives a response.public View getView()
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 Address getAddress()
send()
operation.public String getName()
public String getName(Address member)
member
- member
public void setName(String name)
name
- public Channel name(String name)
setName(String)
public String getClusterName()
connect()
. Calling this method on a closed channel
returns null
.public String getProperties()
public void setUpHandler(UpHandler up_handler)
up_handler
- handler to handle channel eventspublic UpHandler getUpHandler()
public void addChannelListener(ChannelListener listener)
listener
- to be notifiedpublic void removeChannelListener(ChannelListener listener)
listener
- to be removedpublic void clearChannelListeners()
public void setReceiver(Receiver r)
r
- the receiver instance for this channelReceiver
public Receiver getReceiver()
setReceiver(Receiver)
, null otherwisepublic void setDiscardOwnMessages(boolean flag)
flag
- public boolean getDiscardOwnMessages()
public boolean flushSupported()
public void 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
startFlush(boolean)
,
Util#startFlush(Channel, List, int, long, long)
public void 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
Util#startFlush(Channel, List, int, long, long)
public void stopFlush()
startFlush(boolean)
,
startFlush(List, boolean)
public void stopFlush(List<Address> flushParticipants)
It is an obligation of the application to invoke the matching
startFlush(List, boolean)
method with the same list of members prior to invocation of
this method.
flushParticipants
- the flush participantspublic void getState(Address target, long timeout) throws Exception
State transfer is initiated by invoking getState on this channel. The state provider in turn
invokes StateListener.getState(java.io.OutputStream)
callback and sends a state to
this node, the state receiver. After the state arrives to the state receiver
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 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)
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.