Skip to content

Commit 7fbdf02

Browse files
committed
Inject configurable properties
1 parent c494a30 commit 7fbdf02

5 files changed

Lines changed: 128 additions & 12 deletions

File tree

gbfs-validator-java-api/src/main/java/org/entur/gbfs/validator/api/handler/LoaderConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@
2828
public class LoaderConfiguration {
2929

3030
@Bean
31-
public Loader loader() {
32-
return new Loader();
31+
public Loader loader(LoaderProperties properties) {
32+
return new Loader(
33+
properties.getHttp().getMaxTotalConnections(),
34+
properties.getHttp().getMaxConnectionsPerRoute(),
35+
properties.getHttp().getConnectTimeoutSeconds(),
36+
properties.getHttp().getResponseTimeoutSeconds(),
37+
properties.getThreadPool().getSize()
38+
);
3339
}
3440
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
*
3+
* *
4+
* *
5+
* * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
6+
* * * the European Commission - subsequent versions of the EUPL (the "Licence");
7+
* * * You may not use this work except in compliance with the Licence.
8+
* * * You may obtain a copy of the Licence at:
9+
* * *
10+
* * * https://joinup.ec.europa.eu/software/page/eupl
11+
* * *
12+
* * * Unless required by applicable law or agreed to in writing, software
13+
* * * distributed under the Licence is distributed on an "AS IS" basis,
14+
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * * See the Licence for the specific language governing permissions and
16+
* * * limitations under the Licence.
17+
* *
18+
*
19+
*/
20+
21+
package org.entur.gbfs.validator.api.handler;
22+
23+
import org.springframework.boot.context.properties.ConfigurationProperties;
24+
import org.springframework.stereotype.Component;
25+
26+
@Component
27+
@ConfigurationProperties(prefix = "loader")
28+
public class LoaderProperties {
29+
30+
private Http http = new Http();
31+
private ThreadPool threadPool = new ThreadPool();
32+
33+
public Http getHttp() {
34+
return http;
35+
}
36+
37+
public void setHttp(Http http) {
38+
this.http = http;
39+
}
40+
41+
public ThreadPool getThreadPool() {
42+
return threadPool;
43+
}
44+
45+
public void setThreadPool(ThreadPool threadPool) {
46+
this.threadPool = threadPool;
47+
}
48+
49+
public static class Http {
50+
private int maxTotalConnections = 50;
51+
private int maxConnectionsPerRoute = 20;
52+
private int connectTimeoutSeconds = 5;
53+
private int responseTimeoutSeconds = 5;
54+
55+
public int getMaxTotalConnections() {
56+
return maxTotalConnections;
57+
}
58+
59+
public void setMaxTotalConnections(int maxTotalConnections) {
60+
this.maxTotalConnections = maxTotalConnections;
61+
}
62+
63+
public int getMaxConnectionsPerRoute() {
64+
return maxConnectionsPerRoute;
65+
}
66+
67+
public void setMaxConnectionsPerRoute(int maxConnectionsPerRoute) {
68+
this.maxConnectionsPerRoute = maxConnectionsPerRoute;
69+
}
70+
71+
public int getConnectTimeoutSeconds() {
72+
return connectTimeoutSeconds;
73+
}
74+
75+
public void setConnectTimeoutSeconds(int connectTimeoutSeconds) {
76+
this.connectTimeoutSeconds = connectTimeoutSeconds;
77+
}
78+
79+
public int getResponseTimeoutSeconds() {
80+
return responseTimeoutSeconds;
81+
}
82+
83+
public void setResponseTimeoutSeconds(int responseTimeoutSeconds) {
84+
this.responseTimeoutSeconds = responseTimeoutSeconds;
85+
}
86+
}
87+
88+
public static class ThreadPool {
89+
private int size = 20;
90+
91+
public int getSize() {
92+
return size;
93+
}
94+
95+
public void setSize(int size) {
96+
this.size = size;
97+
}
98+
}
99+
}

gbfs-validator-java-api/src/main/java/org/entur/gbfs/validator/api/handler/ValidateApiDelegateHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ValidateApiDelegateHandler implements ValidateApiDelegate {
6262
private static final Logger logger = LoggerFactory.getLogger(ValidateApiDelegateHandler.class);
6363

6464
private final Loader loader;
65-
65+
6666
public ValidateApiDelegateHandler(Loader loader) {
6767
this.loader = loader;
6868
}

gbfs-validator-java-api/src/main/resources/application.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ spring.application.name=gbfs-validator-java-api
33
logging.level.org.entur.gbfs.validator.api.handler.ValidateApiDelegateHandler=DEBUG
44
server.compression.enabled=true
55
server.compression.min-response-size=1024
6+
7+
# Loader HTTP client configuration
8+
loader.http.max-total-connections=50
9+
loader.http.max-connections-per-route=20
10+
loader.http.connect-timeout-seconds=5
11+
loader.http.response-timeout-seconds=5
12+
13+
# Loader thread pool configuration
14+
loader.thread-pool.size=20

gbfs-validator-java-loader/src/main/java/org/entur/gbfs/validator/loader/Loader.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,23 @@ private String getFileName(URI uri) {
7070
}
7171

7272
public Loader() {
73+
this(50, 20, 5, 5, 20);
74+
}
75+
76+
public Loader(int maxTotalConnections, int maxConnectionsPerRoute,
77+
int connectTimeoutSeconds, int responseTimeoutSeconds,
78+
int threadPoolSize) {
7379
// Create connection pool manager
7480
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
7581
// Set the maximum number of total connections
76-
// TODO configurable max total
77-
connectionManager.setMaxTotal(50);
82+
connectionManager.setMaxTotal(maxTotalConnections);
7883
// Set the maximum number of connections per route
79-
// TODO configurable max per route
80-
connectionManager.setDefaultMaxPerRoute(20);
84+
connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
8185

8286
// Configure request timeouts
8387
RequestConfig requestConfig = RequestConfig.custom()
84-
// TODO configurable timeouts
85-
.setConnectTimeout(Timeout.of(5, TimeUnit.SECONDS))
86-
.setResponseTimeout(Timeout.of(5, TimeUnit.SECONDS))
88+
.setConnectTimeout(Timeout.of(connectTimeoutSeconds, TimeUnit.SECONDS))
89+
.setResponseTimeout(Timeout.of(responseTimeoutSeconds, TimeUnit.SECONDS))
8790
.build();
8891

8992
// Build the HttpClient with connection pooling
@@ -93,8 +96,7 @@ public Loader() {
9396
.build();
9497

9598
// Create a thread pool for parallel execution
96-
// TODO configurable pool size
97-
executorService = Executors.newFixedThreadPool(20);
99+
executorService = Executors.newFixedThreadPool(threadPoolSize);
98100
}
99101

100102
public List<LoadedFile> load(String discoveryURIString) throws IOException {

0 commit comments

Comments
 (0)