org.activemq.transport.tcp
Class TcpTransportChannel

java.lang.Object
  extended by org.activemq.transport.TransportChannelSupport
      extended by org.activemq.transport.tcp.TcpTransportChannel
All Implemented Interfaces:
Runnable, Service, TransportChannel
Direct Known Subclasses:
JabberTransportChannel, StompTransportChannel

public class TcpTransportChannel
extends TransportChannelSupport
implements Runnable

A tcp implementation of a TransportChannel

Version:
$Revision: 1.2 $

Field Summary
protected  DataInputStream dataIn
           
protected  DataOutputStream dataOut
           
protected  Socket socket
           
 
Fields inherited from class org.activemq.transport.TransportChannelSupport
cachingEnabled, currentWireFormat, noDelay, pendingStop, transportConnected, usedInternally
 
Constructor Summary
  TcpTransportChannel(TcpTransportServerChannel serverChannel, WireFormat wireFormat, Socket socket, Executor executor)
          Initialize from a ServerSocket
protected TcpTransportChannel(WireFormat wireFormat)
          Construct basic helpers
  TcpTransportChannel(WireFormat wireFormat, Socket socket, Executor executor)
           
  TcpTransportChannel(WireFormat wireFormat, URI remoteLocation)
          Connect to a remote Node - e.g.
  TcpTransportChannel(WireFormat wireFormat, URI remoteLocation, URI localLocation)
          Connect to a remote Node - e.g.
 
Method Summary
 void asyncSend(Packet packet)
          Asynchronously send a Packet
 boolean canProcessWireFormatVersion(int version)
          Can this wireformat process packets of this version
protected  void closeStreams()
           
protected  Socket createSocket(URI remoteLocation)
          Factory method to create a new socket
protected  Socket createSocket(URI remoteLocation, URI localLocation)
          Factory method to create a new socket
protected  Packet doAsyncSend(Packet packet)
          Actually performs the async send of a packet
protected  void doClose(Exception ex)
           
 void forceDisconnect()
          Forces an immediate transport-level disconnect which will be asynchronously reported as an exception to the exceptionListener.
 int getCurrentWireFormatVersion()
           
 Socket getSocket()
           
 int getSocketBufferSize()
           
 int getSoTimeout()
           
protected  void initialiseSocket(Socket sock)
          Configures the socket for use
protected  void initializeStreams()
           
 boolean isClosed()
           
 boolean isMulticast()
           
 boolean isUseAsyncSend()
           
protected  void readWireFormat()
           
 void run()
          reads packets from a Socket
 void setNoDelay(boolean noDelay)
           
 void setSocketBufferSize(int socketBufferSize)
           
 void setSoTimeout(int soTimeout)
          set the socket so timeout
 void setUseAsyncSend(boolean useAsyncSend)
          set the useAsync flag
 void start()
          start listeneing for events
 void stop()
          close the channel
 String toString()
          pretty print for object
 
Methods inherited from class org.activemq.transport.TransportChannelSupport
addTransportStatusEventListener, asyncSendWithReceipt, doConsumePacket, doConsumePacket, doesSupportMessageCompression, doesSupportMessageFragmentation, doesSupportWireFormatVersioning, doHandleReceipt, doHandleWireFormat, fireStatusEvent, fireStatusEvent, getClientID, getEmbeddedBrokerConnector, getExceptionListener, getLastReceiptTimestamp, getPacketListener, getTransportChannelListener, getWireFormat, isCachingEnabled, isNoDelay, isPendingStop, isServerSide, isTransportConnected, isUsedInternally, onAsyncException, removeTransportStatusEventListener, requiresEmbeddedBroker, send, send, setCachingEnabled, setClientID, setExceptionListener, setPacketListener, setPendingStop, setServerSide, setTransportChannelListener, setTransportConnected, setUsedInternally, setWireFormat, stopExecutor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

socket

protected Socket socket

dataOut

protected DataOutputStream dataOut

dataIn

protected DataInputStream dataIn
Constructor Detail

TcpTransportChannel

protected TcpTransportChannel(WireFormat wireFormat)
Construct basic helpers

Parameters:
wireFormat -

TcpTransportChannel

public TcpTransportChannel(WireFormat wireFormat,
                           URI remoteLocation)
                    throws JMSException
Connect to a remote Node - e.g. a Broker

Parameters:
wireFormat -
remoteLocation -
Throws:
JMSException

TcpTransportChannel

public TcpTransportChannel(WireFormat wireFormat,
                           URI remoteLocation,
                           URI localLocation)
                    throws JMSException
Connect to a remote Node - e.g. a Broker

Parameters:
wireFormat -
remoteLocation -
localLocation - - e.g. local InetAddress and local port
Throws:
JMSException

