org.jboss.remoting.transport.multiplex
Class MultiplexingManager

java.lang.Object
  extended by org.jboss.remoting.transport.multiplex.MultiplexingManager
All Implemented Interfaces:
java.util.EventListener, javax.net.ssl.HandshakeCompletedListener, OutputMultiplexor.OutputMultiplexorClient

public class MultiplexingManager
extends java.lang.Object
implements OutputMultiplexor.OutputMultiplexorClient, javax.net.ssl.HandshakeCompletedListener

MultiplexingManager is the heart of the Multiplex system. It is the implementation of the virtual socket group concept. See the Multiplex documentation on the labs.jboss.org website for more information about virtual socket groups.

MultiplexingManager wraps a single real java.net.Socket. It creates the socket when it is running on the client side, and it is passed a socket by MasterServerSocket when it is running on the server side.

MultiplexingManager creates the infrastructure which supports multiplexing, including an OutputMultiplexor output thread and one or more InputMultiplexor input threads. When the last member leaves the socket group, a MultiplexingManager is responsible for negotiating with its remote peer for permission to shut down, and for tearing down the multiplexing infrastructure when the negotiations succeed.

MultiplexingManager also provides the mechanism by which a virtual socket joins a virtual socket group, identifying the new socket to the InputMultiplexor input thread.

Copyright (c) 2005

Author:
Ron Sigal

Nested Class Summary
protected static class MultiplexingManager.PendingActionThread
           
protected  class MultiplexingManager.ShutdownManager
          The motivation behind this class is to prevent the following problem.
protected  class MultiplexingManager.ShutdownThread
           
 
Constructor Summary
protected MultiplexingManager(java.net.InetSocketAddress address, int timeout, java.util.Map configuration)
           
protected MultiplexingManager(java.util.Map configuration)
           
protected MultiplexingManager(java.net.Socket socket, java.util.Map configuration)
           
 
Method Summary
protected static void addToPendingActions(PendingAction pendingAction)
          Adds a PendingAction to the list of actions waiting to be executed.
 void bind(java.net.InetSocketAddress address)
          Binds the wrapped socket.
static boolean checkForManagerByAddressPair(java.net.InetSocketAddress localAddress, java.net.InetSocketAddress remoteAddress)
           
static boolean checkForShareableManager(java.net.InetSocketAddress address)
           
static boolean checkForShareableManagerByAddressPair(java.net.InetSocketAddress localAddress, java.net.InetSocketAddress remoteAddress)
           
 void connect(java.net.InetSocketAddress address, int timeout)
          Connects the wrapped socket.
protected  java.net.Socket createSocket()
           
protected  java.net.Socket createSocket(java.net.InetSocketAddress endpoint, int timeout)
          protected methods and classes
 void decrementReferences()
          Decrement reference counter for this MultiplexingManager.
 java.util.Collection getAllOutputStreams()
           
static MultiplexingManager getaManager(java.net.Socket socket, java.util.Map configuration)
           
static MultiplexingManager getaManagerByAddressPair(java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, int timeout)
           
static MultiplexingManager getaManagerByAddressPair(java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, int timeout, java.util.Map conf)
           
static MultiplexingManager getaManagerByLocalAddress(java.net.InetSocketAddress address)
           
static MultiplexingManager getaManagerByLocalAddress(java.net.InetSocketAddress address, java.util.Map conf)
           
static MultiplexingManager getaManagerByRemoteAddress(java.net.InetSocketAddress address, int timeout)
           
static MultiplexingManager getaManagerByRemoteAddress(java.net.InetSocketAddress address, int timeout, java.util.Map conf)
           
static MultiplexingManager getAnExistingShareableManager(java.net.InetSocketAddress address, java.util.Map conf)
           
static MultiplexingManager getAnExistingShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, java.util.Map conf)
           
 MultiplexingInputStream getAnInputStream(SocketId socketId, VirtualSocket socket)
          Get an InputStream for a VirtualSocket.
 GrowablePipedOutputStream getAnOutputStream(SocketId socketId)
          Get an OutputStrem for a VirtualSocket.
 MultiplexingOutputStream getAnOutputStream(VirtualSocket socket, SocketId socketId)
           
static MultiplexingManager getaShareableManager(java.net.InetSocketAddress address, int timeout)
           
static MultiplexingManager getaShareableManager(java.net.InetSocketAddress address, int timeout, java.util.Map conf)
           
static MultiplexingManager getaShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, int timeout)
           
