org.jgroups.mux
Class MuxChannel

java.lang.Object
  extended by org.jgroups.Channel
      extended by org.jgroups.JChannel
          extended by org.jgroups.mux.MuxChannel
All Implemented Interfaces:
Transport

public class MuxChannel
extends JChannel

Multiplexer channel. This is returned as result of calling ChannelFactory.createMultiplexerChannel(String,String,boolean,String). Maintains the multiplexer ID, which is used to add a header to each message, so that the message can be demultiplexed at the receiver

Version:
$Id: MuxChannel.java,v 1.26.2.1 2007/01/08 21:00:16 vlada Exp $
Author:
Bela Ban

Field Summary
 
Fields inherited from class org.jgroups.JChannel
closed, closer, connected, DEFAULT_PROTOCOL_STACK, log, received_bytes, received_msgs, sent_bytes, sent_msgs, stats
 
Fields inherited from class org.jgroups.Channel
AUTO_GETSTATE, AUTO_RECONNECT, BLOCK, channel_listener, channel_listeners, GET_STATE_EVENTS, LOCAL, receiver, SUSPECT, up_handler, VIEW
 
Constructor Summary
MuxChannel(JChannelFactory f, JChannel ch, java.lang.String id, java.lang.String stack_name, Multiplexer mux)
           
 
Method Summary
protected  void _close(boolean disconnect, boolean close_mq)
          Disconnects and closes the channel.
protected  void checkClosed()
          health check
throws a ChannelClosed exception if the channel is closed
protected  void checkNotConnected()
          health check.
throws a ChannelNotConnected exception if the channel is not connected
 void close()
          Destroys the channel.
 void connect(java.lang.String channel_name)
          Connects the channel to a group.
 boolean connect(java.lang.String cluster_name, Address target, java.lang.String state_id, long timeout)
          Connects the channel to a group and fetches the state
 void disconnect()
          Disconnects the channel if it is connected.
 void down(Event evt)
          Sends a message through the protocol stack if the stack is available
 java.util.Map dumpStats()
          Returns a map of statistics of the various protocols and of the channel itself.
 JChannel getChannel()
          This should never be used (just for testing) !
 java.lang.String getChannelName()
          returns the name of the channel if the channel is not connected or if it is closed it will return null
 java.lang.String getClusterName()
          Returns the cluster name of the group of which the channel is a member.
 View getClusterView()
          Returns the JGroups view of a cluster, e.g.
 java.lang.String getId()
           
 Address getLocalAddress()
          returns the local address of the channel returns null if the channel is closed
 Multiplexer getMultiplexer()
           
 java.lang.Object getOpt(int option)
          returns the value of an option.
 ProtocolStack getProtocolStack()
          Returns the protocol stack.
 java.lang.String getStackName()
           
 boolean getState(Address target, long timeout)
          Retrieves the current group state.
 boolean getState(Address target, java.lang.String state_id, long timeout)
          Retrieves a substate (or partial state) from the target.
 View getView()
          Returns the service view, ie.
 boolean isConnected()
          returns true if the Connect operation has been called successfully
 boolean isOpen()
          returns true if the Open operation has been called successfully
 void open()
          Opens the channel.
 void returnState(byte[] state)
          Called by the application is response to receiving a getState() object when calling receive().
 void returnState(byte[] state, java.lang.String state_id)
          Returns a substate as indicated by state_id
 void send(Address dst, Address src, java.io.Serializable obj)
          creates a new message with the destination address, and the source address and the object as the message value
 void send(Message msg)
          Sends a message through the protocol stack.
 void setClosed(boolean f)
           
 void setConnected(boolean f)
           
 void setOpt(int option, java.lang.Object value)
          Sets a channel option.
 void shutdown()
          Shuts down the channel without disconnecting
 
Methods inherited from class org.jgroups.JChannel
blockOk, closeMessageQueue, dumpQueue, dumpTimerQueue, enableStats, flushSupported, getAllStates, getLog, getNumberOfTasksInTimer, getNumMessages, getProperties, getReceivedBytes, getReceivedMessages, getSentBytes, getSentMessages, init, peek, printProtocolSpec, receive, resetStats, startFlush, startFlush, statsEnabled, stopFlush, toString, up
 
Methods inherited from class org.jgroups.Channel
addChannelListener, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, notifyChannelReconnected, notifyChannelShunned, option2String, removeChannelListener, setChannelListener, setReceiver, setUpHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MuxChannel

public MuxChannel(JChannelFactory f,
                  JChannel ch,
                  java.lang.String id,
                  java.lang.String stack_name,
                  Multiplexer mux)
