-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathGracefulShutdown.java
More file actions
44 lines (38 loc) · 1.19 KB
/
GracefulShutdown.java
File metadata and controls
44 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import java.time.Duration;
import io.jooby.internal.GracefulShutdownHandler;
/**
* Install a handler that at application shutdown time:
*
* <p>- Waits for existing requests to finished with an optional timeout - Incoming requests are
* resolved as Service Unavailable(503)
*
* <p>NOTE: This extension must be installed at very beginning of your route pipeline.
*
* @author edgar
*/
public class GracefulShutdown implements Extension {
private Duration await;
/**
* Creates a new shutdown handler and waits for existing requests to finish or for specified
* amount of time.
*
* @param await Max time to wait for handlers to complete.
*/
public GracefulShutdown(Duration await) {
this.await = await;
}
/** Creates a new shutdown handler and waits for existing request to finish. */
public GracefulShutdown() {}
@Override
public void install(Jooby application) throws Exception {
GracefulShutdownHandler handler = new GracefulShutdownHandler(await);
application.use(handler);
application.onStop(handler::shutdown);
}
}