@@ -110,15 +110,15 @@ private class BeatsInitializer extends ChannelInitializer<SocketChannel> {
110110
111111 private final EventExecutorGroup idleExecutorGroup ;
112112 private final EventExecutorGroup beatsHandlerExecutorGroup ;
113- private final IMessageListener message ;
114- private int clientInactivityTimeoutSeconds ;
115-
116- private boolean enableSSL = false ;
117-
118- public BeatsInitializer ( Boolean secure , IMessageListener messageListener , int clientInactivityTimeoutSeconds , int beatsHandlerThread ) {
119- enableSSL = secure ;
120- this .message = messageListener ;
121- this .clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds ;
113+ private final IMessageListener localMessageListener ;
114+ private final int localClientInactivityTimeoutSeconds ;
115+ private final boolean localEnableSSL ;
116+
117+ BeatsInitializer ( Boolean enableSSL , IMessageListener messageListener , int clientInactivityTimeoutSeconds , int beatsHandlerThread ) {
118+ // Keeps a local copy of Server settings, so they can't be modified once it starts listening
119+ this . localEnableSSL = enableSSL ;
120+ this .localMessageListener = messageListener ;
121+ this .localClientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds ;
122122 idleExecutorGroup = new DefaultEventExecutorGroup (DEFAULT_IDLESTATEHANDLER_THREAD );
123123 beatsHandlerExecutorGroup = new DefaultEventExecutorGroup (beatsHandlerThread );
124124
@@ -127,21 +127,22 @@ public BeatsInitializer(Boolean secure, IMessageListener messageListener, int cl
127127 public void initChannel (SocketChannel socket ) throws IOException , NoSuchAlgorithmException , CertificateException {
128128 ChannelPipeline pipeline = socket .pipeline ();
129129
130- if ( enableSSL ) {
130+ if ( localEnableSSL ) {
131131 SslHandler sslHandler = sslBuilder .build (socket .alloc ());
132132 pipeline .addLast (SSL_HANDLER , sslHandler );
133133 }
134- pipeline .addLast (idleExecutorGroup , IDLESTATE_HANDLER , new IdleStateHandler (clientInactivityTimeoutSeconds , IDLESTATE_WRITER_IDLE_TIME_SECONDS , clientInactivityTimeoutSeconds ));
134+ pipeline .addLast (idleExecutorGroup , IDLESTATE_HANDLER ,
135+ new IdleStateHandler (localClientInactivityTimeoutSeconds , IDLESTATE_WRITER_IDLE_TIME_SECONDS , localClientInactivityTimeoutSeconds ));
135136 pipeline .addLast (BEATS_ACKER , new AckEncoder ());
136137 pipeline .addLast (CONNECTION_HANDLER , new ConnectionHandler ());
137- pipeline .addLast (beatsHandlerExecutorGroup , new BeatsParser (), new BeatsHandler (this . message ));
138+ pipeline .addLast (beatsHandlerExecutorGroup , new BeatsParser (), new BeatsHandler (localMessageListener ));
138139 }
139140
140141 @ Override
141142 public void exceptionCaught (ChannelHandlerContext ctx , Throwable cause ) throws Exception {
142143 logger .warn ("Exception caught in channel initializer" , cause );
143144 try {
144- this . message .onChannelInitializeException (ctx , cause );
145+ localMessageListener .onChannelInitializeException (ctx , cause );
145146 } finally {
146147 super .exceptionCaught (ctx , cause );
147148 }
0 commit comments