org.apache.activemq.transport.tcp
Class TcpTransportServer

java.lang.Object
  extended by org.apache.activemq.util.ServiceSupport
      extended by org.apache.activemq.transport.TransportServerSupport
          extended by org.apache.activemq.transport.TransportServerThreadSupport
              extended by org.apache.activemq.transport.tcp.TcpTransportServer
All Implemented Interfaces:
Runnable, Service, TransportServer, ServiceListener
Direct Known Subclasses:
NIOSSLTransportServer, SslTransportServer

public class TcpTransportServer
extends TransportServerThreadSupport
implements ServiceListener

A TCP based implementation of TransportServer

Author:
David Martin Clavo david(dot)martin(dot)clavo(at)gmail.com (logging improvement modifications)

Field Summary
protected  int backlog
           
protected  int connectionTimeout
           
protected  AtomicInteger currentTransportCount
           
protected  boolean dynamicManagement
          Specifies if the TransportLogger will be manageable by JMX or not.
protected  String logWriterName
          Name of the LogWriter implementation to use.
protected  int maximumConnections
          The maximum number of sockets allowed for this server
protected  long maxInactivityDuration
           
protected  long maxInactivityDurationInitalDelay
           
protected  int minmumWireFormatVersion
           
protected  ServerSocket serverSocket
           
protected  ServerSocketFactory serverSocketFactory
           
protected  int socketBufferSize
           
protected  Thread socketHandlerThread
           
protected  BlockingQueue<Socket> socketQueue
           
protected  int soTimeout
           
protected  boolean startLogging
          startLogging=true -> the TransportLogger object of the Transport stack will initially write messages to the log.
protected  boolean trace
          trace=true -> the Transport stack where this TcpTransport object will be, will have a TransportLogger layer trace=false -> the Transport stack where this TcpTransport object will be, will NOT have a TransportLogger layer, and therefore will never be able to print logging messages.
protected  TcpTransportFactory transportFactory
           
protected  boolean useQueueForAccept
           
protected  WireFormatFactory wireFormatFactory
           
 
Fields inherited from class org.apache.activemq.transport.TransportServerSupport
transportOptions
 
Constructor Summary
TcpTransportServer(TcpTransportFactory transportFactory, URI location, ServerSocketFactory serverSocketFactory)
           
 
Method Summary
 void bind()
           
protected  Transport createTransport(Socket socket, WireFormat format)
          Allow derived classes to override the Transport implementation that this transport server creates.
protected  void doStart()
           
protected  void doStop(ServiceStopper stopper)
           
 int getBacklog()
           
 int getConnectionTimeout()
           
 String getLogWriterName()
           
 int getMaximumConnections()
           
 long getMaxInactivityDuration()
           
 long getMaxInactivityDurationInitalDelay()
           
 int getMinmumWireFormatVersion()
           
 InetSocketAddress getSocketAddress()
           
 int getSocketBufferSize()
           
 int getSoTimeout()
           
 WireFormatFactory getWireFormatFactory()
           
protected  void handleSocket(Socket socket)
           
 boolean isDynamicManagement()
           
 boolean isSslServer()
          For TransportServers that provide SSL connections to their connected peers they should return true here if and only if they populate the ConnectionInfo command presented to the Broker with the peers certificate chain so that the broker knows it can use that information to authenticate the connected peer.
 boolean isStartLogging()
           
 boolean isTrace()
           
 boolean isUseQueueForAccept()
           
