11/*
2- * Copyright (c) 2005, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2005, 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3737@ SuppressWarnings ("removal" )
3838class ServerConfig {
3939
40- private static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.
40+ private static final int DEFAULT_IDLE_TIMER_SCHEDULE_MILLIS = 10000 ; // 10 sec.
4141
42- /* These values must be a reasonable multiple of clockTick */
43- private static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
42+ private static final long DEFAULT_IDLE_INTERVAL_IN_SECS = 30 ;
43+ private static final int DEFAULT_MAX_CONNECTIONS = - 1 ; // no limit on maximum connections
4444 private static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;
4545
4646 private static final long DEFAULT_MAX_REQ_TIME = -1 ; // default: forever
4747 private static final long DEFAULT_MAX_RSP_TIME = -1 ; // default: forever
48- private static final long DEFAULT_TIMER_MILLIS = 1000 ;
48+ // default timer schedule, in milli seconds, for the timer task that's responsible for
49+ // timing out request/response if max request/response time is configured
50+ private static final long DEFAULT_REQ_RSP_TIMER_TASK_SCHEDULE_MILLIS = 1000 ;
4951 private static final int DEFAULT_MAX_REQ_HEADERS = 200 ;
5052 private static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024 ;
5153
52- private static int clockTick ;
53- private static long idleInterval ;
54+ private static long idleTimerScheduleMillis ;
55+ private static long idleIntervalMillis ;
5456 // The maximum number of bytes to drain from an inputstream
5557 private static long drainAmount ;
58+ // the maximum number of connections that the server will allow to be open
59+ // after which it will no longer "accept()" any new connections, till the
60+ // current connection count goes down due to completion of processing the requests
61+ private static int maxConnections ;
5662 private static int maxIdleConnections ;
5763 // The maximum number of request headers allowable
5864 private static int maxReqHeaders ;
5965 // max time a request or response is allowed to take
6066 private static long maxReqTime ;
6167 private static long maxRspTime ;
62- private static long timerMillis ;
68+ private static long reqRspTimerScheduleMillis ;
6369 private static boolean debug ;
6470
6571 // the value of the TCP_NODELAY socket-level option
@@ -70,11 +76,22 @@ class ServerConfig {
7076 new PrivilegedAction <Void >() {
7177 @ Override
7278 public Void run () {
73- idleInterval = Long .getLong ("sun.net.httpserver.idleInterval" ,
74- DEFAULT_IDLE_INTERVAL ) * 1000 ;
79+ idleIntervalMillis = Long .getLong ("sun.net.httpserver.idleInterval" ,
80+ DEFAULT_IDLE_INTERVAL_IN_SECS ) * 1000 ;
81+ if (idleIntervalMillis <= 0 ) {
82+ idleIntervalMillis = DEFAULT_IDLE_INTERVAL_IN_SECS * 1000 ;
83+ }
84+
85+ idleTimerScheduleMillis = Long .getLong ("sun.net.httpserver.clockTick" ,
86+ DEFAULT_IDLE_TIMER_SCHEDULE_MILLIS );
87+ if (idleTimerScheduleMillis <= 0 ) {
88+ // ignore zero or negative value and use the default schedule
89+ idleTimerScheduleMillis = DEFAULT_IDLE_TIMER_SCHEDULE_MILLIS ;
90+ }
7591
76- clockTick = Integer .getInteger ("sun.net.httpserver.clockTick" ,
77- DEFAULT_CLOCK_TICK );
92+ maxConnections = Integer .getInteger (
93+ "jdk.httpserver.maxConnections" ,
94+ DEFAULT_MAX_CONNECTIONS );
7895
7996 maxIdleConnections = Integer .getInteger (
8097 "sun.net.httpserver.maxIdleConnections" ,
@@ -93,8 +110,13 @@ public Void run () {
93110 maxRspTime = Long .getLong ("sun.net.httpserver.maxRspTime" ,
94111 DEFAULT_MAX_RSP_TIME );
95112
96- timerMillis = Long .getLong ("sun.net.httpserver.timerMillis" ,
97- DEFAULT_TIMER_MILLIS );
113+ reqRspTimerScheduleMillis = Long .getLong ("sun.net.httpserver.timerMillis" ,
114+ DEFAULT_REQ_RSP_TIMER_TASK_SCHEDULE_MILLIS );
115+ if (reqRspTimerScheduleMillis <= 0 ) {
116+ // ignore any negative or zero value for this configuration and reset
117+ // to default schedule
118+ reqRspTimerScheduleMillis = DEFAULT_REQ_RSP_TIMER_TASK_SCHEDULE_MILLIS ;
119+ }
98120
99121 debug = Boolean .getBoolean ("sun.net.httpserver.debug" );
100122
@@ -150,14 +172,34 @@ static boolean debugEnabled() {
150172 return debug ;
151173 }
152174
153- static long getIdleInterval () {
154- return idleInterval ;
175+ /**
176+ * {@return Returns the maximum duration, in milli seconds, a connection can be idle}
177+ */
178+ static long getIdleIntervalMillis () {
179+ return idleIntervalMillis ;
180+ }
181+
182+ /**
183+ * {@return Returns the schedule, in milli seconds, for the timer task that is responsible
184+ * for managing the idle connections}
185+ */
186+ static long getIdleTimerScheduleMillis () {
187+ return idleTimerScheduleMillis ;
155188 }
156189
157- static int getClockTick () {
158- return clockTick ;
190+ /**
191+ * @return Returns the maximum number of connections that can be open at any given time.
192+ * This method can return a value of 0 or negative to represent that the limit hasn't
193+ * been configured.
194+ */
195+ static int getMaxConnections () {
196+ return maxConnections ;
159197 }
160198
199+ /**
200+ * @return Returns the maximum number of connections that can be idle. This method
201+ * can return a value of 0 or negative.
202+ */
161203 static int getMaxIdleConnections () {
162204 return maxIdleConnections ;
163205 }
@@ -170,16 +212,30 @@ static int getMaxReqHeaders() {
170212 return maxReqHeaders ;
171213 }
172214
215+ /**
216+ * @return Returns the maximum amount of time the server will wait for the request to be read
217+ * completely. This method can return a value of 0 or negative to imply no maximum limit has
218+ * been configured.
219+ */
173220 static long getMaxReqTime () {
174221 return maxReqTime ;
175222 }
176223
224+ /**
225+ * @return Returns the maximum amount of time the server will wait for the response to be generated
226+ * for a request that is being processed. This method can return a value of 0 or negative to
227+ * imply no maximum limit has been configured.
228+ */
177229 static long getMaxRspTime () {
178230 return maxRspTime ;
179231 }
180232
181- static long getTimerMillis () {
182- return timerMillis ;
233+ /**
234+ * {@return Returns the timer schedule of the task that's responsible for timing out
235+ * request/response that have been running longer than any configured timeout}
236+ */
237+ static long getReqRspTimerScheduleMillis () {
238+ return reqRspTimerScheduleMillis ;
183239 }
184240
185241 static boolean noDelay () {
0 commit comments