Catalog alignment
[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     static {
32         DEFAULT = new Timeouts(); 
33     }
34
35     private Timeouts() {
36     }
37
38     public Timeouts(int connectTimeoutMs, int readTimeoutMs) {
39         setConnectTimeoutMs(connectTimeoutMs);
40         setReadTimeoutMs(readTimeoutMs);
41     }
42
43     public Timeouts(Timeouts timeouts) {
44         setReadTimeoutMs(timeouts.readTimeoutMs);
45         setConnectTimeoutMs(timeouts.connectTimeoutMs);
46         setConnectPoolTimeoutMs(timeouts.connectPoolTimeoutMs);
47     }
48
49     public int getConnectTimeoutMs() {
50         return connectTimeoutMs;
51     }
52     
53     public void setConnectTimeoutMs(int connectTimeoutMs) {
54         validate(connectTimeoutMs);
55         this.connectTimeoutMs = connectTimeoutMs;
56     }
57     
58     public int getReadTimeoutMs() {
59         return readTimeoutMs;
60     }
61     
62     public void setReadTimeoutMs(int readTimeoutMs) {
63         validate(readTimeoutMs);
64         this.readTimeoutMs = readTimeoutMs;
65     }
66     
67     public int getConnectPoolTimeoutMs() {
68         return connectPoolTimeoutMs;
69     }
70     
71     public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
72         validate(connectPoolTimeoutMs);
73         this.connectPoolTimeoutMs = connectPoolTimeoutMs;
74     }
75     
76     @Override
77     public int hashCode() {
78         final int prime = 31;
79         int result = 1;
80         result = prime * result + connectPoolTimeoutMs;
81         result = prime * result + connectTimeoutMs;
82         result = prime * result + readTimeoutMs;
83         return result;
84     }
85     
86     @Override
87     public boolean equals(Object obj) {
88         if (this == obj)
89             return true;
90         if (obj == null)
91             return false;
92         if (getClass() != obj.getClass())
93             return false;
94         Timeouts other = (Timeouts) obj;
95         if (connectPoolTimeoutMs != other.connectPoolTimeoutMs)
96             return false;
97         if (connectTimeoutMs != other.connectTimeoutMs)
98             return false;
99         if (readTimeoutMs != other.readTimeoutMs)
100             return false;
101         return true;
102     }
103     
104     @Override
105     public String toString() {
106         StringBuilder builder = new StringBuilder();
107         builder.append("Timeouts [connectTimeoutMs=");
108         builder.append(connectTimeoutMs);
109         builder.append(", readTimeoutMs=");
110         builder.append(readTimeoutMs);
111         builder.append(", connectPoolTimeoutMs=");
112         builder.append(connectPoolTimeoutMs);
113         builder.append("]");
114         return builder.toString();
115     }
116     
117     private void validate(int timeout) {
118         if(timeout <= 0) {
119             throw new IllegalArgumentException("Timeout values cannot be less than zero");
120         }
121     }
122 }