public class TCPTransportImpl
extends java.lang.Object
TCPTransport
. TCP Transport delegates to an instance of this class.
This is used internally by the client's transport. There is usually no reason to make direct use of it.
Its functionality is best accessed via the client instance.Modifier and Type | Field and Description |
---|---|
protected java.net.URI |
_addr |
protected Client |
_client |
protected TransportFilter |
_filter |
protected boolean |
_handshakeSetStreams |
protected boolean |
_httpPreflight |
protected AMPSRunnable |
_idleRunnable |
protected java.io.InputStream |
_inputStream |
java.util.concurrent.locks.Lock |
_lock |
protected java.io.OutputStream |
_outputStream |
protected java.net.Socket |
_socket |
Constructor and Description |
---|
TCPTransportImpl(Protocol messageType,
java.util.Properties properties,
TransportFilter filter)
Constructs a TCPTransportImpl object with the specified message type, properties, and transport filter.
|
Modifier and Type | Method and Description |
---|---|
protected void |
applySocketProperties(java.util.Properties properties_)
Applies socket properties based on the provided properties.
|
protected void |
applySocketProperty(java.lang.Object key,
java.lang.Object value) |
void |
connect(java.net.URI addr)
Connects the transport to the specified URI.
|
protected void |
connectSocket(java.net.URI addr,
URIProperties properties) |
protected java.net.Socket |
createSocket()
Creates a socket using the default socket factory.
|
protected void |
createStream(java.net.URI addr) |
TCPTransport |
createTransport(Protocol messageType,
TCPTransportImpl impl)
Factory method for creating a new instance of
TCPTransport . |
void |
disconnect()
Initiates the disconnection process.
|
long |
flush()
Flushes the data in the write queue.
|
long |
flush(long timeout)
Flushes the data in the write queue with a specified timeout.
|
AMPSRunnable |
getIdleRunnable()
Gets the transport impl's currently registered idle task, or null
if there is none.
|
void |
handleCloseEvent(int failedVersion,
java.lang.String message,
java.lang.Exception e_)
Handles the event of the connection being closed.
|
protected void |
handshake()
Performs the handshake for the TCP connection.
|
void |
initFromClient(Client client) |
long |
readQueueSize()
Returns the size of the read queue.
|
void |
send(java.nio.ByteBuffer buf)
Sends data through the socket.
|
void |
setConnectTimeout(int connectTimeoutMillis_)
Sets the connect timeout for the TCP transport.
|
void |
setDisconnectHandler(TransportDisconnectHandler h)
Sets the disconnect handler for the transport.
|
void |
setExceptionListener(java.beans.ExceptionListener exceptionListener)
Sets the exception listener for the transport.
|
void |
setIdleRunnable(AMPSRunnable runnable) |
void |
setMessageHandler(MessageHandler h)
Sets the message handler for the transport.
|
void |
setReadTimeout(int readTimeoutMillis_)
Sets the read timeout for the TCP transport.
|
void |
setThreadCreatedHandler(ThreadCreatedHandler h)
Sets the thread created handler for the transport.
|
void |
setTransportFilter(TransportFilter filter)
Sets the transport filter for the transport.
|
java.net.Socket |
socket()
Retrieves the underlying socket.
|
long |
writeQueueSize()
Returns the size of the write queue.
|
protected Client _client
protected java.net.URI _addr
protected java.net.Socket _socket
protected java.io.InputStream _inputStream
protected java.io.OutputStream _outputStream
public final java.util.concurrent.locks.Lock _lock
protected TransportFilter _filter
protected volatile AMPSRunnable _idleRunnable
protected boolean _httpPreflight
protected boolean _handshakeSetStreams
public TCPTransportImpl(Protocol messageType, java.util.Properties properties, TransportFilter filter)
messageType
- The message type associated with the transport.properties
- The properties to be applied to the transport.filter
- The transport filter to be applied.public TCPTransport createTransport(Protocol messageType, TCPTransportImpl impl)
TCPTransport
.messageType
- The protocol message type for the transport.impl
- The underlying implementation for the new transport.public void setMessageHandler(MessageHandler h)
h
- The message handler to be set.public void setDisconnectHandler(TransportDisconnectHandler h)
h
- The disconnect handler to be set.public void setExceptionListener(java.beans.ExceptionListener exceptionListener)
exceptionListener
- The exception listener to be set.public void setThreadCreatedHandler(ThreadCreatedHandler h)
h
- The thread created handler to be set.public void setTransportFilter(TransportFilter filter)
filter
- The transport filter to be set.public void connect(java.net.URI addr) throws ConnectionRefusedException, AlreadyConnectedException, InvalidURIException
addr
- The URI to connect to.ConnectionRefusedException
- Thrown if the connection is refused.AlreadyConnectedException
- Thrown if the transport is already connected.InvalidURIException
- Thrown if the URI is invalid.protected java.net.Socket createSocket() throws java.lang.Exception
java.lang.Exception
- If an error occurs while creating the socket.protected void connectSocket(java.net.URI addr, URIProperties properties) throws java.lang.Exception
java.lang.Exception
protected void createStream(java.net.URI addr) throws java.io.IOException
java.io.IOException
protected void handshake() throws java.lang.Exception
java.lang.Exception
- If an error occurs during the handshake process.protected void applySocketProperties(java.util.Properties properties_) throws java.net.SocketException, InvalidURIException
properties_
- The properties to be applied to the socket.java.net.SocketException
- If an error occurs while setting socket options.InvalidURIException
- If an invalid URI parameter is encountered.protected void applySocketProperty(java.lang.Object key, java.lang.Object value) throws java.net.SocketException, InvalidURIException
java.net.SocketException
InvalidURIException
public void disconnect()
public void send(java.nio.ByteBuffer buf) throws DisconnectedException
buf
- The ByteBuffer containing the data to be sent.DisconnectedException
- If the socket is disconnected while sending the message.public java.net.Socket socket()
public long writeQueueSize()
public long readQueueSize()
public long flush()
public long flush(long timeout)
timeout
- The timeout value in milliseconds.public void handleCloseEvent(int failedVersion, java.lang.String message, java.lang.Exception e_) throws RetryOperationException, DisconnectedException
failedVersion
- The version of the failed connection.message
- The message associated with the event.e_
- The exception that caused the event, if any.RetryOperationException
- If a new connection is available and retrying the operation is necessary.DisconnectedException
- If an error occurs during reconnection or disconnection.public void setReadTimeout(int readTimeoutMillis_)
readTimeoutMillis_
- The read timeout value in milliseconds.public void setConnectTimeout(int connectTimeoutMillis_)
connectTimeoutMillis_
- The connect timeout value in milliseconds.public AMPSRunnable getIdleRunnable()
public void setIdleRunnable(AMPSRunnable runnable)
public void initFromClient(Client client)