TcpTransportChannel

public TcpTransportChannel(TcpTransportServerChannel serverChannel,
                           WireFormat wireFormat,
                           Socket socket,
                           Executor executor)
                    throws JMSException
Initialize from a ServerSocket

Parameters:
serverChannel -
wireFormat -
socket -
executor -
Throws:
JMSException

TcpTransportChannel

public TcpTransportChannel(WireFormat wireFormat,
                           Socket socket,
                           Executor executor)
                    throws JMSException
Throws:
JMSException
Method Detail

start

public void start()
           throws JMSException
start listeneing for events

Specified by:
start in interface Service
Specified by:
start in interface TransportChannel
Throws:
JMSException - if an error occurs

readWireFormat

protected void readWireFormat()
                       throws JMSException,
                              IOException
Throws:
JMSException
IOException

stop

public void stop()
close the channel

Specified by:
stop in interface Service
Specified by:
stop in interface TransportChannel
Overrides:
stop in class TransportChannelSupport

forceDisconnect

public void forceDisconnect()
Description copied from interface: TransportChannel
Forces an immediate transport-level disconnect which will be asynchronously reported as an exception to the exceptionListener. If the channel isn't connected, the call will be ignored.

Specified by:
forceDisconnect in interface TransportChannel

asyncSend

public void asyncSend(Packet packet)
               throws JMSException
Asynchronously send a Packet

Specified by:
asyncSend in interface TransportChannel
Parameters:
packet -
Throws:
JMSException

isMulticast

public boolean isMulticast()
Specified by:
isMulticast in interface TransportChannel
Overrides:
isMulticast in class TransportChannelSupport
Returns:
false

run

public void run()
reads packets from a Socket

Specified by:
run in interface Runnable

isClosed

public boolean isClosed()

toString

public String toString()
pretty print for object

Overrides:
toString in class Object
Returns:
String representation of this object

getSocket

public Socket getSocket()
Returns:
the socket used by the TcpTransportChannel

canProcessWireFormatVersion

public boolean canProcessWireFormatVersion(int version)
Can this wireformat process packets of this version

Specified by:
canProcessWireFormatVersion in interface TransportChannel
Overrides:
canProcessWireFormatVersion in class TransportChannelSupport
Parameters:
version - the version number to test
Returns:
true if can accept the version

getCurrentWireFormatVersion

public int getCurrentWireFormatVersion()
Specified by:
getCurrentWireFormatVersion in interface TransportChannel
Overrides:
getCurrentWireFormatVersion in class TransportChannelSupport
Returns:
the current version of this wire format

isUseAsyncSend

public boolean isUseAsyncSend()
Returns:
true if packets are enqueued to a separate queue before dispatching

setUseAsyncSend

public void setUseAsyncSend(boolean useAsyncSend)
set the useAsync flag

Parameters:
useAsyncSend -

getSoTimeout

public int getSoTimeout()
Returns:
the current so timeout used on the socket

setSoTimeout

public void setSoTimeout(int soTimeout)
                  throws JMSException
set the socket so timeout

Parameters:
soTimeout -
Throws:
JMSException

setNoDelay

public void setNoDelay(boolean noDelay)
Specified by:
setNoDelay in interface TransportChannel
Overrides:
setNoDelay in class TransportChannelSupport
Parameters:
noDelay - The noDelay to set.

getSocketBufferSize

public int getSocketBufferSize()
Returns:
Returns the socketBufferSize.

setSocketBufferSize

public void setSocketBufferSize(int socketBufferSize)
Parameters:
socketBufferSize - The socketBufferSize to set.

doAsyncSend

protected Packet doAsyncSend(Packet packet)
                      throws JMSException
Actually performs the async send of a packet

Overrides:
doAsyncSend in class TransportChannelSupport
Parameters:
packet -
Returns:
a response or null
Throws:
JMSException

doClose

protected void doClose(Exception ex)

initialiseSocket

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

Parameters:
sock -
Throws:
SocketException

initializeStreams

protected void initializeStreams()
                          throws IOException
Throws:
IOException

closeStreams

protected void closeStreams()
                     throws IOException
Throws:
IOException

createSocket

protected Socket createSocket(URI remoteLocation)
                       throws UnknownHostException,
                              IOException
Factory method to create a new socket

Parameters:
remoteLocation - the URI to connect to
Returns:
the newly created socket
Throws:
UnknownHostException
IOException

createSocket

protected Socket createSocket(URI remoteLocation,
                              URI localLocation)
                       throws IOException,
                              UnknownHostException
Factory method to create a new socket

Parameters:
remoteLocation -
localLocation -
Returns:
@throws IOException
Throws:
IOException
UnknownHostException


Copyright © 2004-2008 Protique, Ltd.. All Rights Reserved.