public class TCPTransport extends java.lang.Object implements Transport
tcp://
.Modifier and Type | Field and Description |
---|---|
protected TCPTransportImpl |
_impl |
Constructor and Description |
---|
TCPTransport(Protocol msgType)
Constructs a new TCPTransport instance with the specified message type.
|
TCPTransport(Protocol protocol,
java.util.Properties properties)
Constructs a new TCPTransport instance with the specified protocol and properties.
|
TCPTransport(Protocol msgType,
TCPTransportImpl impl) |
Modifier and Type | Method and Description |
---|---|
Message |
allocateMessage()
Allocates a new message using the underlying protocol.
|
void |
close()
Closes the transport, disconnecting it from the server.
|
void |
connect(java.net.URI uri)
Connects to the specified URI using the underlying implementation.
|
protected TCPTransportImpl |
constructTransportImpl(Protocol protocol,
java.util.Properties properties)
Constructs a new TCPTransport instance with the specified protocol and properties.
|
static TCPTransport |
createTransport(Protocol messageType)
Factory method for creating a new instance of
TCPTransport . |
static TCPTransport |
createTransport(Protocol messageType,
TCPTransportImpl impl)
Factory method for creating a new instance of
TCPTransport . |
void |
disconnect()
Disconnects the transport from the server.
|
long |
flush()
Flushes the transport's write queue.
|
long |
flush(long timeout)
Flushes the transport's write queue with a specified timeout.
|
static int |
getDefaultConnectTimeout()
Returns the default connect timeout used for new connections.
|
static int |
getDefaultReadTimeout()
Returns the default read timeout used for socket reads.
|
AMPSRunnable |
getIdleRunnable()
Gets the transport's currently registered idle task, or null
if there is none.
|
int |
getVersion()
Returns the version of the transport.
|
void |
handleCloseEvent(int failedVersion_,
java.lang.String message,
java.lang.Exception e)
Handles a close event, notifying the underlying implementation.
|
void |
initFromClient(Client client)
Called by Client before calling connect to give Transport access to any
information in the Client needed by the Transport such as message handler,
exceptionListener, etc.
|
static boolean |
isDaemon()
Checks if daemon threads are being used by default.
|
long |
readQueueSize()
Returns the size of the read queue.
|
void |
send(Message message)
Sends the specified message.
|
void |
sendWithoutRetry(Message message)
Sends a message without retrying, handling the serialization process.
|
static void |
setDaemon(boolean daemonThreads)
Sets whether daemon threads should be used by default.
|
static void |
setDefaultConnectTimeout(int defaultConnectTimeoutMillis_)
Returns the default connect timeout used for new connections.
|
static void |
setDefaultReadTimeout(int defaultReadTimeoutMillis_)
Sets the default read timeout used for socket reads.
|
void |
setDisconnectHandler(TransportDisconnectHandler dh)
Sets the handler for disconnect events.
|
void |
setExceptionListener(java.beans.ExceptionListener exceptionListener)
Sets the listener for exception events.
|
void |
setIdleRunnable(AMPSRunnable runnable)
Sets the idle runnable for the transport.
|
void |
setMessageHandler(MessageHandler ml)
Sets the message handler for this transport.
|
void |
setReadTimeout(int readTimeout_)
Sets the read timeout for the transport.
|
void |
setThreadCreatedHandler(ThreadCreatedHandler tch_)
Sets the handler for newly created threads.
|
void |
setTransportFilter(TransportFilter filter)
Sets the transport filter.
|
java.net.Socket |
socket()
Returns the underlying socket of the transport.
|
long |
writeQueueSize()
Returns the size of the write queue.
|
protected TCPTransportImpl _impl
public TCPTransport(Protocol protocol, java.util.Properties properties)
protocol
- The protocol used by the transport.properties
- The properties to configure the transport.public TCPTransport(Protocol msgType)
msgType
- The protocol message type.public TCPTransport(Protocol msgType, TCPTransportImpl impl)
protected TCPTransportImpl constructTransportImpl(Protocol protocol, java.util.Properties properties)
protocol
- The protocol used by the transport.properties
- The properties to configure the transport.public static void setDaemon(boolean daemonThreads)
daemonThreads
- True to use daemon threads; false otherwise.public static boolean isDaemon()
public static void setDefaultReadTimeout(int defaultReadTimeoutMillis_)
defaultReadTimeoutMillis_
- The default read timeout in milliseconds.public static int getDefaultReadTimeout()
public static void setDefaultConnectTimeout(int defaultConnectTimeoutMillis_)
defaultConnectTimeoutMillis_
- The default connect timeout,
in milliseconds. A 0 value means no timeout is specified, i.e. wait
until the OS returns an error.public static int getDefaultConnectTimeout()
public static TCPTransport createTransport(Protocol messageType)
TCPTransport
.messageType
- The protocol message type for the transport.public static 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 ml)
setMessageHandler
in interface Transport
ml
- The message handler to set.public void setThreadCreatedHandler(ThreadCreatedHandler tch_)
setThreadCreatedHandler
in interface Transport
tch_
- The thread created handler to set.public void setDisconnectHandler(TransportDisconnectHandler dh)
setDisconnectHandler
in interface Transport
dh
- The disconnect handler to set.public void setExceptionListener(java.beans.ExceptionListener exceptionListener)
setExceptionListener
in interface Transport
exceptionListener
- The exception listener to set.public void setTransportFilter(TransportFilter filter)
setTransportFilter
in interface Transport
filter
- The transport filter to set.public void connect(java.net.URI uri) throws ConnectionRefusedException, AlreadyConnectedException, InvalidURIException
connect
in interface Transport
uri
- The URI to connect to.ConnectionRefusedException
- If the connection is refused.AlreadyConnectedException
- If the transport is already connected.InvalidURIException
- If the URI is invalid.public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
- If an error occurs during the disconnect process.public void disconnect()
disconnect
in interface Transport
public void handleCloseEvent(int failedVersion_, java.lang.String message, java.lang.Exception e) throws DisconnectedException, RetryOperationException
handleCloseEvent
in interface Transport
failedVersion_
- The failed version.message
- The message associated with the close event.e
- The exception associated with the close event.DisconnectedException
- If the transport is disconnected.RetryOperationException
- If a retry operation is needed.public void sendWithoutRetry(Message message) throws DisconnectedException
sendWithoutRetry
in interface Transport
message
- The message to send.DisconnectedException
- If the transport is disconnected.public void send(Message message) throws DisconnectedException
send
in interface Transport
message
- The message to send.DisconnectedException
- If the transport is disconnected.public Message allocateMessage()
allocateMessage
in interface Transport
public long writeQueueSize() throws DisconnectedException
writeQueueSize
in interface Transport
DisconnectedException
- If the transport is disconnected.public long readQueueSize() throws DisconnectedException
readQueueSize
in interface Transport
DisconnectedException
- If the transport is disconnected.public long flush() throws DisconnectedException
flush
in interface Transport
DisconnectedException
- If the transport is disconnected.public long flush(long timeout) throws DisconnectedException
flush
in interface Transport
timeout
- The maximum time to wait for flushing, in milliseconds.DisconnectedException
- If the transport is disconnected.public java.net.Socket socket()
public int getVersion()
getVersion
in interface Transport
public void setReadTimeout(int readTimeout_)
setReadTimeout
in interface Transport
readTimeout_
- The read timeout in milliseconds.public AMPSRunnable getIdleRunnable()
getIdleRunnable
in interface Transport
public void setIdleRunnable(AMPSRunnable runnable)
setIdleRunnable
in interface Transport
runnable
- The idle runnable to set.public void initFromClient(Client client)
Transport
initFromClient
in interface Transport
client
- The Client that will be using the Transport.