org.apache.activemq.transport.tcp
Class TcpTransport

java.lang.Object
  extended by org.apache.activemq.util.ServiceSupport
      extended by org.apache.activemq.transport.TransportSupport
          extended by org.apache.activemq.transport.TransportThreadSupport
              extended by org.apache.activemq.transport.tcp.TcpTransport
All Implemented Interfaces:
java.lang.Runnable, Service, Transport
Direct Known Subclasses:
SslTransport, XmppTransport

public class TcpTransport
extends TransportThreadSupport
implements Transport, Service, java.lang.Runnable

An implementation of the Transport interface using raw tcp/ip

Version:
$Revision$

Field Summary
protected  int connectionTimeout
           
protected  java.io.DataInputStream dataIn
           
protected  java.io.DataOutputStream dataOut
           
protected  int ioBufferSize
           
protected  java.net.URI localLocation
           
protected  int minmumWireFormatVersion
           
protected  java.net.URI remoteLocation
           
protected  java.net.Socket socket
           
protected  int socketBufferSize
           
protected  javax.net.SocketFactory socketFactory
           
protected  int soTimeout
           
protected  boolean trace
           
protected  boolean useLocalHost
           
protected  WireFormat wireFormat
           
 
Constructor Summary
TcpTransport(WireFormat wireFormat, java.net.Socket socket)
          Initialize from a server Socket
TcpTransport(WireFormat wireFormat, javax.net.SocketFactory socketFactory, java.net.URI remoteLocation, java.net.URI localLocation)
          Connect to a remote Node - e.g.
 
Method Summary
protected  void closeStreams()
           
protected  void connect()
           
protected  void doStart()
           
protected  void doStop(ServiceStopper stopper)
           
 int getConnectionTimeout()
           
 int getIoBufferSize()
           
 java.lang.Boolean getKeepAlive()
           
 int getMinmumWireFormatVersion()
           
 java.lang.String getRemoteAddress()
           
 int getSocketBufferSize()
           
 int getSoTimeout()
           
 java.lang.Boolean getTcpNoDelay()
           
protected  void initialiseSocket(java.net.Socket sock)
          Configures the socket for use
protected  void initializeStreams()
           
 boolean isTrace()
           
 boolean isUseLocalHost()
           
 void oneway(java.lang.Object command)
          A one way asynchronous send
protected  java.lang.Object readCommand()
           
protected  java.lang.String resolveHostName(java.lang.String host)
           
 void run()
          reads packets from a Socket
 void setConnectionTimeout(int connectionTimeout)
          Sets the timeout used to connect to the socket
 void setIoBufferSize(int ioBufferSize)
           
 void setKeepAlive(java.lang.Boolean keepAlive)
          Enable/disable TCP KEEP_ALIVE mode
 void setMinmumWireFormatVersion(int minmumWireFormatVersion)
           
 void setSocketBufferSize(int socketBufferSize)
          Sets the buffer size to use on the socket
 void setSocketOptions(java.util.Map socketOptions)
           
 void setSoTimeout(int soTimeout)
          Sets the socket timeout
 void setTcpNoDelay(java.lang.Boolean tcpNoDelay)
          Enable/disable the TCP_NODELAY option on the socket
 void setTrace(boolean trace)
           
 void setUseLocalHost(boolean useLocalHost)
          Sets whether 'localhost' or the actual local host name should be used to make local connections.
 java.lang.String toString()
           
 
Methods inherited from class org.apache.activemq.transport.TransportThreadSupport
isDaemon, setDaemon
 
Methods inherited from class org.apache.activemq.transport.TransportSupport
asyncRequest, checkStarted, doConsume, getTransportListener, narrow, onException, request, request, setTransportListener
 
Methods inherited from class org.apache.activemq.util.ServiceSupport
dispose, isStarted, isStopped, isStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.activemq.transport.Transport
asyncRequest, getTransportListener, narrow, request, request, setTransportListener
 
Methods inherited from interface org.apache.activemq.Service
start, stop
 

Field Detail

remoteLocation

protected final java.net.URI remoteLocation

localLocation

protected final java.net.URI localLocation

wireFormat

protected final WireFormat wireFormat

connectionTimeout

protected int connectionTimeout

soTimeout

protected int soTimeout

socketBufferSize

protected int socketBufferSize

ioBufferSize

