Sync Integ to Master
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / http / config / Timeouts.java
1 package org.openecomp.sdc.common.http.config;
2
3 public class Timeouts {
4
5     private static final int DEFAULT_TIMEOUT_MS = 15000;
6     private int connectTimeoutMs = DEFAULT_TIMEOUT_MS;
7     private int readTimeoutMs = DEFAULT_TIMEOUT_MS;
8     private int connectPoolTimeoutMs = DEFAULT_TIMEOUT_MS;
9
10     public static final Timeouts DEFAULT;
11     static {
12         DEFAULT = new Timeouts(); 
13     }
14
15     private Timeouts() {
16     }
17
18     public Timeouts(int connectTimeoutMs, int readTimeoutMs) {
19         setConnectTimeoutMs(connectTimeoutMs);
20         setReadTimeoutMs(readTimeoutMs);
21     }
22
23     public Timeouts(Timeouts timeouts) {
24         setReadTimeoutMs(timeouts.readTimeoutMs);
25         setConnectTimeoutMs(timeouts.connectTimeoutMs);
26         setConnectPoolTimeoutMs(timeouts.connectPoolTimeoutMs);
27     }
28
29     public int getConnectTimeoutMs() {
30         return connectTimeoutMs;
31     }
32     
33     public void setConnectTimeoutMs(int connectTimeoutMs) {
34         validate(connectTimeoutMs);
35         this.connectTimeoutMs = connectTimeoutMs;
36     }
37     
38     public int getReadTimeoutMs() {
39         return readTimeoutMs;
40     }
41     
42     public void setReadTimeoutMs(int readTimeoutMs) {
43         validate(readTimeoutMs);
44         this.readTimeoutMs = readTimeoutMs;
45     }
46     
47     public int getConnectPoolTimeoutMs() {
48         return connectPoolTimeoutMs;
49     }
50     
51     public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
52         validate(connectPoolTimeoutMs);
53         this.connectPoolTimeoutMs = connectPoolTimeoutMs;
54     }
55     
56     @Override
57     public int hashCode() {
58         final int prime = 31;
59         int result = 1;
60         result = prime * result + connectPoolTimeoutMs;
61         result = prime * result + connectTimeoutMs;
62         result = prime * result + readTimeoutMs;
63         return result;
64     }
65     
66     @Override
67     public boolean equals(Object obj) {
68         if (this == obj)
69             return true;
70         if (obj == null)
71             return false;
72         if (getClass() != obj.getClass())
73             return false;
74         Timeouts other = (Timeouts) obj;
75         if (connectPoolTimeoutMs != other.connectPoolTimeoutMs)
76             return false;
77         if (connectTimeoutMs != other.connectTimeoutMs)
78             return false;
79         if (readTimeoutMs != other.readTimeoutMs)
80             return false;
81         return true;
82     }
83     
84     @Override
85     public String toString() {
86         StringBuilder builder = new StringBuilder();
87         builder.append("Timeouts [connectTimeoutMs=");
88         builder.append(connectTimeoutMs);
89         builder.append(", readTimeoutMs=");
90         builder.append(readTimeoutMs);
91         builder.append(", connectPoolTimeoutMs=");
92         builder.append(connectPoolTimeoutMs);
93         builder.append("]");
94         return builder.toString();
95     }
96     
97     private void validate(int timeout) {
98         if(timeout <= 0) {
99             throw new IllegalArgumentException("Timeout values cannot be less than zero");
100         }
101     }
102 }