socket.
If an IOException occurs during a write(byte[], int, int) and a socket factory was defined the stream will attempt to reconnect indefinitely. By default
additional writes are discarded when reconnecting. If you set the block on
reconnect to true, then the reconnect will indefinitely block until the TCP stream is reconnected.
You can optionally get a collection of the errors that occurred during a write or reconnect.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private boolean | |
| private final Deque | |
| private static final int | |
| private static final long | |
| protected final ReentrantLock | |
| private Thread | |
| private static final long | |
| private Socket | |
| private final ClientSocketFactory |
| Access | Constructor and Description |
|---|---|
| public | TcpOutputStream(final InetAddress
the address to connect to address, final int the port to connect to port)Creates a TCP output stream. |
| public | TcpOutputStream(final InetAddress
the address to connect to address, final int the port to connect to port, final boolean true to block when attempting to reconnect the socket or false to
reconnect asynchronouslyCreates a TCP output stream. |
| protected | TcpOutputStream(final Socket
the socket used to write the output to socket)
Deprecated
Use
TcpOutputStream(ClientSocketFactory, boolean)
Creates a new TCP output stream. |
| protected | TcpOutputStream(final SocketFactory
the factory used to create the socket socketFactory, final InetAddress the address to connect to address, final int the port to connect to port)Creates a new TCP output stream. |
| protected | TcpOutputStream(final SocketFactory
the factory used to create the socket socketFactory, final InetAddress the address to connect to address, final int the port to connect to port, final boolean true to block when attempting to reconnect the socket or false to
reconnect asynchronouslyCreates a new TCP output stream. |
| public | TcpOutputStream(final ClientSocketFactory
the socket factory used to create TCP sockets socketFactory, final boolean true to block when attempting to reconnect the socket or false to
reconnect asynchronouslyCreates a new TCP stream which uses the |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| public void | close()
Overrides java. Implements java. Closes this resource, relinquishing any underlying resources. |
| private Thread | |
| public void | flush()
Overrides java. Implements java. Flushes this stream by writing any buffered output to the underlying stream. |
| public Collection | Returns: a collection of errors or an empty listRetrieves the errors occurred, if any, during a write or reconnect. |
| public boolean | Returns: true if blocking is enabled, otherwise falseIndicates whether or not the output stream is set to block when attempting to reconnect a TCP connection. |
| public boolean | Returns: true if the stream is connected, otherwise falseReturns the connected state of the TCP stream. |
| private boolean | |
| private static void | |
| public void | setBlockOnReconnect(final boolean
true to block when reconnecting or false to reconnect asynchronously
discarding any new messages coming inEnables or disables blocking when attempting to reconnect the socket. |
| public void | write(final int
the b)byte.Implements abstract java. Writes the specified byte to this output stream. |
| public void | write(final byte[]
the data. b)Overrides java. Writes |
| public void | write(final byte[]
the data. b, final int the start offset in the data. off, final int the number of bytes to write. len)Overrides java. Writes |
| blockOnReconnect | back to summary |
|---|---|
| private boolean blockOnReconnect | |
| connected | back to summary |
|---|---|
| private boolean connected | |
| errors | back to summary |
|---|---|
| private final Deque<Exception> errors | |
| maxErrors | back to summary |
|---|---|
| private static final int maxErrors | |
| maxRetryTimeout | back to summary |
|---|---|
| private static final long maxRetryTimeout | |
| outputLock | back to summary |
|---|---|
| protected final ReentrantLock outputLock | |
| reconnectThread | back to summary |
|---|---|
| private Thread reconnectThread | |
| retryTimeout | back to summary |
|---|---|
| private static final long retryTimeout | |
| socket | back to summary |
|---|---|
| private Socket socket | |
| socketFactory | back to summary |
|---|---|
| private final ClientSocketFactory socketFactory | |
| TcpOutputStream | back to summary |
|---|---|
| public TcpOutputStream(final InetAddress address, final int port) throws IOException Creates a TCP output stream.
Uses the
| |
| TcpOutputStream | back to summary |
|---|---|
| public TcpOutputStream(final InetAddress address, final int port, final boolean blockOnReconnect) throws IOException Creates a TCP output stream.
Uses the
| |
| TcpOutputStream | back to summary |
|---|---|
| protected TcpOutputStream(final Socket socket)
Deprecated Creates a new TCP output stream. Using this constructor does not allow for any kind of reconnect if the connection is dropped.
| |
| TcpOutputStream | back to summary |
|---|---|
| protected TcpOutputStream(final SocketFactory socketFactory, final InetAddress address, final int port) throws IOException Creates a new TCP output stream.
Creates a
| |
| TcpOutputStream | back to summary |
|---|---|
| protected TcpOutputStream(final SocketFactory socketFactory, final InetAddress address, final int port, final boolean blockOnReconnect) throws IOException Creates a new TCP output stream.
Creates a
| |
| TcpOutputStream | back to summary |
|---|---|
| public TcpOutputStream(final ClientSocketFactory socketFactory, final boolean blockOnReconnect) Creates a new TCP stream which uses the
| |
| addError | back to summary |
|---|---|
| private void addError(final Exception e) | |
| checkReconnect | back to summary |
|---|---|
| private void checkReconnect() Attempts to reconnect the socket if required and allowed. Invocations of this method must be locked by the
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
| |
| createThread | back to summary |
|---|---|
| private Thread createThread() | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Overrides java. Implements java. Doc from java. Flushes this stream by writing any buffered output to the underlying stream.
| |
| getErrors | back to summary |
|---|---|
| public Collection Retrieves the errors occurred, if any, during a write or reconnect.
| |
| isBlockOnReconnect | back to summary |
|---|---|
| public boolean isBlockOnReconnect() Indicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.
| |
| isConnected | back to summary |
|---|---|
| public boolean isConnected() Returns the connected state of the TCP stream.
The stream is said to be disconnected when an
| |
| isReconnectAllowed | back to summary |
|---|---|
| private boolean isReconnectAllowed() Invocations of this method must be locked by the | |
| safeClose | back to summary |
|---|---|
| private static void safeClose(final Closeable closeable) | |
| setBlockOnReconnect | back to summary |
|---|---|
| public void setBlockOnReconnect(final boolean blockOnReconnect) Enables or disables blocking when attempting to reconnect the socket.
If set to
| |
| write | back to summary |
|---|---|
| public void write(final int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b) throws IOException Overrides java. Doc from java. Writes
| |
| write | back to summary |
|---|---|
| public void write(final byte[] b, final int off, final int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |
| Modifier and Type | Field and Description |
|---|---|
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| attempts | back to summary |
|---|---|
| private int attempts | |
| RetryConnector | back to summary |
|---|---|
| private RetryConnector() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |