Class SyslogServer<T extends reactor.netty.DisposableChannel>

java.lang.Object
org.openehealth.ipf.commons.audit.server.SyslogServer<T>
Type Parameters:
T -
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
TlsSyslogServer, UdpSyslogServer

public abstract class SyslogServer<T extends reactor.netty.DisposableChannel> extends Object implements Closeable
Abstract base class for TLS and UDP syslog servers. Received Syslog frames must be handled by a consumer; the frames are parsed into a Map with keys as specified in DefaultKeyProvider. If parsing fails (e.g. due to incomplete syslog frames, the map is populated with the raw content and the expection that has been thrown by the parser.

One example for a consumer is SyslogEventCollector that is practical for tests. With this respect, note that SyslogServer is Closeable, so it can easily be started and stopped by using a try-with-resources statement.

Since:
4.0
Author:
Christian Ohr
  • Field Details

    • channel

      protected T extends reactor.netty.DisposableChannel channel
    • consumer

      protected final Consumer<? super Map<String,Object>> consumer
    • errorConsumer

      protected final Consumer<Throwable> errorConsumer
  • Constructor Details

    • SyslogServer

      public SyslogServer(Consumer<? super Map<String,Object>> consumer, Consumer<Throwable> errorConsumer)
      Parameters:
      consumer - consumer for handled syslog frames
      errorConsumer - consumer for errors
  • Method Details

    • start

      public SyslogServer<T> start(String host, int port)
      Starts the server and returns when started within 10 seconds. Requests are handled on the receiver thread.
      Parameters:
      host - exposed host
      port - port
      Returns:
      this instance
    • address

      public SocketAddress address()
    • doStart

      protected abstract SyslogServer<T> doStart(String host, int port)
    • stop

      public void stop()
      Stops the server if it was started before, and returns when stopped within 10 seconds.
    • handleMap

      protected reactor.core.publisher.Mono<Object> handleMap(Map<String,Object> map)
      Asynchronously consumes syslog records. This trick is described at https://levelup.gitconnected.com/reactive-asynchronous-programming-in-java-using-reactor-core-part-2-e9c6caeb8833. It generates a Mono from a potentially blocking call and subscribes using a scheduler.
      Parameters:
      map - syslog map
      Returns:
      nothing
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable