Skip to content

Commit

Permalink
When creating the private BeatsInitializer, some attributes from the …
Browse files Browse the repository at this point in the history
…wrapping server are copied, some none. So changing some attributes in the server will change the internal running state, some will not. This patch choose to copy everything.

Fixes #350
  • Loading branch information
fbacchella authored and robbavey committed Nov 9, 2018
1 parent bbff09f commit 2d64b1f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/org/logstash/beats/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ private class BeatsInitializer extends ChannelInitializer<SocketChannel> {

private final EventExecutorGroup idleExecutorGroup;
private final EventExecutorGroup beatsHandlerExecutorGroup;
private final IMessageListener message;
private int clientInactivityTimeoutSeconds;

private boolean enableSSL = false;

public BeatsInitializer(Boolean secure, IMessageListener messageListener, int clientInactivityTimeoutSeconds, int beatsHandlerThread) {
enableSSL = secure;
this.message = messageListener;
this.clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds;
private final IMessageListener localMessageListener;
private final int localClientInactivityTimeoutSeconds;
private final boolean localEnableSSL;

BeatsInitializer(Boolean enableSSL, IMessageListener messageListener, int clientInactivityTimeoutSeconds, int beatsHandlerThread) {
// Keeps a local copy of Server settings, so they can't be modified once it starts listening
this.localEnableSSL = enableSSL;
this.localMessageListener = messageListener;
this.localClientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds;
idleExecutorGroup = new DefaultEventExecutorGroup(DEFAULT_IDLESTATEHANDLER_THREAD);
beatsHandlerExecutorGroup = new DefaultEventExecutorGroup(beatsHandlerThread);

Expand All @@ -127,21 +127,22 @@ public BeatsInitializer(Boolean secure, IMessageListener messageListener, int cl
public void initChannel(SocketChannel socket) throws IOException, NoSuchAlgorithmException, CertificateException {
ChannelPipeline pipeline = socket.pipeline();

if(enableSSL) {
if (localEnableSSL) {
SslHandler sslHandler = sslBuilder.build(socket.alloc());
pipeline.addLast(SSL_HANDLER, sslHandler);
}
pipeline.addLast(idleExecutorGroup, IDLESTATE_HANDLER, new IdleStateHandler(clientInactivityTimeoutSeconds, IDLESTATE_WRITER_IDLE_TIME_SECONDS , clientInactivityTimeoutSeconds));
pipeline.addLast(idleExecutorGroup, IDLESTATE_HANDLER,
new IdleStateHandler(localClientInactivityTimeoutSeconds, IDLESTATE_WRITER_IDLE_TIME_SECONDS, localClientInactivityTimeoutSeconds));
pipeline.addLast(BEATS_ACKER, new AckEncoder());
pipeline.addLast(CONNECTION_HANDLER, new ConnectionHandler());
pipeline.addLast(beatsHandlerExecutorGroup, new BeatsParser(), new BeatsHandler(this.message));
pipeline.addLast(beatsHandlerExecutorGroup, new BeatsParser(), new BeatsHandler(localMessageListener));
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warn("Exception caught in channel initializer", cause);
try {
this.message.onChannelInitializeException(ctx, cause);
localMessageListener.onChannelInitializeException(ctx, cause);
} finally {
super.exceptionCaught(ctx, cause);
}
Expand Down

0 comments on commit 2d64b1f

Please sign in to comment.