Method Detail

getStackName

public java.lang.String getStackName()

getId

public java.lang.String getId()

getMultiplexer

public Multiplexer getMultiplexer()

getChannelName

public java.lang.String 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 class JChannel
Returns:
The group address

getClusterName

public java.lang.String 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 to connect(). Calling this method on a closed channel returns null.

Overrides:
getClusterName in class JChannel
Returns:
The cluster name

getLocalAddress

public Address getLocalAddress()
Description copied from class: JChannel
returns the local address of the channel returns null if the channel is closed

Overrides:
getLocalAddress in class JChannel
Returns:
The channel's address. Generated by the underlying transport, and opaque. Addresses can be used as destination in the Send operation.

getChannel

public JChannel getChannel()
This should never be used (just for testing) !


getView

public View getView()
Returns the service view, ie. the cluster view (see getView()) 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}

Overrides:
getView in class JChannel
Returns:
The service view (list of nodes on which this service is running)

getClusterView

public View 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

public ProtocolStack 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 class JChannel

isOpen

public boolean isOpen()
Description copied from class: JChannel
returns true if the Open operation has been called successfully

Overrides:
isOpen in class JChannel

isConnected

public boolean isConnected()
Description copied from class: JChannel
returns true if the Connect operation has been called successfully

Overrides:
isConnected in class JChannel

dumpStats

public java.util.Map dumpStats()
Description copied from class: JChannel
Returns a map of statistics of the various protocols and of the channel itself.

