fixing warnings from checkstyle in common-app-api
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / http / config / Timeouts.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.common.http.config;
22
23 public class Timeouts {
24
25     private static final int DEFAULT_TIMEOUT_MS = 15000;
26     private int connectTimeoutMs = DEFAULT_TIMEOUT_MS;
27     private int readTimeoutMs = DEFAULT_TIMEOUT_MS;
28     private int connectPoolTimeoutMs = DEFAULT_TIMEOUT_MS;
29
30     public static final Timeouts DEFAULT;
31
32     static {
33         DEFAULT = new Timeouts();
34     }
35
36     private Timeouts() {
37     }
38
39     public Timeouts(int connectTimeoutMs, int readTimeoutMs) {
40         setConnectTimeoutMs(connectTimeoutMs);
41         setReadTimeoutMs(readTimeoutMs);
42     }
43
44     public Timeouts(Timeouts timeouts) {
45         setReadTimeoutMs(timeouts.readTimeoutMs);
46         setConnectTimeoutMs(timeouts.connectTimeoutMs);
47         setConnectPoolTimeoutMs(timeouts.connectPoolTimeoutMs);
48     }
49
50     public int getConnectTimeoutMs() {
51         return connectTimeoutMs;
52     }
53
54     public void setConnectTimeoutMs(int connectTimeoutMs) {
55         validate(connectTimeoutMs);
56         this.connectTimeoutMs = connectTimeoutMs;
57     }
58
59     public int getReadTimeoutMs() {
60         return readTimeoutMs;
61     }
62
63     public void setReadTimeoutMs(int readTimeoutMs) {
64         validate(readTimeoutMs);
65         this.readTimeoutMs = readTimeoutMs;
66     }
67
68     public int getConnectPoolTimeoutMs() {
69         return connectPoolTimeoutMs;
70     }
71
72     public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
73         validate(connectPoolTimeoutMs);
74         this.connectPoolTimeoutMs = connectPoolTimeoutMs;
75     }
76
77     @Override
78     public int hashCode() {
79         final int prime = 31;
80         int result = 1;
81         result = prime * result + connectPoolTimeoutMs;
82         result = prime * result + connectTimeoutMs;
83         result = prime * result + readTimeoutMs;
84         return result;
85     }
86
87     @Override
88     public boolean equals(Object obj) {
89         if (this == obj) {
90             return true;
91         }
92         if (obj == null) {
93             return false;
94         }
95         if (getClass() != obj.getClass()) {
96             return false;
97         }
98         Timeouts other = (Timeouts) obj;
99         if (connectPoolTimeoutMs != other.connectPoolTimeoutMs) {
100             return false;
101         }
102         if (connectTimeoutMs != other.connectTimeoutMs) {
103             return false;
104         }
105         return readTimeoutMs == other.readTimeoutMs;
106     }
107
108     @Override
109     public String toString() {
110         return "Timeouts [connectTimeoutMs=" + connectTimeoutMs
111                 + ", readTimeoutMs=" + readTimeoutMs
112                 + ", connectPoolTimeoutMs=" + connectPoolTimeoutMs
113                 + "]";
114     }
115
116     private void validate(int timeout) {
117         if (timeout <= 0) {
118             throw new IllegalArgumentException("Timeout values cannot be less than zero");
119         }
120     }
121 }