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
SyslogConstants. If parsing fails (e.g.
due to incomplete syslog frames, the map is populated with the raw content and the
exception that has been thrown by the parser.
Messages that cannot be parsed at all, and exceptions thrown by the consumer, are passed to the error consumer; they do not affect the handling of other messages. Messages are handled concurrently, so the consumer must be thread-safe and must not rely on the order in which messages were sent.
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddress()voidclose()protected abstract SyslogServer<T> protected reactor.core.publisher.Mono<Object> handleError(Throwable throwable) protected reactor.core.publisher.Mono<Object> Asynchronously consumes syslog records.protected reactor.core.publisher.Mono<Object> handleMessage(Object message) Handles a message received from the channel: a parsed syslog message is passed to the consumer, anything else (e.g. aDecoderExceptionfor a message that could not be parsed) to the error consumer.voidsetTimeoutSeconds(int timeoutSeconds) Starts the server and returns when started within 10 seconds.voidstop()Stops the server if it was started before, and returns when stopped within 10 seconds.
-
Field Details
-
channel
-
consumer
-
errorConsumer
-
timeoutSeconds
protected int timeoutSeconds
-
-
Constructor Details
-
SyslogServer
-
-
Method Details
-
start
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
-
doStart
-
stop
public void stop()Stops the server if it was started before, and returns when stopped within 10 seconds. -
handleMessage
Handles a message received from the channel: a parsed syslog message is passed to the consumer, anything else (e.g. aDecoderExceptionfor a message that could not be parsed) to the error consumer.- Parameters:
message- received message- Returns:
- completion of the handling, never failing
- Since:
- 6.0
-
handleMap
Asynchronously consumes syslog records. This trick is described here. It generates a Mono from a potentially blocking call and subscribes using a scheduler. An exception thrown by the consumer is passed to the error consumer.- Parameters:
map- syslog map- Returns:
- nothing
-
handleError
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
setTimeoutSeconds
public void setTimeoutSeconds(int timeoutSeconds)
-