|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.Channel
public abstract class Channel
A channel represents a group communication endpoint (like BSD datagram sockets). A client joins a group by connecting the channel to a group and leaves it by disconnecting. Messages sent over the channel are received by all group members that are connected to the same group (that is, all members that have the same group name).
The FSM for a channel is roughly as follows: a channel is created (unconnected). The channel is connected to a group (connected). Messages can now be sent and received. The channel is disconnected from the group (unconnected). The channel could now be connected to a different group again. The channel is closed (closed). Only a single sender is allowed to be connected to a channel at a time, but there can be more than one channel in an application. Messages can be sent to the group members using the send method and messages can be received setting aReceiver
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
Nested Class Summary | |
---|---|
static class |
Channel.State
|
Field Summary | |
---|---|
protected java.util.Set<ChannelListener> |
channel_listeners
|
protected boolean |
discard_own_messages
|
protected Receiver |
receiver
|
protected SocketFactory |
socket_factory
|
protected Channel.State |
state
The current state of the channel |
protected UpHandler |
up_handler
|
Constructor Summary | |
---|---|
Channel()
|
Method Summary | |
---|---|
void |
addChannelListener(ChannelListener listener)
Adds a ChannelListener instance that will be notified when a channel event such as connect, disconnect or close occurs. |
void |
clearChannelListeners()
Clears all installed ChannelListener instances |
abstract void |
close()
Destroys the channel and its associated resources (e.g., the protocol stack). |
abstract void |
connect(java.lang.String cluster_name)
Connects the channel to a group. |
abstract 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. |
abstract void |
disconnect()
Disconnects the channel if it is connected. |
java.lang.Object |
down(Event evt)
Enables access to event mechanism of a channel and is normally not used by clients directly. |
abstract java.util.Map<java.lang.String,java.lang.Object> |
dumpStats()
Returns a map of statistics of the various protocols and of the channel itself. |
abstract boolean |
flushSupported()
|
abstract Address |
getAddress()
Returns the channel's own address. |
abstract java.lang.String |
getClusterName()
Returns the cluster name of the group of which the channel is a member. |
boolean |
getDiscardOwnMessages()
Returns true if this channel will discard its own messages, false otherwise |
protected abstract Log |
getLog()
|
abstract java.lang.String |
getName()
Returns the logical name of this channel if set. |
abstract java.lang.String |
getName(Address member)
Returns the logical name of a given member. |
java.lang.String |
getProperties()
|
abstract ProtocolStack |
getProtocolStack()
|
Receiver |
getReceiver()
Returns a receiver for this channel if it has been installed using setReceiver(Receiver) , null otherwise |
SocketFactory |
getSocketFactory()
|
java.lang.String |
getState()
|
abstract void |
getState(Address target,
long timeout)
Retrieves the full state from the target member. |
UpHandler |
getUpHandler()
Returns UpHandler installed for this channel |
abstract View |
getView()
Gets the current view. |
boolean |
isClosed()
Determines whether the channel is in the closed state. |
boolean |
isConnected()
Determines whether the channel is connected to a group. |
boolean |
isConnecting()
Determines whether the channel is in the connecting state; this means connect(String) has been
called, but hasn't returned yet |
boolean |
isOpen()
Determines whether the channel is open; ie. |
protected void |
notifyChannelClosed(Channel c)
|
protected void |
notifyChannelConnected(Channel c)
|
protected void |
notifyChannelDisconnected(Channel c)
|
void |
removeChannelListener(ChannelListener listener)
Removes a ChannelListener previously installed |
abstract void |
send(Address dst,
byte[] buf)
Sends a message. |
abstract void |
send(Address dst,
byte[] buf,
int offset,
int length)
Sends a message to a destination. |
abstract void |
send(Address dst,
java.lang.Object obj)
Helper method to create a Message with given parameters and invoke send(Message) . |
abstract void |
send(Message msg)
Sends a message. |
void |
setDiscardOwnMessages(boolean flag)
When set to true, all messages sent by a member A will be discarded by A. |
abstract void |
setName(java.lang.String name)
Sets the logical name for the channel. |
void |
setReceiver(Receiver r)
Sets the receiver for this channel. |
void |
setSocketFactory(SocketFactory factory)
|
void |
setUpHandler(UpHandler up_handler)
Sets this channel event handler to be a recipient off all events . |
abstract void |
startFlush(boolean automatic_resume)
Will perform a flush of the system, ie. |
abstract void |
startFlush(java.util.List<Address> flushParticipants,
boolean automatic_resume)
Performs a partial flush in a cluster for flush participants. |
abstract void |
stopFlush()
|
abstract void |
stopFlush(java.util.List<Address> flushParticipants)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected volatile Channel.State state
protected UpHandler up_handler
protected java.util.Set<ChannelListener> channel_listeners
protected Receiver receiver
protected SocketFactory socket_factory
protected boolean discard_own_messages
Constructor Detail |
---|
public Channel()
Method Detail |
---|
public java.lang.String getState()
protected abstract Log getLog()
public abstract ProtocolStack getProtocolStack()
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
public abstract void connect(java.lang.String cluster_name) throws java.lang.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.
java.lang.Exception
- The protocol stack cannot be started
java.lang.IllegalStateException
- The channel is closedpublic abstract void connect(java.lang.String cluster_name, Address target, long timeout) throws java.lang.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.
- Parameters:
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.
- Throws:
java.lang.Exception
- Connecting to the cluster or state transfer was not successful
java.lang.IllegalStateException
- The channel is closed and therefore cannot be used
public abstract void disconnect()
connect(String)
public abstract 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.
public boolean isOpen()
public boolean isConnected()
public boolean isConnecting()
connect(String)
has been
called, but hasn't returned yet
public boolean isClosed()
public abstract java.util.Map<java.lang.String,java.lang.Object> dumpStats()
public abstract void send(Message msg) throws java.lang.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.
java.lang.IllegalStateException
- thrown if the channel is disconnected or closed
java.lang.Exception
public abstract void send(Address dst, java.lang.Object obj) throws java.lang.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 thrown
java.lang.Exception
- exception thrown if message sending was not successfulpublic abstract void send(Address dst, byte[] buf) throws java.lang.Exception
send(Address,byte[],int,int)
for details
dst
- destination address for message. If null, message will be sent to all current group
membersbuf
- buffer message payload
java.lang.Exception
- exception thrown if message sending was not successfulpublic abstract void send(Address dst, byte[] buf, int offset, int length) throws java.lang.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
java.lang.Exception
- If send() failedpublic java.lang.Object down(Event evt)
sends
- an Event to a specific protocol layer and receive a response.
public abstract 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 abstract Address getAddress()
send()
operation.
public abstract java.lang.String getName()
public abstract java.lang.String getName(Address member)
member
-
member
public abstract void setName(java.lang.String name)
name
- public abstract java.lang.String getClusterName()
connect()
. Calling this method on a closed channel
returns null
.
public java.lang.String getProperties()
public void setUpHandler(UpHandler up_handler)
the
- 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 otherwise
public void setDiscardOwnMessages(boolean flag)
flag
- public boolean getDiscardOwnMessages()
public abstract boolean flushSupported()
public abstract void startFlush(java.util.List<Address> flushParticipants, boolean automatic_resume) throws java.lang.Exception
automatic_resume
- if true call stopFlush()
after the flush
java.lang.Exception
startFlush(boolean)
public abstract void startFlush(boolean automatic_resume) throws java.lang.Exception
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.
automatic_resume
- if true call stopFlush()
after the flush
java.lang.Exception
public abstract void stopFlush()
public abstract void stopFlush(java.util.List<Address> flushParticipants)
public abstract void getState(Address target, long timeout) throws java.lang.Exception
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.
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 received
java.lang.IllegalStateException
- The channel was closed or disconnected, or the flush (if present) failed
StateTransferException
- raised if there was a problem during the state transfer
java.lang.Exception
MessageListener.getState(java.io.OutputStream)
,
MessageListener.setState(java.io.InputStream)
protected void notifyChannelConnected(Channel c)
protected void notifyChannelDisconnected(Channel c)
protected void notifyChannelClosed(Channel c)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |