@@ -22,18 +22,24 @@ public class Server {
2222 private final int port ;
2323 private final String host ;
2424 private final int beatsHeandlerThreadCount ;
25+ private final boolean protectDirectMemory ;
2526 private NioEventLoopGroup workGroup ;
2627 private IMessageListener messageListener = new MessageListener ();
2728 private SslHandlerProvider sslHandlerProvider ;
2829 private BeatsInitializer beatsInitializer ;
2930
3031 private final int clientInactivityTimeoutSeconds ;
3132
32- public Server (String host , int p , int clientInactivityTimeoutSeconds , int threadCount ) {
33+ // public Server(String host, int p, int clientInactivityTimeoutSeconds, int threadCount) {
34+ // this(host, p, clientInactivityTimeoutSeconds, threadCount, true);
35+ // }
36+
37+ public Server (String host , int p , int clientInactivityTimeoutSeconds , int threadCount , boolean protectDirectMemory ) {
3338 this .host = host ;
3439 port = p ;
3540 this .clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds ;
3641 beatsHeandlerThreadCount = threadCount ;
42+ this .protectDirectMemory = protectDirectMemory ;
3743 }
3844
3945 public void setSslHandlerProvider (SslHandlerProvider sslHandlerProvider ){
@@ -130,7 +136,9 @@ private class BeatsInitializer extends ChannelInitializer<SocketChannel> {
130136
131137 public void initChannel (SocketChannel socket ){
132138 ChannelPipeline pipeline = socket .pipeline ();
133- pipeline .addLast (new OOMConnectionCloser ());
139+ if (protectDirectMemory ) {
140+ pipeline .addLast (new OOMConnectionCloser ());
141+ }
134142
135143 if (isSslEnabled ()) {
136144 pipeline .addLast (SSL_HANDLER , sslHandlerProvider .sslHandlerForChannel (socket ));
@@ -139,8 +147,10 @@ public void initChannel(SocketChannel socket){
139147 new IdleStateHandler (localClientInactivityTimeoutSeconds , IDLESTATE_WRITER_IDLE_TIME_SECONDS , localClientInactivityTimeoutSeconds ));
140148 pipeline .addLast (BEATS_ACKER , new AckEncoder ());
141149 pipeline .addLast (CONNECTION_HANDLER , new ConnectionHandler ());
142- pipeline .addLast (new FlowLimiterHandler ());
143- pipeline .addLast (new ThunderingGuardHandler ());
150+ if (protectDirectMemory ) {
151+ pipeline .addLast (new FlowLimiterHandler ());
152+ pipeline .addLast (new ThunderingGuardHandler ());
153+ }
144154 pipeline .addLast (beatsHandlerExecutorGroup , new BeatsParser ());
145155 pipeline .addLast (beatsHandlerExecutorGroup , new BeatsHandler (localMessageListener ));
146156 }
0 commit comments