protected int ioBufferSize

socket

protected java.net.Socket socket

dataOut

protected java.io.DataOutputStream dataOut

dataIn

protected java.io.DataInputStream dataIn

trace

protected boolean trace

useLocalHost

protected boolean useLocalHost

minmumWireFormatVersion

protected int minmumWireFormatVersion

socketFactory

protected javax.net.SocketFactory socketFactory
Constructor Detail

TcpTransport

public TcpTransport(WireFormat wireFormat,
                    javax.net.SocketFactory socketFactory,
                    java.net.URI remoteLocation,
                    java.net.URI localLocation)
             throws java.net.UnknownHostException,
                    java.io.IOException
Connect to a remote Node - e.g. a Broker

Parameters:
wireFormat -
socketFactory -
remoteLocation -
localLocation - - e.g. local InetAddress and local port
Throws:
java.io.IOException
java.net.UnknownHostException

TcpTransport

public TcpTransport(WireFormat wireFormat,
                    java.net.Socket socket)
             throws java.io.IOException
Initialize from a server Socket

Parameters:
wireFormat -
socket -
Throws:
java.io.IOException
Method Detail

oneway

public void oneway(java.lang.Object command)
            throws java.io.IOException
A one way asynchronous send

Specified by:
oneway in interface Transport
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
pretty print of 'this'

run

public void run()
reads packets from a Socket

Specified by:
run in interface java.lang.Runnable

readCommand

protected java.lang.Object readCommand()
                                throws java.io.IOException
Throws:
java.io.IOException

isTrace

public boolean isTrace()

setTrace

public void setTrace(boolean trace)

getMinmumWireFormatVersion

public int getMinmumWireFormatVersion()

setMinmumWireFormatVersion

public void setMinmumWireFormatVersion(int minmumWireFormatVersion)

isUseLocalHost

public boolean isUseLocalHost()

setUseLocalHost

public void setUseLocalHost(boolean useLocalHost)
Sets whether 'localhost' or the actual local host name should be used to make local connections. On some operating systems such as Macs its not possible to connect as the local host name so localhost is better.


getSocketBufferSize

public int getSocketBufferSize()

setSocketBufferSize

public void setSocketBufferSize(int socketBufferSize)
Sets the buffer size to use on the socket


getSoTimeout

public int getSoTimeout()

setSoTimeout

public void setSoTimeout(int soTimeout)
Sets the socket timeout


getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Sets the timeout used to connect to the socket


getKeepAlive

public java.lang.Boolean getKeepAlive()

setKeepAlive

public void setKeepAlive(java.lang.Boolean keepAlive)
Enable/disable TCP KEEP_ALIVE mode


getTcpNoDelay

public java.lang.Boolean getTcpNoDelay()

setTcpNoDelay

public void setTcpNoDelay(java.lang.Boolean tcpNoDelay)
Enable/disable the TCP_NODELAY option on the socket


getIoBufferSize

public int getIoBufferSize()
Returns:
the ioBufferSize

setIoBufferSize

public void setIoBufferSize(int ioBufferSize)
Parameters:
ioBufferSize - the ioBufferSize to set

resolveHostName

protected java.lang.String resolveHostName(java.lang.String host)
                                    throws java.net.UnknownHostException
Throws:
java.net.UnknownHostException

initialiseSocket

protected void initialiseSocket(java.net.Socket sock)
                         throws java.net.SocketException
Configures the socket for use

Parameters:
sock -
Throws:
java.net.SocketException

doStart

protected void doStart()
                throws java.lang.Exception
Overrides:
doStart in class TransportThreadSupport
Throws:
java.lang.Exception

connect

protected void connect()
                throws java.lang.Exception
Throws:
java.lang.Exception

doStop

protected void doStop(ServiceStopper stopper)
               throws java.lang.Exception
Specified by:
doStop in class ServiceSupport
Throws:
java.lang.Exception

initializeStreams

protected void initializeStreams()
                          throws java.lang.Exception
Throws:
java.lang.Exception

closeStreams

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

setSocketOptions

public void setSocketOptions(java.util.Map socketOptions)

getRemoteAddress

public java.lang.String getRemoteAddress()
Specified by:
getRemoteAddress in interface Transport
Returns:
the remote address for this connection


Copyright © 2009 Apache Software Foundation. All Rights Reserved.