Class TcpSocketManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.OutputStreamManager
org.apache.logging.log4j.core.net.AbstractSocketManager
org.apache.logging.log4j.core.net.TcpSocketManager
- All Implemented Interfaces:
AutoCloseable,ByteBufferDestination
- Direct Known Subclasses:
SslSocketManager
Manager of TCP Socket connections.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected static classTcpSocketManager.TcpSocketManagerFactory<M extends TcpSocketManager,T extends org.apache.logging.log4j.core.net.TcpSocketManager.FactoryData> Factory to create a TcpSocketManager.Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager
AbstractManager.AbstractFactoryData -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default reconnection delay (30000 milliseconds or 30 seconds).Fields inherited from class org.apache.logging.log4j.core.net.AbstractSocketManager
host, inetAddress, portFields inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
byteBuffer, layoutFields inherited from class org.apache.logging.log4j.core.appender.AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionTcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize) Deprecated.TcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions) Constructs. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected SocketcreateSocket(InetSocketAddress socketAddress) protected static SocketcreateSocket(InetSocketAddress socketAddress, SocketOptions socketOptions, int connectTimeoutMillis) intGets this TcpSocketManager's content format.intUSE AT YOUR OWN RISK, method is public for testing purpose only for now.static TcpSocketManagergetSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize) static TcpSocketManagergetSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions) Obtains a TcpSocketManager.USE AT YOUR OWN RISK, method is public for testing purpose only for now.static voidsetHostResolver(TcpSocketManager.HostResolver resolver) This method is only for unit testing.toString()protected voidwrite(byte[] bytes, int offset, int length, boolean immediateFlush) Some output streams synchronize writes while others do not.Methods inherited from class org.apache.logging.log4j.core.net.AbstractSocketManager
getHost, getPortMethods inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager
createOutputStream, drain, flush, flushBuffer, flushDestination, getByteBuffer, getManager, getOutputStream, hasOutputStream, isOpen, releaseSub, setOutputStream, skipFooter, write, write, write, writeBytes, writeBytes, writeFooter, writeHeader, writeToDestinationMethods inherited from class org.apache.logging.log4j.core.appender.AbstractManager
close, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
-
Field Details
-
DEFAULT_RECONNECTION_DELAY_MILLIS
public static final int DEFAULT_RECONNECTION_DELAY_MILLISThe default reconnection delay (30000 milliseconds or 30 seconds).- See Also:
-
-
Constructor Details
-
TcpSocketManager
@Deprecated public TcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize) Deprecated.Constructs.- Parameters:
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.
-
TcpSocketManager
public TcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions) Constructs.- Parameters:
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.
-
-
Method Details
-
getSocketManager
@Deprecated public static TcpSocketManager getSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize) Obtains a TcpSocketManager.- Parameters:
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.- Returns:
- A TcpSocketManager.
-
getSocketManager
public static TcpSocketManager getSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, Layout<? extends Serializable> layout, int bufferSize, SocketOptions socketOptions) Obtains a TcpSocketManager.- Parameters:
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.- Returns:
- A TcpSocketManager.
-
write
protected void write(byte[] bytes, int offset, int length, boolean immediateFlush) Description copied from class:OutputStreamManagerSome output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Overrides:
writein classOutputStreamManager- Parameters:
bytes- The serialized Log event.offset- The offset into the byte array.length- The number of bytes to write.immediateFlush- flushes immediately after writing.
-
closeOutputStream
protected boolean closeOutputStream()- Overrides:
closeOutputStreamin classOutputStreamManager
-
getConnectTimeoutMillis
public int getConnectTimeoutMillis() -
getContentFormat
Gets this TcpSocketManager's content format. Specified by:- Key: "protocol" Value: "tcp"
- Key: "direction" Value: "out"
- Overrides:
getContentFormatin classAbstractSocketManager- Returns:
- Map of content format keys supporting TcpSocketManager
-
createSocket
- Throws:
IOException
-
createSocket
protected static Socket createSocket(InetSocketAddress socketAddress, SocketOptions socketOptions, int connectTimeoutMillis) throws IOException - Throws:
IOException
-
setHostResolver
This method is only for unit testing. It is not Thread-safe.- Parameters:
resolver- the HostResolver.
-
getSocketOptions
USE AT YOUR OWN RISK, method is public for testing purpose only for now. -
getSocket
USE AT YOUR OWN RISK, method is public for testing purpose only for now. -
getReconnectionDelayMillis
public int getReconnectionDelayMillis() -
toString
-
TcpSocketManager(String, OutputStream, Socket, InetAddress, String, int, int, int, boolean, Layout, int, SocketOptions).