2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.common.http.config;
23 public class Timeouts {
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;
30 public static final Timeouts DEFAULT;
33 DEFAULT = new Timeouts();
39 public Timeouts(int connectTimeoutMs, int readTimeoutMs) {
40 setConnectTimeoutMs(connectTimeoutMs);
41 setReadTimeoutMs(readTimeoutMs);
44 public Timeouts(Timeouts timeouts) {
45 setReadTimeoutMs(timeouts.readTimeoutMs);
46 setConnectTimeoutMs(timeouts.connectTimeoutMs);
47 setConnectPoolTimeoutMs(timeouts.connectPoolTimeoutMs);
50 public int getConnectTimeoutMs() {
51 return connectTimeoutMs;
54 public void setConnectTimeoutMs(int connectTimeoutMs) {
55 validate(connectTimeoutMs);
56 this.connectTimeoutMs = connectTimeoutMs;
59 public int getReadTimeoutMs() {
63 public void setReadTimeoutMs(int readTimeoutMs) {
64 validate(readTimeoutMs);
65 this.readTimeoutMs = readTimeoutMs;
68 public int getConnectPoolTimeoutMs() {
69 return connectPoolTimeoutMs;
72 public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
73 validate(connectPoolTimeoutMs);
74 this.connectPoolTimeoutMs = connectPoolTimeoutMs;
78 public int hashCode() {
81 result = prime * result + connectPoolTimeoutMs;
82 result = prime * result + connectTimeoutMs;
83 result = prime * result + readTimeoutMs;
88 public boolean equals(Object obj) {
95 if (getClass() != obj.getClass()) {
98 Timeouts other = (Timeouts) obj;
99 if (connectPoolTimeoutMs != other.connectPoolTimeoutMs) {
102 if (connectTimeoutMs != other.connectTimeoutMs) {
105 return readTimeoutMs == other.readTimeoutMs;
109 public String toString() {
110 return "Timeouts [connectTimeoutMs=" + connectTimeoutMs
111 + ", readTimeoutMs=" + readTimeoutMs
112 + ", connectPoolTimeoutMs=" + connectPoolTimeoutMs
116 private void validate(int timeout) {
118 throw new IllegalArgumentException("Timeout values cannot be less than zero");