1212import io .netty .handler .timeout .IdleStateHandler ;
1313import io .netty .util .concurrent .DefaultEventExecutorGroup ;
1414import io .netty .util .concurrent .EventExecutorGroup ;
15+ import io .netty .util .internal .PlatformDependent ;
1516import org .apache .logging .log4j .LogManager ;
1617import org .apache .logging .log4j .Logger ;
1718import org .logstash .netty .SslHandlerProvider ;
@@ -30,16 +31,26 @@ public class Server {
3031
3132 private final int clientInactivityTimeoutSeconds ;
3233
33- // public Server(String host, int p, int clientInactivityTimeoutSeconds, int threadCount) {
34- // this(host, p, clientInactivityTimeoutSeconds, threadCount, true);
35- // }
36-
3734 public Server (String host , int p , int clientInactivityTimeoutSeconds , int threadCount , boolean protectDirectMemory ) {
3835 this .host = host ;
3936 port = p ;
4037 this .clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds ;
4138 beatsHeandlerThreadCount = threadCount ;
4239 this .protectDirectMemory = protectDirectMemory ;
40+
41+ validateMinimumDirectMemory ();
42+ }
43+
44+ /**
45+ * Validate if the configured available direct memory is enough for safe processing, else throws a ConfigurationException
46+ * */
47+ private void validateMinimumDirectMemory () {
48+ long maxDirectMemoryAllocatable = PlatformDependent .maxDirectMemory ();
49+ if (maxDirectMemoryAllocatable < 256 * 1024 * 1024 ) {
50+ long roundedMegabytes = Math .round ((double ) maxDirectMemoryAllocatable / 1024 / 1024 );
51+ throw new IllegalArgumentException ("Max direct memory should be at least 256MB but was " + roundedMegabytes + "MB, " +
52+ "please check your MaxDirectMemorySize and io.netty.maxDirectMemory settings" );
53+ }
4354 }
4455
4556 public void setSslHandlerProvider (SslHandlerProvider sslHandlerProvider ){
0 commit comments