1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.settings;
20
21 import fr.cnes.doi.utils.spec.Requirement;
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
24 import org.restlet.Server;
25 import org.restlet.data.Parameter;
26 import org.restlet.ext.jetty.JettyServerHelper;
27
28
29
30
31
32
33
34 @Requirement(reqId = Requirement.DOI_CONFIG_010, reqName = Requirement.DOI_CONFIG_010_NAME)
35 public final class JettySettings extends JettyServerHelper {
36
37
38
39
40 private static final Logger LOG = LogManager.getLogger(JettySettings.class.getName());
41
42
43
44
45 private final DoiSettings settings;
46
47
48
49
50 private final Server server;
51
52
53
54
55
56
57
58 public JettySettings(final Server server,
59 final DoiSettings settings) {
60 super(server);
61 LOG.trace("Entering in Constructor");
62 this.server = server;
63 this.settings = settings;
64 LOG.trace("Exiting from Constructor");
65 }
66
67
68
69
70
71
72
73
74
75 @Override
76 public int getHttpRequestHeaderSize() {
77 LOG.traceEntry();
78 int result;
79 try {
80 result = settings.getInt(Consts.JETTY_REQUEST_HEADER_SIZE);
81 LOG.debug("getHttpRequestHeaderSize : default value from configuration file loaded");
82 } catch (NumberFormatException e) {
83 result = super.getHttpRequestHeaderSize();
84 LOG.debug("getHttpRequestHeaderSize : default value loaded");
85 }
86 LOG.info("getHttpRequestHeaderSize : {}", result);
87 return LOG.traceExit(result);
88 }
89
90
91
92
93
94
95
96
97 @Override
98 public int getHttpResponseHeaderSize() {
99 LOG.traceEntry();
100 int result;
101 try {
102 result = settings.getInt(Consts.JETTY_RESPONSE_HEADER_SIZE);
103 LOG.debug("getHttpResponseHeaderSize : default value from configuration file loaded");
104 } catch (NumberFormatException e) {
105 result = super.getHttpResponseHeaderSize();
106 LOG.debug("getHttpResponseHeaderSize : default value loaded");
107 }
108 LOG.info("getHttpResponseHeaderSize : {}", result);
109 LOG.trace("Exiting from getHttpResponseHeaderSize with result {}", result);
110 return result;
111 }
112
113
114
115
116
117
118 @Override
119 public int getThreadPoolMinThreads() {
120 LOG.traceEntry();
121 int result;
122 try {
123 result = settings.getInt(Consts.JETTY_MIN_THREADS);
124 LOG.debug("getThreadPoolMinThreads : default value from configuration file loaded");
125 } catch (NumberFormatException e) {
126 result = super.getThreadPoolMinThreads();
127 LOG.debug("getThreadPoolMinThreads : default value loaded");
128 }
129 LOG.info("getThreadPoolMinThreads : {}", result);
130 return LOG.traceExit(result);
131 }
132
133
134
135
136
137
138 @Override
139 public int getThreadPoolMaxThreads() {
140 LOG.traceEntry();
141 int result;
142 try {
143 result = settings.getInt(Consts.JETTY_MAX_THREADS);
144 LOG.debug("getThreadPoolMaxThreads : default value from configuration file loaded");
145 } catch (NumberFormatException e) {
146 result = super.getThreadPoolMaxThreads();
147 LOG.debug("getThreadPoolMaxThreads : default value loaded");
148 }
149 LOG.info("getThreadPoolMaxThreads : {}", result);
150 return LOG.traceExit(result);
151 }
152
153
154
155
156
157
158 @Override
159 public int getThreadPoolThreadsPriority() {
160 LOG.traceEntry();
161 int result;
162 try {
163 result = settings.getInt(Consts.JETTY_THREADS_PRIORITY);
164 LOG.debug("getThreadPoolThreadsPriority : default value from configuration file loaded");
165 } catch (NumberFormatException e) {
166 result = super.getThreadPoolThreadsPriority();
167 LOG.debug("getThreadPoolThreadsPriority : default value loaded");
168 }
169 LOG.info("getThreadPoolThreadsPriority : {}", result);
170 return LOG.traceExit(result);
171 }
172
173
174
175
176
177
178
179 @Override
180 public int getThreadPoolIdleTimeout() {
181 LOG.traceEntry();
182 int result;
183 try {
184 result = settings.getInt(Consts.JETTY_THREAD_MAX_IDLE_TIME_MS);
185 LOG.debug("getThreadPoolIdleTimeout : default value from configuration file loaded");
186 } catch (NumberFormatException e) {
187 result = super.getThreadPoolIdleTimeout();
188 LOG.debug("getThreadPoolIdleTimeout : default value loaded");
189 }
190 LOG.info("getThreadPoolIdleTimeout : {}", result);
191 return LOG.traceExit(result);
192 }
193
194
195
196
197
198
199
200 @Override
201 public long getThreadPoolStopTimeout() {
202 LOG.traceEntry();
203 long result;
204 try {
205 result = settings.getLong(Consts.JETTY_THREAD_STOP_TIME_MS);
206 LOG.debug("getThreadPoolStopTimeout : default value from configuration file loaded");
207 } catch (NumberFormatException e) {
208 result = super.getThreadPoolStopTimeout();
209 LOG.debug("getThreadPoolStopTimeout : default value loaded");
210 }
211 LOG.info("getThreadPoolStopTimeout : {}", result);
212 return LOG.traceExit(result);
213 }
214
215
216
217
218
219
220
221 @Override
222 public int getConnectorAcceptors() {
223 LOG.traceEntry();
224 int result;
225 try {
226 result = settings.getInt(Consts.JETTY_ACCEPTOR_THREADS);
227 LOG.debug("getConnectorAcceptors : default value from configuration file loaded");
228 } catch (NumberFormatException e) {
229 result = super.getConnectorAcceptors();
230 LOG.debug("getConnectorAcceptors : default value loaded");
231 }
232 LOG.info("getConnectorAcceptors : {}", result);
233 return LOG.traceExit(result);
234 }
235
236
237
238
239
240
241
242 @Override
243 public int getConnectorSelectors() {
244 LOG.traceEntry();
245 int result;
246 try {
247 result = settings.getInt(Consts.JETTY_SELECTOR_THREADS);
248 LOG.debug("getConnectorSelectors : default value from configuration file loaded");
249 } catch (NumberFormatException e) {
250 result = super.getConnectorSelectors();
251 LOG.debug("getConnectorSelectors : default value loaded");
252 }
253 LOG.info("getConnectorSelectors : {}", result);
254 return LOG.traceExit(result);
255 }
256
257
258
259
260
261
262
263 @Override
264 public int getLowResourceMonitorIdleTimeout() {
265 LOG.traceEntry();
266 int result;
267 try {
268 result = settings.getInt(Consts.JETTY_LOW_RESOURCES_MAX_IDLE_TIME_MS);
269 LOG.debug(
270 "getLowResourceMonitorIdleTimeout : default value from configuration file loaded");
271 } catch (NumberFormatException e) {
272 result = super.getLowResourceMonitorIdleTimeout();
273 LOG.debug("getLowResourceMonitorIdleTimeout : default value loaded");
274 }
275 LOG.info("getLowResourceMonitorIdleTimeout : {}", result);
276 return LOG.traceExit(result);
277 }
278
279
280
281
282
283
284
285 @Override
286 public int getLowResourceMonitorPeriod() {
287 LOG.traceEntry();
288 int result;
289 try {
290 result = settings.getInt(Consts.JETTY_LOW_RESOURCES_PERIOD);
291 LOG.debug("getLowResourceMonitorPeriod : default value from configuration file loaded");
292 } catch (NumberFormatException e) {
293 result = super.getLowResourceMonitorPeriod();
294 LOG.debug("getLowResourceMonitorPeriod : default value loaded");
295 }
296 LOG.info("getLowResourceMonitorPeriod : {}", result);
297 return LOG.traceExit(result);
298 }
299
300
301
302
303
304
305
306 @Override
307 public long getLowResourceMonitorMaxMemory() {
308 LOG.traceEntry();
309 long result;
310 try {
311 result = settings.getLong(Consts.JETTY_LOW_RESOURCES_MAX_MEMORY);
312 LOG.debug(
313 "getLowResourceMonitorMaxMemory : default value from configuration file loaded");
314 } catch (NumberFormatException e) {
315 result = super.getLowResourceMonitorMaxMemory();
316 LOG.debug("getLowResourceMonitorMaxMemory : default value loaded");
317 }
318 LOG.info("getLowResourceMonitorMaxMemory : {}", result);
319 return LOG.traceExit(result);
320 }
321
322
323
324
325
326
327
328 @Override
329 public int getLowResourceMonitorMaxConnections() {
330 LOG.traceEntry();
331 int result;
332 try {
333 result = settings.getInt(Consts.JETTY_LOW_RESOURCES_MAX_MEMORY);
334 LOG.debug(
335 "getLowResourceMonitorMaxConnections : default value from configuration file loaded");
336 } catch (NumberFormatException e) {
337 result = super.getLowResourceMonitorMaxConnections();
338 LOG.debug("getLowResourceMonitorMaxConnections : default value loaded");
339 }
340 LOG.info("getLowResourceMonitorMaxConnections : {}", result);
341 return LOG.traceExit(result);
342 }
343
344
345
346
347
348
349
350 @Override
351 public boolean getLowResourceMonitorThreads() {
352 LOG.traceEntry();
353 boolean result;
354 try {
355 result = settings.getBoolean(Consts.JETTY_LOW_RESOURCES_THREADS);
356 LOG.debug("getLowResourceMonitorThreads : default value from configuration file loaded");
357 } catch (IllegalArgumentException e) {
358 result = super.getLowResourceMonitorThreads();
359 LOG.debug("getLowResourceMonitorThreads : default value loaded");
360 }
361 LOG.info("getLowResourceMonitorThreads : {}", result);
362 return LOG.traceExit(result);
363 }
364
365
366
367
368
369
370 @Override
371 public int getConnectorAcceptQueueSize() {
372 LOG.traceEntry();
373 int result;
374 try {
375 result = settings.getInt(Consts.JETTY_ACCEPT_QUEUE_SIZE);
376 LOG.debug("getConnectorAcceptQueueSize : default value from configuration file loaded");
377 } catch (NumberFormatException e) {
378 result = super.getConnectorAcceptQueueSize();
379 LOG.debug("getConnectorAcceptQueueSize : default value loaded");
380 }
381 LOG.info("getConnectorAcceptQueueSize : {}", result);
382 return LOG.traceExit(result);
383 }
384
385
386
387
388
389
390
391 @Override
392 public int getConnectorSoLingerTime() {
393 LOG.traceEntry();
394 int result;
395 try {
396 result = settings.getInt(Consts.JETTY_SO_LINGER_TIME);
397 LOG.debug("getConnectorSoLingerTime : default value from configuration file loaded");
398 } catch (NumberFormatException e) {
399 result = super.getConnectorSoLingerTime();
400 LOG.debug("getConnectorSoLingerTime : default value loaded");
401 }
402 LOG.info("getConnectorSoLingerTime : {}", result);
403 return LOG.traceExit(result);
404 }
405
406
407
408
409
410
411
412
413
414 @Override
415 public int getConnectorIdleTimeout() {
416 LOG.traceEntry();
417 int result;
418 try {
419 result = settings.getInt(Consts.JETTY_IO_MAX_IDLE_TIME_MS);
420 LOG.debug("getConnectorIdleTimeout : default value from configuration file loaded");
421 } catch (NumberFormatException e) {
422 result = super.getConnectorIdleTimeout();
423 LOG.debug("getConnectorIdleTimeout : default value loaded");
424 }
425 LOG.info("getConnectorIdleTimeout : {}", result);
426 return LOG.traceExit(result);
427 }
428
429
430
431
432
433
434
435
436
437 @Override
438 public int getHttpOutputBufferSize() {
439 LOG.traceEntry();
440 int result;
441 try {
442 result = settings.getInt(Consts.JETTY_RESPONSE_BUFFER_SIZE);
443 LOG.debug("getHttpOutputBufferSize : default value from configuration file loaded");
444 } catch (NumberFormatException e) {
445 result = super.getHttpOutputBufferSize();
446 LOG.debug("getHttpOutputBufferSize : default value loaded");
447 }
448 LOG.info("getHttpOutputBufferSize : {}", result);
449 return LOG.traceExit(result);
450 }
451
452
453
454
455
456
457 @Override
458 public int getHttpHeaderCacheSize() {
459 LOG.traceEntry();
460 int result;
461 try {
462 result = settings.getInt(Consts.JETTY_REQUEST_BUFFER_SIZE);
463 LOG.debug("getHttpHeaderCacheSize : default value from configuration file loaded");
464 } catch (NumberFormatException e) {
465 result = super.getHttpHeaderCacheSize();
466 LOG.debug("getHttpHeaderCacheSize : default value loaded");
467 }
468 LOG.info("getHttpHeaderCacheSize : {}", result);
469 return LOG.traceExit(result);
470 }
471
472
473
474
475
476
477
478 @Override
479 public int getConnectorStopTimeout() {
480 LOG.traceEntry();
481 int result;
482 try {
483 result = settings.getInt(Consts.JETTY_GRACEFUL_SHUTDOWN);
484 LOG.debug("getConnectorStopTimeout : default value from configuration file loaded");
485 } catch (NumberFormatException e) {
486 result = super.getConnectorStopTimeout();
487 LOG.debug("getConnectorStopTimeout : default value loaded");
488 }
489 LOG.info("getConnectorStopTimeout : {}", result);
490 return LOG.traceExit(result);
491 }
492
493
494
495
496
497
498
499 @Override
500 public long getLowResourceMonitorStopTimeout() {
501 LOG.traceEntry();
502 long result;
503 try {
504 result = settings.getLong(Consts.JETTY_GRACEFUL_SHUTDOWN);
505 LOG.debug(
506 "getLowResourceMonitorStopTimeout : default value from configuration file loaded");
507 } catch (NumberFormatException e) {
508 result = super.getLowResourceMonitorStopTimeout();
509 LOG.debug("getLowResourceMonitorStopTimeout : default value loaded");
510 }
511 LOG.info("getLowResourceMonitorStopTimeout : {}", result);
512 return LOG.traceExit(result);
513 }
514
515
516
517
518 public void addParamsToServerContext() {
519 LOG.traceEntry();
520 LOG.info("---- Jetty parameters ----");
521 addParam("threadPool.minThreads", getThreadPoolMinThreads());
522 addParam("threadPool.maxThreads", getThreadPoolMaxThreads());
523 addParam("threadPool.threadsPriority", getThreadPoolThreadsPriority());
524 addParam("threadPool.idleTimeout", getThreadPoolIdleTimeout());
525 addParam("threadPool.stopTimeout", getThreadPoolStopTimeout());
526 addParam("connector.acceptors", getConnectorAcceptors());
527 addParam("connector.selectors", getConnectorSelectors());
528 addParam("connector.acceptQueueSize", getConnectorAcceptQueueSize());
529 addParam("connector.idleTimeout", getConnectorIdleTimeout());
530 addParam("connector.soLingerTime", getConnectorSoLingerTime());
531 addParam("connector.stopTimeout", getConnectorStopTimeout());
532 addParam("http.headerCacheSize", getHttpHeaderCacheSize());
533 addParam("http.requestHeaderSize", getHttpRequestHeaderSize());
534 addParam("http.responseHeaderSize", getHttpResponseHeaderSize());
535 addParam("http.outputBufferSize", getHttpOutputBufferSize());
536 addParam("lowResource.period", getLowResourceMonitorPeriod());
537 addParam("lowResource.threads", getLowResourceMonitorThreads());
538 addParam("lowResource.maxMemory", getLowResourceMonitorMaxMemory());
539 addParam("lowResource.maxConnections", getLowResourceMonitorMaxConnections());
540 addParam("lowResource.idleTimeout", getLowResourceMonitorIdleTimeout());
541 addParam("lowResource.stopTimeout", getLowResourceMonitorStopTimeout());
542 LOG.info("Jetty settings have been loaded");
543 LOG.info("---------------------------");
544 LOG.traceExit();
545 }
546
547
548
549
550
551
552
553
554 private void addParam(final String propName,
555 final Object propValue) {
556 LOG.traceEntry("Parameters : {} and {}", propName, propValue);
557 if (propValue == null) {
558 throw new IllegalArgumentException("propValue for " + propName + " is not defined");
559 }
560 final Parameter param = this.server.getContext().getParameters().getFirst(propName);
561 if (param == null) {
562 this.server.getContext().getParameters().add(propName, String.valueOf(propValue));
563 LOG.info("add to a new param {} : {}", propName, propValue);
564 } else {
565 param.setValue(String.valueOf(propValue));
566 LOG.info("add to an existant param {} : {}", propName, propValue);
567 }
568 LOG.traceExit();
569 }
570 }