org.jboss.remoting.transport.multiplex
Class VirtualSocket

java.lang.Object
  extended byjava.net.Socket
      extended byorg.jboss.remoting.transport.multiplex.VirtualSocket

public class VirtualSocket
extends java.net.Socket

Copyright (c) 2005

Author:
Ron Sigal

Nested Class Summary
static interface VirtualSocket.DisconnectListener
           
protected  class VirtualSocket.PendingClose
           
 
Field Summary
protected static java.lang.Thread closingThread
           
protected static org.jboss.logging.Logger log
           
 
Constructor Summary
VirtualSocket()
           
VirtualSocket(java.net.InetAddress address, int port)
           
VirtualSocket(java.net.InetAddress host, int port, boolean stream)
           
VirtualSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort)
           
VirtualSocket(MultiplexingManager manager, SocketId remoteSocketId)
           
VirtualSocket(java.net.SocketImpl impl)
           
VirtualSocket(java.lang.String host, int port)
           
VirtualSocket(java.lang.String host, int port, boolean stream)
           
VirtualSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort)
           
 
Method Summary
 void addDisconnectListener(VirtualSocket.DisconnectListener listener)
           
 void bind(java.net.SocketAddress address)
          Binds the socket to a local address.
 void close()
           
 void connect(java.net.SocketAddress socketAddress)
          Connects this socket to the server.
 void connect(java.net.SocketAddress socketAddress, int timeout)
          Connects this socket to the server with a specified timeout value.
 void connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, int timeout)
           
protected  void doClose()
           
protected  java.net.Socket getActualSocket()
           
 java.nio.channels.SocketChannel getChannel()
           
 java.net.InetAddress getInetAddress()
           
 java.io.InputStream getInputStream()
           
 boolean getKeepAlive()
           
 java.net.InetAddress getLocalAddress()
          Note.
 int getLocalPort()
           
 java.net.SocketAddress getLocalSocketAddress()
           
 SocketId getLocalSocketId()
           
 int getLocalVirtualPort()
           
protected  MultiplexingManager getManager()
           
 MultiplexingManager getMultiplexingManager()
           
 boolean getOOBInline()
           
 java.io.OutputStream getOutputStream()
           
 int getPort()
           
protected  Protocol getProtocol()
           
 int getReceiveBufferSize()
           
 java.net.SocketAddress getRemoteSocketAddress()
           
 SocketId getRemoteSocketId()
           
 boolean getReuseAddress()
           
 int getSendBufferSize()
           
 javax.net.SocketFactory getSocketFactory()
           
 int getSoLinger()
           
 int getSoTimeout()
           
 boolean getTcpNoDelay()
           
 int getTrafficClass()
           
 int getVirtualPort()
           
protected  void handleRemoteDisconnect()
           
protected  void handleRemoteOutputShutDown()
          FIXME Comment this
protected  boolean hasReceivedDisconnectMessage()
           
 boolean isBound()
           
 boolean isClosed()
          Returns the closed state of the socket.
 boolean isConnected()
          Returns the connected state of the socket.
 boolean isInputShutdown()
          Returns whether the read-half of the socket connection is closed.
 boolean isOutputShutdown()
          Returns whether the write-half of the socket connection is closed.
 void removeDisconnectListener(VirtualSocket.DisconnectListener listener)
           
 void sendUrgentData(int data)
           
protected  void setActualSocket(java.net.Socket actualSocket)
           
protected  void setBound(boolean bound)
           
protected  void setClosed(boolean closed)
           
protected  void setConnected(boolean connected)
           
protected  void setInputShutdown(boolean inputShutdown)
           
protected  void setInputStream(MultiplexingInputStream inputStream)
           
 void setKeepAlive(boolean on)
           
protected  void setLocalSocketId(SocketId localSocketId)
           
protected  void setManager(MultiplexingManager manager)
           
 void setOOBInline(boolean on)
           
protected  void setOutputShutdown(boolean outputShutdown)
           
protected  void setOutputStream(MultiplexingOutputStream outputStream)
           
protected  void setProtocol(Protocol protocol)
           
 void setReceiveBufferSize(int size)
           
protected  void setReceivedDisconnectMessage(boolean receivedDisconnectMessage)
           
protected  void setRemoteSocketId(SocketId remoteSocketId)
           
 void setReuseAddress(boolean on)
           
 void setSendBufferSize(int size)
           
 void setSocketFactory(javax.net.SocketFactory socketFactory)
           
 void setSoLinger(boolean on, int linger)
           
 void setSoTimeout(int timeout)
           
 void setTcpNoDelay(boolean on)
           
 void setTrafficClass(int tc)
           
 void shutdownInput()
           
 void shutdownOutput()
           
 
