Class MuxChannel

All Implemented Interfaces:
Transport

public class MuxChannel extends JChannel
Multiplexer channel is a lightweight version of a regular channel where multiple MuxChannel(s) share the same underlying regular channel.

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:
  • Method Details

    • getStackName

      public String getStackName()
    • getId

      public String getId()
    • getMultiplexer

      public Multiplexer getMultiplexer()
    • getChannelName

      public 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 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.
    • getProperties

      public String 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 class JChannel
    • 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
    • dumpStats

      public Map<String,Object> 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:
      Mapinvalid input: '<'String,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

      protected void setClosed(boolean f)
    • setConnected

      protected void setConnected(boolean f)
    • connect

      public void connect(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 for the return value. Once the call returns, the 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:
    • 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 class JChannel
      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 started
      ChannelException - 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
      1. The JChannel sends a DISCONNECT event down the protocol stack
      2. Blocks until the event has returned
      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:
    • 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
    • notifyServiceDown

      protected void notifyServiceDown()
    • open

      public void open() throws ChannelException
      Description copied from class: JChannel
      Opens the channel. Note that the channel is only open, but not connected. 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
    • shutdown

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

      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
      ChannelClosedException
    • send

      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:
    • 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
    • downcall

      public Object downcall(Event evt)
      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
      Overrides:
      downcall in class JChannel
      Parameters:
      evt -
      Returns:
    • 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 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
      useFlushIfPresent - 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 initiated
      ChannelClosedException - 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 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, String state_id)
      Description copied from class: JChannel
      Returns a substate as indicated by state_id
      Overrides:
      returnState in class JChannel
      Parameters:
      state -
      state_id -