protected  String resolveHostName(ServerSocket socket, InetAddress bindAddress)
           
 void run()
          pull Sockets from the ServerSocket
 void setBacklog(int backlog)
           
 void setBrokerInfo(BrokerInfo brokerInfo)
          Associates a broker info with the transport server so that the transport can do discovery advertisements of the broker.
 void setConnectionTimeout(int connectionTimeout)
           
 void setDynamicManagement(boolean useJmx)
           
 void setLogWriterName(String logFormat)
           
 void setMaximumConnections(int maximumConnections)
           
 void setMaxInactivityDuration(long maxInactivityDuration)
           
 void setMaxInactivityDurationInitalDelay(long maxInactivityDurationInitalDelay)
           
 void setMinmumWireFormatVersion(int minmumWireFormatVersion)
           
 void setSocketBufferSize(int socketBufferSize)
           
 void setSoTimeout(int soTimeout)
           
 void setStartLogging(boolean startLogging)
           
 void setTrace(boolean trace)
           
 void setUseQueueForAccept(boolean useQueueForAccept)
           
 void setWireFormatFactory(WireFormatFactory wireFormatFactory)
           
 void started(Service service)
           
 void stopped(Service service)
           
 String toString()
           
 
Methods inherited from class org.apache.activemq.transport.TransportServerThreadSupport
getStackSize, isDaemon, isJoinOnStop, setDaemon, setJoinOnStop, setStackSize
 
Methods inherited from class org.apache.activemq.transport.TransportServerSupport
getAcceptListener, getBindLocation, getConnectURI, onAcceptError, setAcceptListener, setBindLocation, setConnectURI, setTransportOption
 
Methods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, postStop, preStart, removeServiceListener, 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.Service
start, stop
 

Field Detail

serverSocket

protected ServerSocket serverSocket

backlog

protected int backlog

wireFormatFactory

protected WireFormatFactory wireFormatFactory

transportFactory

protected final TcpTransportFactory transportFactory

maxInactivityDuration

protected long maxInactivityDuration

maxInactivityDurationInitalDelay

protected long maxInactivityDurationInitalDelay

minmumWireFormatVersion

protected int minmumWireFormatVersion

useQueueForAccept

protected boolean useQueueForAccept

trace

protected boolean trace
trace=true -> the Transport stack where this TcpTransport object will be, will have a TransportLogger layer trace=false -> the Transport stack where this TcpTransport object will be, will NOT have a TransportLogger layer, and therefore will never be able to print logging messages. This parameter is most probably set in Connection or TransportConnector URIs.


soTimeout

protected int soTimeout

socketBufferSize

protected int socketBufferSize

connectionTimeout

protected int connectionTimeout

logWriterName

protected String logWriterName
Name of the LogWriter implementation to use. Names are mapped to classes in the resources/META-INF/services/org/apache/activemq/transport/logwriters directory. This parameter is most probably set in Connection or TransportConnector URIs.


dynamicManagement

protected boolean dynamicManagement
Specifies if the TransportLogger will be manageable by JMX or not. Also, as long as there is at least 1 TransportLogger which is manageable, a TransportLoggerControl MBean will me created.


startLogging

protected boolean startLogging
startLogging=true -> the TransportLogger object of the Transport stack will initially write messages to the log. startLogging=false -> the TransportLogger object of the Transport stack will initially NOT write messages to the log. This parameter only has an effect if trace == true. This parameter is most probably set in Connection or TransportConnector URIs.


serverSocketFactory

protected final ServerSocketFactory serverSocketFactory

socketQueue

protected BlockingQueue<Socket> socketQueue

socketHandlerThread

protected Thread socketHandlerThread

maximumConnections

protected int maximumConnections
The maximum number of sockets allowed for this server


currentTransportCount

protected AtomicInteger currentTransportCount
Constructor Detail

TcpTransportServer

public TcpTransportServer(TcpTransportFactory transportFactory,
                          URI location,
                          ServerSocketFactory serverSocketFactory)
                   throws IOException,
                          URISyntaxException
Throws:
IOException
URISyntaxException
Method Detail

bind

public void bind()
          throws IOException
Throws:
IOException

getWireFormatFactory

public WireFormatFactory getWireFormatFactory()
Returns:
Returns the wireFormatFactory.

setWireFormatFactory

public void setWireFormatFactory(WireFormatFactory wireFormatFactory)
Parameters:
wireFormatFactory - The wireFormatFactory to set.