Overrides:
dumpStats in class JChannel
Returns:
Map. A map where the keys are the protocols ("channel" pseudo key is used for the channel itself") and the values are property maps.

setClosed

public void setClosed(boolean f)

setConnected

public void setConnected(boolean f)

getOpt

public java.lang.Object getOpt(int option)
Description copied from class: JChannel
returns the value of an option.

Overrides:
getOpt in class JChannel
Parameters:
option - the option you want to see the value for
Returns:
the object value, in most cases java.lang.Boolean
See Also:
JChannel.setOpt(int, java.lang.Object)

setOpt

public void setOpt(int option,
                   java.lang.Object value)
Description copied from class: JChannel
Sets a channel option. The options can be one of the following:

There are certain dependencies between the options that you can set, I will try to describe them here.

Option: Channel.BLOCK
Value: java.lang.Boolean
Result: set to true will set setOpt(VIEW, true) and the JChannel will receive BLOCKS and VIEW events

Option: LOCAL
Value: java.lang.Boolean
Result: set to true the JChannel will receive messages that it self sent out.

Option: AUTO_RECONNECT
Value: java.lang.Boolean
Result: set to true and the JChannel will try to reconnect when it is being closed

Option: AUTO_GETSTATE
Value: java.lang.Boolean
Result: set to true, the AUTO_RECONNECT will be set to true and the JChannel will try to get the state after a close and reconnect happens

Overrides:
setOpt in class JChannel
Parameters:
option - the parameter option Channel.VIEW, Channel.SUSPECT, etc
value - the value to set for this option

connect

public void connect(java.lang.String channel_name)
             throws ChannelException,
                    ChannelClosedException
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 to receive a CONNECT_OK event. Once the CONNECT_OK event arrives from the protocol stack, any channel listeners are notified and the channel is considered connected.

Overrides:
connect in class JChannel
Parameters:
channel_name - A String denoting the group name. Cannot be null.
Throws:
ChannelException - The protocol stack cannot be started
ChannelClosedException - The channel is closed and therefore cannot be used any longer. A new channel has to be created first.
See Also:
Channel.disconnect()

connect

public boolean connect(java.lang.String cluster_name,
                       Address target,
                       java.lang.String state_id,
                       long timeout)
                throws ChannelException
Description copied from class: Channel
Connects the channel to a group and fetches the state

Overrides:
connect in class JChannel
state_id - The ID of a substate. If the full state is to be fetched, set this to null
Returns:
True if the state could be fetched, otherwise false. If true is returned, the state setting method (e.g. setState() will be called.
Throws:
ChannelException

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
  1. The JChannel sends a DISCONNECT event down the protocol stack
  2. Blocks until the channel to receives a DISCONNECT_OK event
  3. Sends a STOP_QUEING event down the stack
  4. Stops the protocol stack by calling ProtocolStack.stop()
  5. Notifies the listener, if the listener is available

Overrides:
disconnect in class JChannel
See Also:
Channel.connect(String)

open

public void open()
          throws ChannelException
Description copied from class: JChannel
Opens the channel. This does the following actions:
  1. Resets the receiver queue by calling Queue.reset
  2. Sets up the protocol stack by calling ProtocolStack.setup
  3. Sets the closed flag to false

Overrides:
open in class JChannel
Throws:
ChannelException

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

Overrides:
close in class JChannel

_close

protected void _close(boolean disconnect,
                      boolean close_mq)
Description copied from class: JChannel
Disconnects and closes the channel. This method does the folloing things
  1. Calls this.disconnect if the disconnect parameter is true
  2. Calls Queue.close on mq if the close_mq parameter is true
  3. Calls ProtocolStack.stop on the protocol stack
  4. Calls ProtocolStack.destroy on the protocol stack
  5. Sets the channel closed and channel connected flags to true and false
  6. Notifies any channel listener of the channel close operation

Overrides:
_close in class JChannel

shutdown

public void shutdown()
Description copied from class: JChannel
Shuts down the channel without disconnecting

Overrides:
shutdown in class JChannel

send

public void send(Message msg)
          throws ChannelNotConnectedException,
                 ChannelClosedException
Description copied from class: JChannel
Sends a message through the protocol stack. Implements the Transport interface.

Specified by:
send in interface Transport
Overrides:
send in class JChannel
Parameters:
msg - the message to be sent through the protocol stack, the destination of the message is specified inside the message itself
Throws:
ChannelNotConnectedException - The channel must be connected to send messages.
ChannelClosedException - The channel is closed and therefore cannot be used any longer. A new channel has to be created first.

send

public void send(Address dst,
                 Address src,
                 java.io.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 class JChannel
Parameters:
dst - - the destination address of the message, null for all members
src - - the source address of the message
obj - - the value of the message
Throws:
ChannelNotConnectedException
ChannelClosedException
See Also:
JChannel.send(org.jgroups.Message)

down

public void down(Event evt)
Description copied from class: JChannel
Sends a message through the protocol stack if the stack is available

Overrides:
down in class JChannel
Parameters:
evt - the message to send down, encapsulated in an event

getState

public boolean getState(Address target,
                        long timeout)
                 throws ChannelNotConnectedException,
                        ChannelClosedException
Description copied from class: JChannel
Retrieves the current group state. Sends GET_STATE event down to STATE_TRANSFER layer. Blocks until STATE_TRANSFER sends up a GET_STATE_OK event or until timeout milliseconds have elapsed. The argument of GET_STATE_OK should be a single object.

Overrides:
getState in class JChannel
Parameters:
target - the target member to receive the state from. if null, state is retrieved from coordinator
timeout - the number of milliseconds to wait for the operation to complete successfully. 0 waits until the state has been received
Returns:
true of the state was received, false if the operation timed out
Throws:
ChannelNotConnectedException - The channel must be connected to receive messages.
ChannelClosedException - The channel is closed and therefore cannot be used any longer. A new channel has to be created first.

getState

public boolean getState(Address target,
                        java.lang.String state_id,
                        long timeout)
                 throws ChannelNotConnectedException,
                        ChannelClosedException
Description copied from class: JChannel
Retrieves a substate (or partial state) from the target.

Overrides:
getState in class JChannel
Parameters:
target - State provider. If null, coordinator is used
state_id - The ID of the substate. If null, the entire state will be transferred
timeout - the number of milliseconds to wait for the operation to complete successfully. 0 waits until the state has been received
Returns:
Throws:
ChannelNotConnectedException
ChannelClosedException

returnState

public void returnState(byte[] state)
Description copied from class: JChannel
Called by the application is response to receiving a getState() object when calling receive(). 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 class JChannel
Parameters:
state - The state of the application as a byte buffer (to send over the network).

returnState

public void returnState(byte[] state,
                        java.lang.String state_id)
Description copied from class: JChannel
Returns a substate as indicated by state_id

Overrides:
returnState in class JChannel

checkNotConnected

protected void checkNotConnected()
                          throws ChannelNotConnectedException
Description copied from class: JChannel
health check.
throws a ChannelNotConnected exception if the channel is not connected

Overrides:
checkNotConnected in class JChannel
Throws:
ChannelNotConnectedException

checkClosed

protected void checkClosed()
                    throws ChannelClosedException
Description copied from class: JChannel
health check
throws a ChannelClosed exception if the channel is closed

Overrides:
checkClosed in class JChannel
Throws:
ChannelClosedException


Copyright ? 1998-2006 Bela Ban. All Rights Reserved.