static MultiplexingManager getaShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress, java.net.InetSocketAddress localAddress, int timeout, java.util.Map conf)
           
 java.io.OutputStream getBackchannelOutputStream()
           
 GrowablePipedOutputStream getConnectedOutputStream(SocketId socketId)
          Returns a GrowablePipedOutputStream that is connected to a MultiplexingInputStream.
 java.io.OutputStream getDeadLetterOutputStream()
          Returns OutputStream to use when corrupted InputStream gives no known "mailbox"
 javax.net.ssl.HandshakeCompletedEvent getHandshakeCompletedEvent()
           
 java.io.InputStream getInputStream()
          Returns InputStream of real socket
 OutputMultiplexor getOutputMultiplexor()
           
 java.io.OutputStream getOutputStream()
          Returns OutputStream of real socket
 java.io.OutputStream getOutputStreamByLocalSocket(SocketId socketId)
           
 Protocol getProtocol()
           
 java.net.ServerSocket getServerSocket()
           
 int getShutdownMonitorPeriod()
           
 int getShutdownRefusalsMaximum()
           
 int getShutdownRequestTimeout()
           
 java.net.Socket getSocket()
           
 VirtualSocket getSocketByLocalPort(SocketId socketId)
           
 javax.net.SocketFactory getSocketFactory()
           
static int getStaticThreadMonitorPeriod()
           
 void handshakeCompleted(javax.net.ssl.HandshakeCompletedEvent event)
          To implement HandshakeCompletedListener interface.
 void incrementReferences()
          Increment reference counter for this MultiplexingManager.
protected static void init(java.util.Map configuration)
           
protected  void initParameters(java.util.Map configuration)
           
 boolean isBound()
           
 boolean isConnected()
           
 boolean isRemoteServerSocketRegistered()
           
 boolean isServerSocketRegistered()
           
 boolean isShutdown()
           
 boolean isSocketRegistered(SocketId socketId)
           
protected  void notifySocketsOfException()
           
 void outputFlushed()
          Needed to implement OutputMultiplexor.OutputMultiplexorClient
protected  void registerByLocalAddress(java.net.InetSocketAddress address)
           
protected  void registerByRemoteAddress(java.net.InetSocketAddress address)
           
 void registerRemoteServerSocket()
          Indicates that a VirtualServerSocket belongs the virtual socket group at the remote end of the connection.
 MultiplexingInputStream registerServerSocket(java.net.ServerSocket serverSocket)
          Identifies a VirtualServerSocket as the one associated with this virtual socket group.
protected  void registerShareable(java.net.InetSocketAddress address)
           
 MultiplexingInputStream registerSocket(VirtualSocket socket)
          Adds a VirtualSocket to this virtual socket group.
protected  void removeAnInputStream(SocketId socketId)
           
 boolean respondToShutdownRequest()
           
 void setCreatedForRemoteServerSocket()
           
protected  void setEOF()
           
protected  void setReadException(java.io.IOException e)
           
 void setShutdownMonitorPeriod(int period)
           
 void setShutdownRefusalsMaximum(int maximum)
           
 void setShutdownRequestTimeout(int timeout)
           
 void setSocketFactory(javax.net.SocketFactory socketFactory)
           
static void setStaticThreadsMonitorPeriod(int period)
           
protected  void setup()
           
protected  void setWriteException(java.io.IOException e)
           
protected  void shutdown()
           
protected static void shutdownThreads()
           
 java.lang.String toString()
           
protected  void unregisterAllMaps()
           
protected  void unregisterByLocalAddress()
           
protected  void unregisterByRemoteAddress()
           
 void unRegisterRemoteServerSocket()
          Indicates there will no longer be a VirtualServeSocket at the remote end of this connection.
 void unRegisterServerSocket(java.net.ServerSocket serverSocket)
          Indicates a VirtualServerSocket is leaving this virtual socket group.
protected  void unregisterShareable()
           
 void unRegisterSocket(VirtualSocket socket)
          Indicates that a VirtualSocket is leaving a virtual socket group.
 boolean waitForRemoteServerSocketRegistered()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiplexingManager

protected MultiplexingManager(java.util.Map configuration)
                       throws java.io.IOException
Throws:
java.io.IOException

MultiplexingManager

protected MultiplexingManager(java.net.Socket socket,
                              java.util.Map configuration)
                       throws java.io.IOException
Parameters:
socket -
configuration -
Throws:
java.io.IOException

MultiplexingManager

protected MultiplexingManager(java.net.InetSocketAddress address,
                              int timeout,
                              java.util.Map configuration)
                       throws java.io.IOException
Parameters:
address -
timeout -
configuration -
Throws:
java.io.IOException
Method Detail

init

protected static void init(java.util.Map configuration)
                    throws java.io.IOException
Throws:
java.io.IOException

setup

