public class TcpSocketManager extends AbstractSocketManager
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
TcpSocketManager.FactoryData
Data for the factory.
|
static class |
TcpSocketManager.HostResolver |
private class |
TcpSocketManager.Reconnector
Handles reconnecting to a Socket on a Thread.
|
protected static class |
TcpSocketManager.TcpSocketManagerFactory<M extends TcpSocketManager,T extends TcpSocketManager.FactoryData>
Factory to create a TcpSocketManager.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
connectTimeoutMillis |
private static int |
DEFAULT_PORT
The default port number of remote logging server (4560).
|
static int |
DEFAULT_RECONNECTION_DELAY_MILLIS
The default reconnection delay (30000 milliseconds or 30 seconds).
|
private static TcpSocketManager.TcpSocketManagerFactory<TcpSocketManager,TcpSocketManager.FactoryData> |
FACTORY |
private boolean |
immediateFail |
private int |
reconnectionDelayMillis |
private TcpSocketManager.Reconnector |
reconnector |
private boolean |
retry |
private java.net.Socket |
socket |
private SocketOptions |
socketOptions |
host, inetAddress, portbyteBuffer, layoutcount, LOGGER| Constructor and Description |
|---|
TcpSocketManager(java.lang.String name,
java.io.OutputStream os,
java.net.Socket socket,
java.net.InetAddress inetAddress,
java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectionDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize)
|
TcpSocketManager(java.lang.String name,
java.io.OutputStream os,
java.net.Socket socket,
java.net.InetAddress inetAddress,
java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectionDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize,
SocketOptions socketOptions)
Constructs.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
closeOutputStream() |
private TcpSocketManager.Reconnector |
createReconnector() |
protected java.net.Socket |
createSocket(java.net.InetSocketAddress socketAddress) |
protected static java.net.Socket |
createSocket(java.net.InetSocketAddress socketAddress,
SocketOptions socketOptions,
int connectTimeoutMillis) |
int |
getConnectTimeoutMillis() |
java.util.Map<java.lang.String,java.lang.String> |
getContentFormat()
Gets this TcpSocketManager's content format.
|
int |
getReconnectionDelayMillis() |
java.net.Socket |
getSocket()
USE AT YOUR OWN RISK, method is public for testing purpose only for now.
|
static TcpSocketManager |
getSocketManager(java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize)
|
static TcpSocketManager |
getSocketManager(java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize,
SocketOptions socketOptions)
Obtains a TcpSocketManager.
|
SocketOptions |
getSocketOptions()
USE AT YOUR OWN RISK, method is public for testing purpose only for now.
|
static void |
setHostResolver(TcpSocketManager.HostResolver resolver)
This method is only for unit testing.
|
java.lang.String |
toString() |
protected void |
write(byte[] bytes,
int offset,
int length,
boolean immediateFlush)
Some output streams synchronize writes while others do not.
|
private void |
writeAndFlush(byte[] bytes,
int offset,
int length,
boolean immediateFlush) |
createOutputStream, drain, flush, flushBuffer, flushDestination, getByteBuffer, getManager, getOutputStream, hasOutputStream, isOpen, releaseSub, setOutputStream, skipFooter, write, write, write, writeBytes, writeBytes, writeFooter, writeToDestinationclose, getCount, getLoggerContext, getName, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateDatapublic static final int DEFAULT_RECONNECTION_DELAY_MILLIS
private static final int DEFAULT_PORT
private static final TcpSocketManager.TcpSocketManagerFactory<TcpSocketManager,TcpSocketManager.FactoryData> FACTORY
private final int reconnectionDelayMillis
private TcpSocketManager.Reconnector reconnector
private java.net.Socket socket
private final SocketOptions socketOptions
private final boolean retry
private final boolean immediateFail
private final int connectTimeoutMillis
@Deprecated
public TcpSocketManager(java.lang.String name,
java.io.OutputStream os,
java.net.Socket socket,
java.net.InetAddress inetAddress,
java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectionDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize)
TcpSocketManager(String, OutputStream, Socket, InetAddress, String, int, int, int, boolean, Layout, int, SocketOptions).name - The unique name of this connection.os - The OutputStream.socket - The Socket.inetAddress - The Internet address of the host.host - The name of the host.port - The port number on the host.connectTimeoutMillis - the connect timeout in milliseconds.reconnectionDelayMillis - Reconnection interval.immediateFail - True if the write should fail if no socket is immediately available.layout - The Layout.bufferSize - The buffer size.public TcpSocketManager(java.lang.String name,
java.io.OutputStream os,
java.net.Socket socket,
java.net.InetAddress inetAddress,
java.lang.String host,
int port,
int connectTimeoutMillis,
int reconnectionDelayMillis,
boolean immediateFail,
Layout<? extends java.io.Serializable> layout,
int bufferSize,
SocketOptions socketOptions)
name - The unique name of this connection.os - The OutputStream.socket - The Socket.inetAddress - The Internet address of the host.host - The name of the host.port - The port number on the host.connectTimeoutMillis - the connect timeout in milliseconds.reconnectionDelayMillis - Reconnection interval.immediateFail - True if the write should fail if no socket is immediately available.layout - The Layout.bufferSize - The buffer size.@Deprecated public static TcpSocketManager getSocketManager(java.lang.String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends java.io.Serializable> layout, int bufferSize)
host - The host to connect to.port - The port on the host.connectTimeoutMillis - the connect timeout in millisecondsreconnectDelayMillis - The interval to pause between retries.bufferSize - The buffer size.public static TcpSocketManager getSocketManager(java.lang.String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends java.io.Serializable> layout, int bufferSize, SocketOptions socketOptions)
host - The host to connect to.port - The port on the host.connectTimeoutMillis - the connect timeout in millisecondsreconnectDelayMillis - The interval to pause between retries.bufferSize - The buffer size.protected void write(byte[] bytes,
int offset,
int length,
boolean immediateFlush)
OutputStreamManagerwrite in class OutputStreamManagerbytes - The serialized Log event.offset - The offset into the byte array.length - The number of bytes to write.immediateFlush - flushes immediately after writing.private void writeAndFlush(byte[] bytes,
int offset,
int length,
boolean immediateFlush)
throws java.io.IOException
java.io.IOExceptionprotected boolean closeOutputStream()
closeOutputStream in class OutputStreamManagerpublic int getConnectTimeoutMillis()
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
getContentFormat in class AbstractSocketManagerprivate TcpSocketManager.Reconnector createReconnector()
protected java.net.Socket createSocket(java.net.InetSocketAddress socketAddress)
throws java.io.IOException
java.io.IOExceptionprotected static java.net.Socket createSocket(java.net.InetSocketAddress socketAddress,
SocketOptions socketOptions,
int connectTimeoutMillis)
throws java.io.IOException
java.io.IOExceptionpublic static void setHostResolver(TcpSocketManager.HostResolver resolver)
resolver - the HostResolver.public SocketOptions getSocketOptions()
public java.net.Socket getSocket()
public int getReconnectionDelayMillis()
public java.lang.String toString()
toString in class java.lang.Object