Class MuxChannel
- All Implemented Interfaces:
Transport
MuxChannel has to be created with a unique application id. The multiplexer keeps track of all registered applications and tags messages belonging to a specific application with that id for sent messages. When receiving a message from a remote peer, the multiplexer will dispatch a message to the appropriate MuxChannel depending on the id attached to the message.
MuxChannel is created using
ChannelFactory.createMultiplexerChannel(String, String)
.
- Since:
- 2.4
- Version:
- $Id: MuxChannel.java,v 1.38.2.14 2008/02/15 04:23:42 vlada Exp $
- Author:
- Bela Ban, Vladimir Blagojevic
- See Also:
-
Field Summary
Fields inherited from class org.jgroups.JChannel
additional_data, closed, closer, connected, DEFAULT_PROTOCOL_STACK, info, log, received_bytes, received_msgs, sent_bytes, sent_msgs, stats
Fields inherited from class org.jgroups.Channel
AUTO_GETSTATE, AUTO_RECONNECT, BLOCK, channel_listeners, GET_STATE_EVENTS, LOCAL, receiver, SUSPECT, up_handler, VIEW
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Destroys the channel.void
Connects the channel to a group.void
Connects this channel to a group and gets a state from a specified state provider.void
Disconnects the channel if it is connected.void
Sends a message through the protocol stack if the stack is availableCan be used instead of down() when a return value is expected.Returns a map of statistics of the various protocols and of the channel itself.This should never be used (just for testing) !returns the name of the channel if the channel is not connected or if it is closed it will return nullReturns the cluster name of the group of which the channel is a member.Returns the JGroups view of a cluster, e.g.getId()
returns the local address of the channel returns null if the channel is closedreturns the protocol stack configuration in string format.Returns the protocol stack.boolean
Retrieves a substate (or partial state) indicated by state_id from the target member.getView()
Returns the service view, ie.protected void
void
open()
Opens the channel.void
returnState
(byte[] state) Called by the application is response to receiving agetState()
object when callingreceive()
.void
returnState
(byte[] state, String state_id) Returns a substate as indicated by state_idvoid
send
(Address dst, Address src, Serializable obj) creates a new message with the destination address, and the source address and the object as the message valuevoid
Sends a message through the protocol stack.protected void
setClosed
(boolean f) protected void
setConnected
(boolean f) void
shutdown()
Shuts down the channel without disconnectingMethods inherited from class org.jgroups.JChannel
_close, blockOk, checkClosed, checkClosedOrNotConnected, closeMessageQueue, dumpChannelStats, dumpQueue, dumpStats, dumpTimerQueue, enableStats, flushSupported, getAllStates, getInfo, getLocalAddressAsString, getLog, getNumberOfTasksInTimer, getNumMessages, getOpt, getReceivedBytes, getReceivedMessages, getSentBytes, getSentMessages, getState, getState, getState, getTimerThreads, init, isConnected, isOpen, peek, printProtocolSpec, receive, resetStats, setInfo, setOpt, startFlush, startFlush, startFlush, statsEnabled, stopFlush, stopFlush, stopStack, toString, up
Methods inherited from class org.jgroups.Channel
addChannelListener, clearChannelListeners, getReceiver, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, notifyChannelReconnected, notifyChannelShunned, option2String, removeChannelListener, setChannelListener, setReceiver, setUpHandler
-
Method Details
-
getStackName
-
getId
-
getMultiplexer
-
getChannelName
Description copied from class:JChannel
returns the name of the channel if the channel is not connected or if it is closed it will return null- Overrides:
getChannelName
in classJChannel
- Returns:
- The group address
-
getClusterName
Description copied from class:Channel
Returns the cluster name of the group of which the channel is a member. This is the object that was the argument toconnect()
. Calling this method on a closed channel returnsnull
.- Overrides:
getClusterName
in classJChannel
- Returns:
- The cluster name
-
getLocalAddress
Description copied from class:JChannel
returns the local address of the channel returns null if the channel is closed- Overrides:
getLocalAddress
in classJChannel
- Returns:
- The channel's address. Generated by the underlying transport, and opaque.
Addresses can be used as destination in the
Send
operation.
-
getProperties
Description copied from class:JChannel
returns the protocol stack configuration in string format. an example of this property is
"UDP:PING:FD:STABLE:NAKACK:UNICAST:FRAG:FLUSH:GMS:VIEW_ENFORCER:STATE_TRANSFER:QUEUE"- Overrides:
getProperties
in classJChannel
-
getChannel
This should never be used (just for testing) ! -
getView
Returns the service view, ie. the cluster view (seegetView()
) minus the nodes on which this service is not running, e.g. if S1 runs on A and C, and the cluster view is {A,B,C}, then the service view is {A,C} -
getClusterView
Returns the JGroups view of a cluster, e.g. if we have nodes A, B and C, then the view will be {A,B,C}- Returns:
- The JGroups view
-
getProtocolStack
Description copied from class:JChannel
Returns the protocol stack. Currently used by Debugger. Specific to JChannel, therefore not visible in Channel- Overrides:
getProtocolStack
in classJChannel
-
dumpStats
Description copied from class:JChannel
Returns a map of statistics of the various protocols and of the channel itself. -
setClosed
protected void setClosed(boolean f) -
setConnected
protected void setConnected(boolean f) -
connect
Description copied from class:JChannel
Connects the channel to a group. 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. This method starts the protocol stack by calling ProtocolStack.start, then it sends an Event.CONNECT event down the stack and waits for the return value. Once the call returns, the channel listeners are notified and the channel is considered connected.- Overrides:
connect
in classJChannel
- Parameters:
channel_name
- AString
denoting the group name. Cannot be null.- Throws:
ChannelException
- The protocol stack cannot be startedChannelClosedException
- The channel is closed and therefore cannot be used any longer. A new channel has to be created first.- See Also:
-
connect
public void connect(String cluster_name, Address target, String state_id, long timeout) throws ChannelException Description copied from class:JChannel
Connects this channel to a group and gets a state from a specified state provider.This method essentially invokes
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 succesion. 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.
- Overrides:
connect
in classJChannel
- 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.state_id
- the substate id for partial state transfer. If null entire state will be transferred.timeout
- the timeout for state transfer.- Throws:
ChannelException
- The protocol stack cannot be startedChannelException
- Connecting to cluster was not successful
-
disconnect
public void disconnect()Description copied from class:JChannel
Disconnects the channel if it is connected. If the channel is closed, this operation is ignored
Otherwise the following actions happen in the listed order
- The JChannel sends a DISCONNECT event down the protocol stack
- Blocks until the event has returned
- Sends a STOP_QUEING event down the stack
- Stops the protocol stack by calling ProtocolStack.stop()
- Notifies the listener, if the listener is available
- Overrides:
disconnect
in classJChannel
- See Also:
- The JChannel sends a DISCONNECT event down the protocol stack
-
close
public void close()Description copied from class:JChannel
Destroys the channel. After this method has been called, the channel us unusable.
This operation will disconnect the channel and close the channel receive queue immediately -
notifyServiceDown
protected void notifyServiceDown() -
open
Description copied from class:JChannel
Opens the channel. Note that the channel is only open, but not connected. This does the following actions:- Resets the receiver queue by calling Queue.reset
- Sets up the protocol stack by calling ProtocolStack.setup
- Sets the closed flag to false
- Overrides:
open
in classJChannel
- Throws:
ChannelException
-
shutdown
public void shutdown()Description copied from class:JChannel
Shuts down the channel without disconnecting -
send
Description copied from class:JChannel
Sends a message through the protocol stack. Implements the Transport interface.- Specified by:
send
in interfaceTransport
- Overrides:
send
in classJChannel
- Parameters:
msg
- the message to be sent through the protocol stack, the destination of the message is specified inside the message itself- Throws:
ChannelNotConnectedException
ChannelClosedException
-
send
public void send(Address dst, Address src, Serializable obj) throws ChannelNotConnectedException, ChannelClosedException Description copied from class:JChannel
creates a new message with the destination address, and the source address and the object as the message value- Overrides:
send
in classJChannel
- Parameters:
dst
- - the destination address of the message, null for all memberssrc
- - the source address of the messageobj
- - the value of the message- Throws:
ChannelNotConnectedException
ChannelClosedException
- See Also:
-
down
Description copied from class:JChannel
Sends a message through the protocol stack if the stack is available -
downcall
Description copied from class:Channel
Can be used instead of down() when a return value is expected. This will be removed in 3.0 when we change the signature of down() to return Object rather than void -
getState
public boolean getState(Address target, String state_id, long timeout, boolean useFlushIfPresent) throws ChannelNotConnectedException, ChannelClosedException Description copied from class:JChannel
Retrieves a substate (or partial state) indicated by state_id from the target member.State transfer is initiated by invoking getState on this channel, state receiver, and sending a GET_STATE message to a target member - state provider. State provider passes GET_STATE message to application that is using the state provider channel which in turn provides an application state to a state receiver. Upon successful installation of a state at state receiver this method returns true.
- Overrides:
getState
in classJChannel
- Parameters:
target
- State provider. If null, coordinator is usedstate_id
- The ID of the substate. If null, the entire state will be transferredtimeout
- the number of milliseconds to wait for the operation to complete successfully. 0 waits until the state has been receiveduseFlushIfPresent
- whether channel should be flushed prior to state retrieval- Returns:
- true if state transfer was successful, false otherwise
- Throws:
ChannelNotConnectedException
- if channel was not connected at the time state retrieval was initiatedChannelClosedException
- if channel was closed at the time state retrieval was initiated- See Also:
-
returnState
public void returnState(byte[] state) Description copied from class:JChannel
Called by the application is response to receiving agetState()
object when callingreceive()
. When the application receives a getState() message on the receive() method, it should call returnState() to reply with the state of the application- Overrides:
returnState
in classJChannel
- Parameters:
state
- The state of the application as a byte buffer (to send over the network).
-
returnState
Description copied from class:JChannel
Returns a substate as indicated by state_id- Overrides:
returnState
in classJChannel
- Parameters:
state
-state_id
-
-