protected void setup()
              throws java.io.IOException
Throws:
java.io.IOException

initParameters

protected void initParameters(java.util.Map configuration)

getaManager

public static MultiplexingManager getaManager(java.net.Socket socket,
                                              java.util.Map configuration)
                                       throws java.io.IOException
Parameters:
socket -
configuration -
Returns:
Throws:
java.io.IOException - TODO: what if multiplexor already exists?

getaManagerByLocalAddress

public static MultiplexingManager getaManagerByLocalAddress(java.net.InetSocketAddress address)
                                                     throws java.io.IOException
Parameters:
address -
Returns:
Throws:
java.io.IOException

getaManagerByLocalAddress

public static MultiplexingManager getaManagerByLocalAddress(java.net.InetSocketAddress address,
                                                            java.util.Map conf)
                                                     throws java.io.IOException
Parameters:
address -
conf -
Returns:
Throws:
java.io.IOException

getaManagerByRemoteAddress

public static MultiplexingManager getaManagerByRemoteAddress(java.net.InetSocketAddress address,
                                                             int timeout)
                                                      throws java.io.IOException
Parameters:
address -
timeout -
Returns:
Throws:
java.io.IOException

getaManagerByRemoteAddress

public static MultiplexingManager getaManagerByRemoteAddress(java.net.InetSocketAddress address,
                                                             int timeout,
                                                             java.util.Map conf)
                                                      throws java.io.IOException
Parameters:
address -
timeout -
configuration -
Returns:
Throws:
java.io.IOException

getaManagerByAddressPair

public static MultiplexingManager getaManagerByAddressPair(java.net.InetSocketAddress remoteAddress,
                                                           java.net.InetSocketAddress localAddress,
                                                           int timeout)
                                                    throws java.io.IOException
Parameters:
remoteAddress -
localAddress -
timeout -
Returns:
Throws:
java.io.IOException

getaManagerByAddressPair

public static MultiplexingManager getaManagerByAddressPair(java.net.InetSocketAddress remoteAddress,
                                                           java.net.InetSocketAddress localAddress,
                                                           int timeout,
                                                           java.util.Map conf)
                                                    throws java.io.IOException
Parameters:
remoteAddress -
localAddress -
timeout -
configuration -
Returns:
Throws:
java.io.IOException

getaShareableManager

public static MultiplexingManager getaShareableManager(java.net.InetSocketAddress address,
                                                       int timeout)
                                                throws java.io.IOException
Parameters:
address -
timeout -
Returns:
Throws:
java.io.IOException

getaShareableManager

public static MultiplexingManager getaShareableManager(java.net.InetSocketAddress address,
                                                       int timeout,
                                                       java.util.Map conf)
                                                throws java.io.IOException
Parameters:
address -
timeout -
conf -
Returns:
Throws:
java.io.IOException

getAnExistingShareableManager

public static MultiplexingManager getAnExistingShareableManager(java.net.InetSocketAddress address,
                                                                java.util.Map conf)
                                                         throws java.io.IOException
Parameters:
address -
timeout -
conf -
Returns:
Throws:
java.io.IOException

getaShareableManagerByAddressPair

public static MultiplexingManager getaShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress,
                                                                    java.net.InetSocketAddress localAddress,
                                                                    int timeout)
                                                             throws java.io.IOException
Parameters:
remoteAddress -
localAddress -
timeout -
Returns:
Throws:
java.io.IOException

getaShareableManagerByAddressPair

public static MultiplexingManager getaShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress,
                                                                    java.net.InetSocketAddress localAddress,
                                                                    int timeout,
                                                                    java.util.Map conf)
                                                             throws java.io.IOException
Parameters:
remoteAddress -
localAddress -
timeout -
conf -
Returns:
Throws:
java.io.IOException

getAnExistingShareableManagerByAddressPair

public static MultiplexingManager getAnExistingShareableManagerByAddressPair(java.net.InetSocketAddress remoteAddress,
                                                                             java.net.InetSocketAddress localAddress,
                                                                             java.util.Map conf)
                                                                      throws java.io.IOException
Parameters:
remoteAddress -
localAddress -
conf -
Returns:
Throws:
java.io.IOException

checkForShareableManager

public static boolean checkForShareableManager(java.net.InetSocketAddress address)
                                        throws java.io.IOException
Parameters:
address -
Returns:
Throws:
java.io.IOException

checkForManagerByAddressPair

public static boolean checkForManagerByAddressPair(java.net.InetSocketAddress localAddress,
                                                   java.net.InetSocketAddress remoteAddress)
Parameters:
localAddress -
remoteAddress -
Returns:

checkForShareableManagerByAddressPair

