Class SyslogPublisher

  • Direct Known Subclasses:
    SyslogTcpPublisher, SyslogUdpPublisher

    public abstract class SyslogPublisher
    extends Object
    This class manages the real socket that is connected to syslog daemon. The socket could be either TCP or UDP socket. If TCP socket is closed, it is (re)opened before sending a message.
    • Constructor Detail

      • SyslogPublisher

        public SyslogPublisher​(InetSocketAddress socketAddress)
        Creates a new SyslogPublisher instance.
        Parameters:
        socketAddress - The socket address to be used for sending the syslog messages.
    • Method Detail

      • publishLogRecords

        public void publishLogRecords​(List<String> logRecords)
        Flush underlying connection. Sends buffered bytes as UDP datagram or as the next message on TCP stream. The real socket is (re)opened before, if necessary.
        Parameters:
        logRecords - The logRecords that needs to be published to Syslog.
      • reconnect

        protected abstract void reconnect()
                                   throws IOException
        Checks if the currently opened connection is still valid, and connects/reconnects to the Syslog server if necessary.
        Throws:
        IOException - If there was an IO error while trying to connect to the Syslog server.
      • sendLogRecord

        protected abstract void sendLogRecord​(byte[] bytes)
                                       throws IOException
        Sends the log record to the syslog server by the means of the chosen protocol (TCP or UDP).
        Parameters:
        bytes - The logRecord's byte[] representation.
        Throws:
        IOException - If there was an IO error while sending the audit entry to Syslog.
      • closeConnection

        protected abstract void closeConnection()
                                         throws IOException
        Closes the underlying connection.
        Throws:
        IOException - If there was an IO error while closing the connection.