12
12
import io .netty .handler .timeout .IdleStateHandler ;
13
13
import io .netty .util .concurrent .DefaultEventExecutorGroup ;
14
14
import io .netty .util .concurrent .EventExecutorGroup ;
15
+ import io .netty .util .internal .PlatformDependent ;
15
16
import org .apache .logging .log4j .LogManager ;
16
17
import org .apache .logging .log4j .Logger ;
17
18
import org .logstash .netty .SslHandlerProvider ;
@@ -30,16 +31,26 @@ public class Server {
30
31
31
32
private final int clientInactivityTimeoutSeconds ;
32
33
33
- // public Server(String host, int p, int clientInactivityTimeoutSeconds, int threadCount) {
34
- // this(host, p, clientInactivityTimeoutSeconds, threadCount, true);
35
- // }
36
-
37
34
public Server (String host , int p , int clientInactivityTimeoutSeconds , int threadCount , boolean protectDirectMemory ) {
38
35
this .host = host ;
39
36
port = p ;
40
37
this .clientInactivityTimeoutSeconds = clientInactivityTimeoutSeconds ;
41
38
beatsHeandlerThreadCount = threadCount ;
42
39
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
+ }
43
54
}
44
55
45
56
public void setSslHandlerProvider (SslHandlerProvider sslHandlerProvider ){
0 commit comments