setBrokerInfo

public void setBrokerInfo(BrokerInfo brokerInfo)
Associates a broker info with the transport server so that the transport can do discovery advertisements of the broker.

Specified by:
setBrokerInfo in interface TransportServer
Parameters:
brokerInfo -

getMaxInactivityDuration

public long getMaxInactivityDuration()

setMaxInactivityDuration

public void setMaxInactivityDuration(long maxInactivityDuration)

getMaxInactivityDurationInitalDelay

public long getMaxInactivityDurationInitalDelay()

setMaxInactivityDurationInitalDelay

public void setMaxInactivityDurationInitalDelay(long maxInactivityDurationInitalDelay)

getMinmumWireFormatVersion

public int getMinmumWireFormatVersion()

setMinmumWireFormatVersion

public void setMinmumWireFormatVersion(int minmumWireFormatVersion)

isTrace

public boolean isTrace()

setTrace

public void setTrace(boolean trace)

getLogWriterName

public String getLogWriterName()

setLogWriterName

public void setLogWriterName(String logFormat)

isDynamicManagement

public boolean isDynamicManagement()

setDynamicManagement

public void setDynamicManagement(boolean useJmx)

isStartLogging

public boolean isStartLogging()

setStartLogging

public void setStartLogging(boolean startLogging)

getBacklog

public int getBacklog()
Returns:
the backlog

setBacklog

public void setBacklog(int backlog)
Parameters:
backlog - the backlog to set

isUseQueueForAccept

public boolean isUseQueueForAccept()
Returns:
the useQueueForAccept

setUseQueueForAccept

public void setUseQueueForAccept(boolean useQueueForAccept)
Parameters:
useQueueForAccept - the useQueueForAccept to set

run

public void run()
pull Sockets from the ServerSocket

Specified by:
run in interface Runnable

createTransport

protected Transport createTransport(Socket socket,
                                    WireFormat format)
                             throws IOException
Allow derived classes to override the Transport implementation that this transport server creates.

Parameters:
socket -
format -
Returns:
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object
Returns:
pretty print of this

resolveHostName

protected String resolveHostName(ServerSocket socket,
                                 InetAddress bindAddress)
                          throws UnknownHostException
Parameters:
socket -
inetAddress -
Returns:
real hostName
Throws:
UnknownHostException

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class TransportServerThreadSupport
Throws:
Exception

doStop

protected void doStop(ServiceStopper stopper)
               throws Exception
Overrides:
doStop in class TransportServerThreadSupport
Throws:
Exception

getSocketAddress

public InetSocketAddress getSocketAddress()
Specified by:
getSocketAddress in interface TransportServer
Returns:
The socket address that this transport is accepting connections on or null if this does not or is not currently accepting connections on a socket.

handleSocket

protected final void handleSocket(Socket socket)

getSoTimeout

public int getSoTimeout()

setSoTimeout

public void setSoTimeout(int soTimeout)

getSocketBufferSize

public int getSocketBufferSize()

setSocketBufferSize

public void setSocketBufferSize(int socketBufferSize)

getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)

getMaximumConnections

public int getMaximumConnections()
Returns:
the maximumConnections

setMaximumConnections

public void setMaximumConnections(int maximumConnections)
Parameters:
maximumConnections - the maximumConnections to set

started

public void started(Service service)
Specified by:
started in interface ServiceListener

stopped

public void stopped(Service service)
Specified by:
stopped in interface ServiceListener

isSslServer

public boolean isSslServer()
Description copied from interface: TransportServer
For TransportServers that provide SSL connections to their connected peers they should return true here if and only if they populate the ConnectionInfo command presented to the Broker with the peers certificate chain so that the broker knows it can use that information to authenticate the connected peer.

Specified by:
isSslServer in interface TransportServer
Returns:
true if this transport server provides SSL level security over its connections.


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.