Class TcpTransport
java.lang.Object
org.apache.activemq.util.ServiceSupport
org.apache.activemq.transport.TransportSupport
org.apache.activemq.transport.TransportThreadSupport
org.apache.activemq.transport.tcp.TcpTransport
- Direct Known Subclasses:
NIOTransport
,SslTransport
An implementation of the
Transport
interface using raw tcp/ip-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected TimeStampStream
protected boolean
protected int
protected DataInputStream
protected DataOutputStream
protected boolean
Prevents setting both the Differentiated Services and Type of Service transport options at the same time, since they share the same spot in the TCP/IP packet headers.protected boolean
Specifies if the TransportLogger will be manageable by JMX or not.protected final TcpTransport.InitBuffer
protected int
protected int
Specifies the port that will be used by the JMX server to manage the TransportLoggers.protected final URI
protected String
Name of the LogWriter implementation to use.protected int
protected int
protected final URI
protected Socket
protected int
protected SocketFactory
protected int
protected boolean
startLogging=true -> the TransportLogger object of the Transport stack will initially write messages to the log.protected final AtomicReference<CountDownLatch>
protected boolean
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 int
The Traffic Class to be set on the socket.protected boolean
protected boolean
protected final WireFormat
-
Constructor Summary
ConstructorDescriptionTcpTransport
(WireFormat wireFormat, Socket socket) Initialize from a server SocketTcpTransport
(WireFormat wireFormat, Socket socket, TcpTransport.InitBuffer initBuffer) TcpTransport
(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation, URI localLocation) Connect to a remote Node - e.g. a Broker -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
connect()
protected void
doRun()
protected void
doStart()
protected void
doStop
(ServiceStopper stopper) int
int
int
int
int
Returns a counter which gets incremented as data is read from the transport.int
int
int
int
Retrieves the WireFormat instance associated with this Transport instance.protected void
initialiseSocket
(Socket sock) Configures the socket for useprotected void
boolean
boolean
boolean
boolean
isTrace()
boolean
<T> T
narrow acceptancevoid
A one way asynchronous sendprotected Object
protected String
resolveHostName
(String host) void
run()
reads packets from a Socketvoid
setCloseAsync
(boolean closeAsync) void
setConnectionTimeout
(int connectionTimeout) Sets the timeout used to connect to the socketvoid
setDiffServ
(String diffServ) void
setDynamicManagement
(boolean useJmx) void
setIoBufferSize
(int ioBufferSize) void
setJmxPort
(int jmxPort) void
setKeepAlive
(Boolean keepAlive) Enable/disable TCP KEEP_ALIVE modevoid
setLogWriterName
(String logFormat) void
setMinmumWireFormatVersion
(int minmumWireFormatVersion) void
setPeerCertificates
(X509Certificate[] certificates) Sets the certificates provided by the connected peer.void
setSocketBufferSize
(int socketBufferSize) Sets the buffer size to use on the socketvoid
setSocketOptions
(Map<String, Object> socketOptions) void
setSoLinger
(int soLinger) Enable/disable soLingervoid
setSoTimeout
(int soTimeout) Sets the socket timeoutvoid
setStartLogging
(boolean startLogging) void
setTcpNoDelay
(Boolean tcpNoDelay) Enable/disable the TCP_NODELAY option on the socketvoid
setTrace
(boolean trace) void
setTypeOfService
(int typeOfService) void
setUseLocalHost
(boolean useLocalHost) Sets whether 'localhost' or the actual local host name should be used to make local connections.void
stop()
Override so that stop() blocks until the run thread is no longer running.toString()
Methods inherited from class org.apache.activemq.transport.TransportThreadSupport
getStackSize, isDaemon, setDaemon, setStackSize
Methods inherited from class org.apache.activemq.transport.TransportSupport
asyncRequest, checkStarted, doConsume, getTransportListener, isConnected, isDisposed, isFaultTolerant, isReconnectSupported, isUpdateURIsSupported, onException, reconnect, request, request, setTransportListener, updateURIs
Methods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, postStop, preStart, removeServiceListener, start
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, isConnected, isDisposed, isFaultTolerant, isReconnectSupported, isUpdateURIsSupported, reconnect, request, request, setTransportListener, updateURIs
-
Field Details
-
remoteLocation
-
localLocation
-
wireFormat
-
connectionTimeout
protected int connectionTimeout -
soTimeout
protected int soTimeout -
socketBufferSize
protected int socketBufferSize -
ioBufferSize
protected int ioBufferSize -
closeAsync
protected boolean closeAsync -
socket
-
dataOut
-
dataIn
-
buffOut
-
initBuffer
-
trafficClass
protected int trafficClassThe Traffic Class to be set on the socket. -
diffServChosen
protected boolean diffServChosenPrevents setting both the Differentiated Services and Type of Service transport options at the same time, since they share the same spot in the TCP/IP packet headers. -
typeOfServiceChosen
protected boolean typeOfServiceChosen -
trace
protected boolean tracetrace=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. -
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 dynamicManagementSpecifies 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 startLoggingstartLogging=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. -
jmxPort
protected int jmxPortSpecifies the port that will be used by the JMX server to manage the TransportLoggers. This should only be set in an URI by a client (producer or consumer) since a broker will already create a JMX server. It is useful for people who test a broker and clients in the same machine and want to control both via JMX; a different port will be needed. -
useLocalHost
protected boolean useLocalHost -
minmumWireFormatVersion
protected int minmumWireFormatVersion -
socketFactory
-
stoppedLatch
-
receiveCounter
protected volatile int receiveCounter -
socketOptions
-
-
Constructor Details
-
TcpTransport
public TcpTransport(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation, URI localLocation) throws UnknownHostException, IOException Connect to a remote Node - e.g. a Broker- Parameters:
wireFormat
-socketFactory
-remoteLocation
-localLocation
- - e.g. local InetAddress and local port- Throws:
IOException
UnknownHostException
-
TcpTransport
Initialize from a server Socket- Parameters:
wireFormat
-socket
-- Throws:
IOException
-
TcpTransport
public TcpTransport(WireFormat wireFormat, Socket socket, TcpTransport.InitBuffer initBuffer) throws IOException - Throws:
IOException
-
-
Method Details
-
oneway
A one way asynchronous send- Specified by:
oneway
in interfaceTransport
- Throws:
IOException
-
toString
-
run
public void run()reads packets from a Socket -
doRun
- Throws:
IOException
-
readCommand
- Throws:
IOException
-
getDiffServ
-
setDiffServ
- Throws:
IllegalArgumentException
-
getTypeOfService
public int getTypeOfService() -
setTypeOfService
public void setTypeOfService(int typeOfService) -
isTrace
public boolean isTrace() -
setTrace
public void setTrace(boolean trace) -
getLogWriterName
-
setLogWriterName
-
isDynamicManagement
public boolean isDynamicManagement() -
setDynamicManagement
public void setDynamicManagement(boolean useJmx) -
isStartLogging
public boolean isStartLogging() -
setStartLogging
public void setStartLogging(boolean startLogging) -
getJmxPort
public int getJmxPort() -
setJmxPort
public void setJmxPort(int jmxPort) -
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
-
setKeepAlive
Enable/disable TCP KEEP_ALIVE mode -
setSoLinger
public void setSoLinger(int soLinger) Enable/disable soLinger- Parameters:
soLinger
- enabled if > -1, disabled if == -1, system default otherwise
-
getSoLinger
public int getSoLinger() -
getTcpNoDelay
-
setTcpNoDelay
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
-
isCloseAsync
public boolean isCloseAsync()- Returns:
- the closeAsync
-
setCloseAsync
public void setCloseAsync(boolean closeAsync) - Parameters:
closeAsync
- the closeAsync to set
-
resolveHostName
- Throws:
UnknownHostException
-
initialiseSocket
Configures the socket for use- Parameters:
sock
- the socket- Throws:
SocketException
IllegalArgumentException
-
doStart
- Overrides:
doStart
in classTransportThreadSupport
- Throws:
Exception
-
connect
- Throws:
Exception
-
doStop
- Specified by:
doStop
in classServiceSupport
- Throws:
Exception
-
stop
Override so that stop() blocks until the run thread is no longer running.- Specified by:
stop
in interfaceService
- Overrides:
stop
in classServiceSupport
- Throws:
Exception
-
initializeStreams
- Throws:
Exception
-
closeStreams
- Throws:
IOException
-
setSocketOptions
-
getRemoteAddress
- Specified by:
getRemoteAddress
in interfaceTransport
- Returns:
- the remote address for this connection
-
narrow
Description copied from class:TransportSupport
narrow acceptance- Specified by:
narrow
in interfaceTransport
- Overrides:
narrow
in classTransportSupport
- Returns:
- 'this' if assignable
-
getReceiveCounter
public int getReceiveCounter()Description copied from interface:Transport
Returns a counter which gets incremented as data is read from the transport. It should only be used to determine if there is progress being made in reading the next command from the transport. The value may wrap into the negative numbers.- Specified by:
getReceiveCounter
in interfaceTransport
- Returns:
- a counter which gets incremented as data is read from the transport.
-
getWireFormat
Description copied from interface:Transport
Retrieves the WireFormat instance associated with this Transport instance.- Specified by:
getWireFormat
in interfaceTransport
- Returns:
- the WireFormat in use.
-
getPeerCertificates
- Specified by:
getPeerCertificates
in interfaceTransport
- Returns:
- the Certificates provided by the peer, or null if not a secure channel.
-
setPeerCertificates
Description copied from interface:Transport
Sets the certificates provided by the connected peer.- Specified by:
setPeerCertificates
in interfaceTransport
- Parameters:
certificates
- the Certificates provided by the peer.
-