6c2c76e87c21dc599c22ebdddfd04bed516b8f43
[so.git] / common / src / main / java / org / onap / so / configuration / rest / HttpClientConnectionConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.configuration.rest;
22
23 import java.util.concurrent.TimeUnit;
24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.stereotype.Service;
26
27 /**
28  * This class is used configure the parameters needed for {@link org.apache.http.impl.client.CloseableHttpClient}
29  * 
30  * @author waqas.ikram@est.tech
31  */
32 @Service
33 public class HttpClientConnectionConfiguration {
34
35     @Value(value = "${rest.http.client.configuration.connTimeOutInSec:10}")
36     private int connectionTimeOutInSeconds;
37
38     @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:180}")
39     private int socketTimeOutInSeconds;
40
41     @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:600}")
42     private int timeToLiveInSeconds;
43
44     @Value(value = "${rest.http.client.configuration.maxConnections:10}")
45     private int maxConnections;
46
47     @Value(value = "${rest.http.client.configuration.maxConnectionsPerRoute:2}")
48     private int maxConnectionsPerRoute;
49
50     /**
51      * @return the socket connection time out in milliseconds
52      */
53     public int getSocketTimeOutInMiliSeconds() {
54         return (int) TimeUnit.SECONDS.toMillis(socketTimeOutInSeconds);
55     }
56
57     /**
58      * @return the maximum total connection value.
59      */
60     public int getMaxConnections() {
61         return maxConnections;
62     }
63
64     /**
65      * @return the maximum connection per route value.
66      */
67     public int getMaxConnectionsPerRoute() {
68         return maxConnectionsPerRoute;
69     }
70
71     /**
72      * @return the connect time out value in milliseconds.
73      */
74     public int getConnectionTimeOutInMilliSeconds() {
75         return (int) TimeUnit.SECONDS.toMillis(connectionTimeOutInSeconds);
76     }
77
78     /**
79      * @return the connection time to live value in mintues.
80      */
81     public int getTimeToLiveInMins() {
82         return (int) TimeUnit.SECONDS.toMinutes(timeToLiveInSeconds);
83     }
84
85 }