public static boolean checkForShareableManagerByAddressPair(java.net.InetSocketAddress localAddress,
                                                            java.net.InetSocketAddress remoteAddress)
Parameters:
localAddress -
remoteAddress -
Returns:

getStaticThreadMonitorPeriod

public static int getStaticThreadMonitorPeriod()
Returns:

setStaticThreadsMonitorPeriod

public static void setStaticThreadsMonitorPeriod(int period)
Parameters:
period -

shutdownThreads

protected static void shutdownThreads()

addToPendingActions

protected static void addToPendingActions(PendingAction pendingAction)
Adds a PendingAction to the list of actions waiting to be executed.

Parameters:
pendingAction -

bind

public void bind(java.net.InetSocketAddress address)
          throws java.io.IOException
Binds the wrapped socket.

Parameters:
address -
Throws:
java.io.IOException

connect

public void connect(java.net.InetSocketAddress address,
                    int timeout)
             throws java.io.IOException
Connects the wrapped socket.

Parameters:
address -
timeout -
Throws:
java.io.IOException

registerServerSocket

public MultiplexingInputStream registerServerSocket(java.net.ServerSocket serverSocket)
                                             throws java.io.IOException
Identifies a VirtualServerSocket as the one associated with this virtual socket group.

Returns:
a MultiplexingInputStream for use by serverSocket.
Throws:
java.io.IOException

unRegisterServerSocket

public void unRegisterServerSocket(java.net.ServerSocket serverSocket)
                            throws java.io.IOException
Indicates a VirtualServerSocket is leaving this virtual socket group.

Parameters:
serverSocket -
Throws:
java.io.IOException

registerSocket

public MultiplexingInputStream registerSocket(VirtualSocket socket)
                                       throws java.io.IOException
Adds a VirtualSocket to this virtual socket group.

Parameters:
socket -
Returns:
a MultiplexingInputStream for use by socket
Throws:
java.io.IOException

unRegisterSocket

public void unRegisterSocket(VirtualSocket socket)
                      throws java.io.IOException
Indicates that a VirtualSocket is leaving a virtual socket group.

Parameters:
socket -
Throws:
java.io.IOException

registerRemoteServerSocket

public void registerRemoteServerSocket()
                                throws java.io.IOException
Indicates that a VirtualServerSocket belongs the virtual socket group at the remote end of the connection. This virtual socket groupD becomes "joinable", in the sense that a new VirtualSocket v can join this virtual group because there is a VirtualServerSocket at the other end of the connection to create a remote peer for v.

Throws:
java.io.IOException

unRegisterRemoteServerSocket

public void unRegisterRemoteServerSocket()
Indicates there will no longer be a VirtualServeSocket at the remote end of this connection. This virtual socket group will no longer be "joinable". (See registerRemoteServerSocket().)


setCreatedForRemoteServerSocket

public void setCreatedForRemoteServerSocket()

isRemoteServerSocketRegistered

public boolean isRemoteServerSocketRegistered()

waitForRemoteServerSocketRegistered

public boolean waitForRemoteServerSocketRegistered()

incrementReferences

public void incrementReferences()
                         throws java.io.IOException
Increment reference counter for this MultiplexingManager.

Throws:
java.io.IOException

decrementReferences

public void decrementReferences()
                         throws java.io.IOException
Decrement reference counter for this MultiplexingManager.

Throws:
java.io.IOException

getAllOutputStreams

public java.util.Collection getAllOutputStreams()
Returns:

getDeadLetterOutputStream

public java.io.OutputStream getDeadLetterOutputStream()
Returns OutputStream to use when corrupted InputStream gives no known "mailbox"

Returns:
OutputStream to use when corrupted InputStream gives no known "mailbox"

getInputStream

public java.io.InputStream getInputStream()
Returns InputStream of real socket

Returns:
InputStream of real socket

getOutputStream

public java.io.OutputStream getOutputStream()
Returns OutputStream of real socket

Returns:
OutputStream of real socket

getAnInputStream

public MultiplexingInputStream getAnInputStream(SocketId socketId,
                                                VirtualSocket socket)
                                         throws java.io.IOException
Get an InputStream for a VirtualSocket.

Parameters:
socketId -
socket -
Returns:
Throws:
java.io.IOException

getAnOutputStream

public GrowablePipedOutputStream getAnOutputStream(SocketId socketId)
Get an OutputStrem for a VirtualSocket.

Parameters:
socketId -
Returns:

getAnOutputStream

public MultiplexingOutputStream getAnOutputStream(VirtualSocket socket,
                                                  SocketId socketId)
Parameters:
socketId -
Returns:

getConnectedOutputStream

public GrowablePipedOutputStream getConnectedOutputStream(SocketId socketId)
                                                   throws java.io.IOException
Returns a GrowablePipedOutputStream that is connected to a MultiplexingInputStream. It will create the MultiplexingInputStream if necessary. This method exists to allow InputMultiplexor to get a place to put bytes directed to an unrecognized SocketId, which might be necessary if the remote socket starts writing before this end of the connection is ready. Originally, we had a three step handshake, in which (1) the client socket sent a "connect" message, (2) the server socket sent a "connected" message, and (3) the client socket sent a "connect verify" message. In the interests of performance we eliminated the final step.

Parameters:
socketId -
Returns:
Throws:
java.io.IOException

getBackchannelOutputStream

public java.io.OutputStream getBackchannelOutputStream()
Returns:

getHandshakeCompletedEvent

public javax.net.ssl.HandshakeCompletedEvent getHandshakeCompletedEvent()
Returns:
handshakeCompletedEvent

getOutputMultiplexor

public OutputMultiplexor getOutputMultiplexor()
Returns:

getOutputStreamByLocalSocket

public java.io.OutputStream getOutputStreamByLocalSocket(SocketId socketId)
Parameters:
socketId -
Returns:

getProtocol

public Protocol getProtocol()
Returns:

getServerSocket

public java.net.ServerSocket getServerSocket()
Returns:

getSocket

public java.net.Socket getSocket()
Returns:

getSocketByLocalPort

public VirtualSocket getSocketByLocalPort(SocketId socketId)
Parameters:
socketId -
Returns:

getSocketFactory

public javax.net.SocketFactory getSocketFactory()
Returns:

handshakeCompleted

public void handshakeCompleted(javax.net.ssl.HandshakeCompletedEvent event)
To implement HandshakeCompletedListener interface.

Specified by:
handshakeCompleted in interface javax.net.ssl.HandshakeCompletedListener

isBound

public boolean isBound()
Returns:

isConnected

public boolean isConnected()
Returns:

isServerSocketRegistered

public boolean isServerSocketRegistered()
Returns:

isShutdown

public boolean isShutdown()

isSocketRegistered

public boolean isSocketRegistered(SocketId socketId)
Parameters:
socketId -
Returns:
TODO: isn't used

respondToShutdownRequest

public boolean respondToShutdownRequest()
Returns:

setSocketFactory

public void setSocketFactory(javax.net.SocketFactory socketFactory)
Parameters:
socketFactory -

getShutdownMonitorPeriod

public int getShutdownMonitorPeriod()
Returns:

getShutdownRefusalsMaximum

public int getShutdownRefusalsMaximum()
Returns:

getShutdownRequestTimeout

public int getShutdownRequestTimeout()
Returns:

setShutdownRequestTimeout

public void setShutdownRequestTimeout(int timeout)
Parameters:
timeout -

setShutdownRefusalsMaximum

public void setShutdownRefusalsMaximum(int maximum)
Parameters:
maximum -

setShutdownMonitorPeriod

public void setShutdownMonitorPeriod(int period)
Parameters:
period -

outputFlushed

public void outputFlushed()
Needed to implement OutputMultiplexor.OutputMultiplexorClient

Specified by:
outputFlushed in interface OutputMultiplexor.OutputMultiplexorClient

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createSocket

protected java.net.Socket createSocket(java.net.InetSocketAddress endpoint,
                                       int timeout)
                                throws java.io.IOException
protected methods and classes

Throws:
java.io.IOException

createSocket

protected java.net.Socket createSocket()
                                throws java.io.IOException
Throws:
java.io.IOException

registerByLocalAddress

protected void registerByLocalAddress(java.net.InetSocketAddress address)
Parameters:
address -

unregisterByLocalAddress

protected void unregisterByLocalAddress()

registerByRemoteAddress

protected void registerByRemoteAddress(java.net.InetSocketAddress address)
Parameters:
address -

unregisterByRemoteAddress

protected void unregisterByRemoteAddress()

registerShareable

protected void registerShareable(java.net.InetSocketAddress address)
Parameters:
address -

unregisterShareable

protected void unregisterShareable()

unregisterAllMaps

protected void unregisterAllMaps()

removeAnInputStream

protected void removeAnInputStream(SocketId socketId)
Parameters:
socketId -

setReadException

protected void setReadException(java.io.IOException e)

setWriteException

protected void setWriteException(java.io.IOException e)

notifySocketsOfException

protected void notifySocketsOfException()

setEOF

protected void setEOF()

shutdown

protected void shutdown()


Copyright © 1998-2005 JBoss Inc . All Rights Reserved.