1   /*
2    * Copyright 2017 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server;
17  
18  import com.fasterxml.jackson.annotation.JsonProperty;
19  import com.google.common.base.MoreObjects;
20  
21  /**
22   * Graceful shutdown timeout.
23   */
24  public final class GracefulShutdownTimeout {
25      private final long quietPeriodMillis;
26      private final long timeoutMillis;
27  
28      /**
29       * Creates a new instance.
30       *
31       * @param quietPeriodMillis the number of milliseconds to wait for active requests to go end before
32       *                          shutting down. {@code 0} means the server will stop right away without waiting.
33       * @param timeoutMillis the number of milliseconds to wait before shutting down the server regardless of
34       *                      active requests. This should be set to a time greater than {@code quietPeriodMillis}
35       *                      to ensure the server shuts down even if there is a stuck request.
36       */
37      public GracefulShutdownTimeout(
38              @JsonProperty(value = "quietPeriodMillis", required = true) long quietPeriodMillis,
39              @JsonProperty(value = "timeoutMillis", required = true) long timeoutMillis) {
40          this.quietPeriodMillis = quietPeriodMillis;
41          this.timeoutMillis = timeoutMillis;
42      }
43  
44      /**
45       * Returns the quiet period of graceful shutdown process, in milliseconds.
46       */
47      @JsonProperty("quietPeriodMillis")
48      public long quietPeriodMillis() {
49          return quietPeriodMillis;
50      }
51  
52      /**
53       * Returns the timeout of graceful shutdown process, in milliseconds.
54       */
55      @JsonProperty("timeoutMillis")
56      public long timeoutMillis() {
57          return timeoutMillis;
58      }
59  
60      @Override
61      public String toString() {
62          return MoreObjects.toStringHelper(this)
63                            .add("quietPeriodMillis", quietPeriodMillis)
64                            .add("timeoutMillis", timeoutMillis).toString();
65      }
66  }