Methods inherited from class java.net.Socket
setSocketImplFactory, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.jboss.logging.Logger log

closingThread

protected static java.lang.Thread closingThread
Constructor Detail

VirtualSocket

public VirtualSocket(MultiplexingManager manager,
                     SocketId remoteSocketId)
              throws java.io.IOException

VirtualSocket

public VirtualSocket()

VirtualSocket

public VirtualSocket(java.lang.String host,
                     int port)
              throws java.net.UnknownHostException,
                     java.io.IOException

VirtualSocket

public VirtualSocket(java.lang.String host,
                     int port,
                     boolean stream)
              throws java.io.IOException
Parameters:
host -
port -
stream -
Throws:
java.io.IOException

VirtualSocket

public VirtualSocket(java.net.InetAddress address,
                     int port)
              throws java.io.IOException
Parameters:
address -
port -
Throws:
java.io.IOException

VirtualSocket

public VirtualSocket(java.net.InetAddress host,
                     int port,
                     boolean stream)
              throws java.io.IOException
Parameters:
host -
port -
stream -
Throws:
java.io.IOException

VirtualSocket

public VirtualSocket(java.net.SocketImpl impl)
              throws java.net.SocketException
Parameters:
impl -
Throws:
java.net.SocketException

VirtualSocket

public VirtualSocket(java.lang.String host,
                     int port,
                     java.net.InetAddress localAddr,
                     int localPort)
              throws java.io.IOException
Parameters:
host -
port -
localAddr -
localPort -
Throws:
java.io.IOException

VirtualSocket

public VirtualSocket(java.net.InetAddress address,
                     int port,
                     java.net.InetAddress localAddr,
                     int localPort)
              throws java.io.IOException
Parameters:
address -
port -
localAddr -
localPort -
Throws:
java.io.IOException
Method Detail

bind

public void bind(java.net.SocketAddress address)
          throws java.io.IOException
Binds the socket to a local address.

If the address is null, then the system will pick up an ephemeral port and a valid local address to bind the socket. TODO: security

Parameters:
address - the SocketAddress to bind to
Throws:
java.io.IOException - if the bind operation fails, or if the socket is already bound.
java.lang.IllegalArgumentException - if bindpoint is a SocketAddress subclass not supported by this socket

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

connect

public void connect(java.net.SocketAddress socketAddress)
             throws java.io.IOException
Connects this socket to the server.

Parameters:
socketAddress - the SocketAddress
Throws:
java.io.IOException - if an error occurs during the connection
java.lang.IllegalArgumentException - if endpoint is null or is a SocketAddress subclass not supported by this socket

connect

public void connect(java.net.SocketAddress socketAddress,
                    int timeout)
             throws java.io.IOException
Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.

Parameters:
socketAddress - the SocketAddress
timeout - the timeout value to be used in milliseconds.
Throws:
java.io.IOException - if an error occurs during the connection
java.net.SocketTimeoutException - if timeout expires before connecting
java.lang.IllegalArgumentException - if endpoint is null or is a SocketAddress subclass not supported by this socket

getChannel

public java.nio.channels.SocketChannel getChannel()

getInetAddress

public java.net.InetAddress getInetAddress()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Throws:
java.io.IOException

getKeepAlive

public boolean getKeepAlive()
                     throws java.net.SocketException
Throws:
java.net.SocketException

getLocalAddress

public java.net.InetAddress getLocalAddress()
Note. Socket.getLocalAddress() returns "wildcard" address for an unbound socket.


getLocalPort

public int getLocalPort()

getLocalSocketAddress

public java.net.SocketAddress getLocalSocketAddress()

getOOBInline

public boolean getOOBInline()
                     throws java.net.SocketException
Throws:
java.net.SocketException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Throws:
java.io.IOException

getPort

public int getPort()

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Throws:
java.net.SocketException

getRemoteSocketAddress

public java.net.SocketAddress getRemoteSocketAddress()

getReuseAddress

public boolean getReuseAddress()
                        throws java.net.SocketException
Throws:
java.net.SocketException

getSendBufferSize

public int getSendBufferSize()
                      throws java.net.SocketException
Throws:
java.net.SocketException

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
Throws:
java.net.SocketException

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Throws:
java.net.SocketException

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws java.net.SocketException
Throws:
java.net.SocketException

getTrafficClass

public int getTrafficClass()
                    throws java.net.SocketException
Throws:
java.net.SocketException

isBound

public boolean isBound()
Returns:
Returns the bound.

