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 inDefaultKeyProvider
. 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 isCloseable
, so it can easily be started and stopped by using a try-with-resources statement.- Since:
- 4.0
- Author:
- Christian Ohr
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SocketAddress
address()
void
close()
protected abstract SyslogServer<T>
doStart(String host, int port)
protected reactor.core.publisher.Mono<Object>
handleMap(Map<String,Object> map)
Asynchronously consumes syslog records.SyslogServer<T>
start(String host, int port)
Starts the server and returns when started within 10 seconds.void
stop()
Stops the server if it was started before, and returns when stopped within 10 seconds.
-
-
-
Method Detail
-
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 hostport
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-