Class AnalyticsTcpSocketManager

java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.OutputStreamManager
org.apache.logging.log4j.core.net.AbstractSocketManager
io.vertigo.core.plugins.analytics.log.log4j.AnalyticsTcpSocketManager
All Implemented Interfaces:
AutoCloseable, org.apache.logging.log4j.core.layout.ByteBufferDestination

public class AnalyticsTcpSocketManager extends org.apache.logging.log4j.core.net.AbstractSocketManager
Manager of TCP Socket connections. /!\ Fork of org.apache.logging.log4j.core.net.TcpSocketManager : - correct reconnexion bug : https://issues.apache.org/jira/browse/LOG4J2-3518 - buffer data while waiting for reconnexion (instead of loosing logs)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    protected static class 
    AnalyticsTcpSocketManager.TcpSocketManagerFactory<M extends AnalyticsTcpSocketManager,T extends io.vertigo.core.plugins.analytics.log.log4j.AnalyticsTcpSocketManager.FactoryData>
    Factory to create a TcpSocketManager.

    Nested classes/interfaces inherited from class org.apache.logging.log4j.core.appender.AbstractManager

    org.apache.logging.log4j.core.appender.AbstractManager.AbstractFactoryData
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default reconnection delay (30000 milliseconds or 30 seconds).

    Fields inherited from class org.apache.logging.log4j.core.net.AbstractSocketManager

    host, inetAddress, port

    Fields inherited from class org.apache.logging.log4j.core.appender.OutputStreamManager

    byteBuffer, layout

    Fields inherited from class org.apache.logging.log4j.core.appender.AbstractManager

    count, LOGGER
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnalyticsTcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize)
    Deprecated.
    Use TcpSocketManager(String, OutputStream, Socket, InetAddress, String, int, int, int, boolean, Layout, int, SocketOptions).
    AnalyticsTcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize, org.apache.logging.log4j.core.net.SocketOptions socketOptions)
    Constructs.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    protected Socket
     
    protected static Socket
    createSocket(InetSocketAddress socketAddress, org.apache.logging.log4j.core.net.SocketOptions socketOptions, int connectTimeoutMillis)
     
    int
     
    Gets this TcpSocketManager's content format.
    int
     
    USE AT YOUR OWN RISK, method is public for testing purpose only for now.
    getSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize, org.apache.logging.log4j.core.net.SocketOptions socketOptions)
    Obtains a TcpSocketManager.
    org.apache.logging.log4j.core.net.SocketOptions
    USE AT YOUR OWN RISK, method is public for testing purpose only for now.
    static byte[]
    gzip(byte[] val, int offset, int length)
     
    static void
    This method is only for unit testing.
     
    protected void
    write(byte[] originBytes, int originOffset, int originLength, boolean immediateFlush)
     

    Methods inherited from class org.apache.logging.log4j.core.net.AbstractSocketManager

    getHost, getPort

    Methods 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, writeToDestination

    Methods 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_RECONNECTION_DELAY_MILLIS

      public static final int DEFAULT_RECONNECTION_DELAY_MILLIS
      The default reconnection delay (30000 milliseconds or 30 seconds).
      See Also:
  • Constructor Details

    • AnalyticsTcpSocketManager

      @Deprecated public AnalyticsTcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize)
      Deprecated.
      Use TcpSocketManager(String, OutputStream, Socket, InetAddress, String, int, int, int, boolean, Layout, int, 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.
    • AnalyticsTcpSocketManager

      public AnalyticsTcpSocketManager(String name, OutputStream os, Socket socket, InetAddress inetAddress, String host, int port, int connectTimeoutMillis, int reconnectionDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize, org.apache.logging.log4j.core.net.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

      public static AnalyticsTcpSocketManager getSocketManager(String host, int port, int connectTimeoutMillis, int reconnectDelayMillis, boolean immediateFail, boolean compress, org.apache.logging.log4j.core.Layout<? extends Serializable> layout, int bufferSize, org.apache.logging.log4j.core.net.SocketOptions socketOptions)
      Obtains a TcpSocketManager.
      Parameters:
      host - The host to connect to.
      port - The port on the host.
      connectTimeoutMillis - the connect timeout in milliseconds
      reconnectDelayMillis - The interval to pause between retries.
      bufferSize - The buffer size.
      Returns:
      A TcpSocketManager.
    • write

      protected void write(byte[] originBytes, int originOffset, int originLength, boolean immediateFlush)
      Overrides:
      write in class org.apache.logging.log4j.core.appender.OutputStreamManager
    • gzip

      public static byte[] gzip(byte[] val, int offset, int length) throws IOException
      Throws:
      IOException
    • closeOutputStream

      protected boolean closeOutputStream()
      Overrides:
      closeOutputStream in class org.apache.logging.log4j.core.appender.OutputStreamManager
    • getConnectTimeoutMillis

      public int getConnectTimeoutMillis()
    • getContentFormat

      public Map<String,String> getContentFormat()
      Gets this TcpSocketManager's content format. Specified by:
      • Key: "protocol" Value: "tcp"
      • Key: "direction" Value: "out"
      Overrides:
      getContentFormat in class org.apache.logging.log4j.core.net.AbstractSocketManager
      Returns:
      Map of content format keys supporting TcpSocketManager
    • createSocket

      protected Socket createSocket(InetSocketAddress socketAddress) throws IOException
      Throws:
      IOException
    • createSocket

      protected static Socket createSocket(InetSocketAddress socketAddress, org.apache.logging.log4j.core.net.SocketOptions socketOptions, int connectTimeoutMillis) throws IOException
      Throws:
      IOException
    • setHostResolver

      public static void setHostResolver(AnalyticsTcpSocketManager.HostResolver resolver)
      This method is only for unit testing. It is not Thread-safe.
      Parameters:
      resolver - the HostResolver.
    • getSocketOptions

      public org.apache.logging.log4j.core.net.SocketOptions getSocketOptions()
      USE AT YOUR OWN RISK, method is public for testing purpose only for now.
    • getSocket

      public Socket getSocket()
      USE AT YOUR OWN RISK, method is public for testing purpose only for now.
    • getReconnectionDelayMillis

      public int getReconnectionDelayMillis()
    • toString

      public String toString()
      Overrides:
      toString in class Object