isClosed

public boolean isClosed()
Returns the closed state of the socket.


isConnected

public boolean isConnected()
Returns the connected state of the socket.


isInputShutdown

public boolean isInputShutdown()
Returns whether the read-half of the socket connection is closed.


isOutputShutdown

public boolean isOutputShutdown()
Returns whether the write-half of the socket connection is closed.


sendUrgentData

public void sendUrgentData(int data)
                    throws java.io.IOException
Throws:
java.io.IOException

setKeepAlive

public void setKeepAlive(boolean on)
                  throws java.net.SocketException
Throws:
java.net.SocketException

setOOBInline

public void setOOBInline(boolean on)
                  throws java.net.SocketException
Throws:
java.net.SocketException

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
Throws:
java.net.SocketException

setReuseAddress

public void setReuseAddress(boolean on)
                     throws java.net.SocketException
Throws:
java.net.SocketException

setSendBufferSize

public void setSendBufferSize(int size)
                       throws java.net.SocketException
Throws:
java.net.SocketException

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws java.net.SocketException
Throws:
java.net.SocketException

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Throws:
java.net.SocketException

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws java.net.SocketException
Throws:
java.net.SocketException

setTrafficClass

public void setTrafficClass(int tc)
                     throws java.net.SocketException
Throws:
java.net.SocketException

shutdownInput

public void shutdownInput()
                   throws java.io.IOException
Throws:
java.io.IOException

shutdownOutput

public void shutdownOutput()
                    throws java.io.IOException
Throws:
java.io.IOException

addDisconnectListener

public void addDisconnectListener(VirtualSocket.DisconnectListener listener)

connect

public void connect(java.net.SocketAddress remoteAddress,
                    java.net.SocketAddress localAddress,
                    int timeout)
             throws java.io.IOException
Throws:
java.io.IOException

getMultiplexingManager

public MultiplexingManager getMultiplexingManager()

getVirtualPort

public int getVirtualPort()

getLocalVirtualPort

public int getLocalVirtualPort()

getLocalSocketId

public SocketId getLocalSocketId()
Returns:

getRemoteSocketId

public SocketId getRemoteSocketId()
Returns:

getSocketFactory

public javax.net.SocketFactory getSocketFactory()
Returns:

removeDisconnectListener

public void removeDisconnectListener(VirtualSocket.DisconnectListener listener)
Parameters:
listener -

setSocketFactory

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

getActualSocket

protected java.net.Socket getActualSocket()
Returns:
Returns the actualSocket.

setActualSocket

protected void setActualSocket(java.net.Socket actualSocket)
Parameters:
actualSocket - The actualSocket to set.

setBound

protected void setBound(boolean bound)
Parameters:
bound - The bound to set.

setClosed

protected void setClosed(boolean closed)
Parameters:
closed - The closed to set.

setConnected

protected void setConnected(boolean connected)
Parameters:
connected - The connected to set.

setInputShutdown

protected void setInputShutdown(boolean inputShutdown)
Parameters:
inputShutdown - The inputShutdown to set.

setInputStream

protected void setInputStream(MultiplexingInputStream inputStream)
Parameters:
inputStream - The inputStream to set.

setLocalSocketId

protected void setLocalSocketId(SocketId localSocketId)
Parameters:
localSocketId - The localSocketId to set.

getManager

protected MultiplexingManager getManager()
Returns:

setManager

protected void setManager(MultiplexingManager manager)
Parameters:
manager - The manager to set.

setOutputShutdown

protected void setOutputShutdown(boolean outputShutdown)
Parameters:
outputShutdown - The outputShutdown to set.

setOutputStream

protected void setOutputStream(MultiplexingOutputStream outputStream)
Parameters:
outputStream - The outputStream to set.

getProtocol

protected Protocol getProtocol()
Returns:
Returns the protocol.

setProtocol

protected void setProtocol(Protocol protocol)
Parameters:
protocol - The protocol to set.

hasReceivedDisconnectMessage

protected boolean hasReceivedDisconnectMessage()
Returns:

setReceivedDisconnectMessage

protected void setReceivedDisconnectMessage(boolean receivedDisconnectMessage)
Parameters:
receivedDisconnectMessage -

setRemoteSocketId

protected void setRemoteSocketId(SocketId remoteSocketId)
Parameters:
remoteSocketId - The remoteSocketId to set.

doClose

protected void doClose()

handleRemoteOutputShutDown

protected void handleRemoteOutputShutDown()
                                   throws java.io.IOException
FIXME Comment this

Throws:
java.io.IOException

handleRemoteDisconnect

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


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