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;
32 DEFAULT = new Timeouts();
38 public Timeouts(int connectTimeoutMs, int readTimeoutMs) {
39 setConnectTimeoutMs(connectTimeoutMs);
40 setReadTimeoutMs(readTimeoutMs);
43 public Timeouts(Timeouts timeouts) {
44 setReadTimeoutMs(timeouts.readTimeoutMs);
45 setConnectTimeoutMs(timeouts.connectTimeoutMs);
46 setConnectPoolTimeoutMs(timeouts.connectPoolTimeoutMs);
49 public int getConnectTimeoutMs() {
50 return connectTimeoutMs;
53 public void setConnectTimeoutMs(int connectTimeoutMs) {
54 validate(connectTimeoutMs);
55 this.connectTimeoutMs = connectTimeoutMs;
58 public int getReadTimeoutMs() {
62 public void setReadTimeoutMs(int readTimeoutMs) {
63 validate(readTimeoutMs);
64 this.readTimeoutMs = readTimeoutMs;
67 public int getConnectPoolTimeoutMs() {
68 return connectPoolTimeoutMs;
71 public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
72 validate(connectPoolTimeoutMs);
73 this.connectPoolTimeoutMs = connectPoolTimeoutMs;
77 public int hashCode() {
80 result = prime * result + connectPoolTimeoutMs;
81 result = prime * result + connectTimeoutMs;
82 result = prime * result + readTimeoutMs;
87 public boolean equals(Object obj) {
92 if (getClass() != obj.getClass())
94 Timeouts other = (Timeouts) obj;
95 if (connectPoolTimeoutMs != other.connectPoolTimeoutMs)
97 if (connectTimeoutMs != other.connectTimeoutMs)
99 if (readTimeoutMs != other.readTimeoutMs)
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);
114 return builder.toString();
117 private void validate(int timeout) {
119 throw new IllegalArgumentException("Timeout values cannot be less than zero");