Skip to content

Commit 2e02604

Browse files
Merge pull request #109 from OneBusAway/release-please--branches--main--changes--next
release: 0.1.0-alpha.53
2 parents 38d7082 + aba1226 commit 2e02604

7 files changed

Lines changed: 170 additions & 8 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0-alpha.52"
2+
".": "0.1.0-alpha.53"
33
}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 0.1.0-alpha.53 (2026-02-19)
4+
5+
Full Changelog: [v0.1.0-alpha.52...v0.1.0-alpha.53](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.52...v0.1.0-alpha.53)
6+
7+
### Features
8+
9+
* **client:** add connection pooling option ([9dcb580](https://github.com/OneBusAway/java-sdk/commit/9dcb580bc844c9f90296c4e4a2a8c2c53b70bb95))
10+
11+
12+
### Chores
13+
14+
* **internal:** make `OkHttp` constructor internal ([ac8f1c2](https://github.com/OneBusAway/java-sdk/commit/ac8f1c28e6ec0a636fa725bd9f033703388b3282))
15+
316
## 0.1.0-alpha.52 (2026-02-18)
417

518
Full Changelog: [v0.1.0-alpha.51...v0.1.0-alpha.52](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.51...v0.1.0-alpha.52)

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<!-- x-release-please-start-version -->
44

5-
[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.52)
6-
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.52/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.52)
5+
[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.53)
6+
[![javadoc](https://javadoc.io/badge2/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.53/javadoc.svg)](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.53)
77

88
<!-- x-release-please-end -->
99

@@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/).
1515

1616
<!-- x-release-please-start-version -->
1717

18-
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.52).
18+
The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). Javadocs are available on [javadoc.io](https://javadoc.io/doc/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.53).
1919

2020
<!-- x-release-please-end -->
2121

@@ -26,7 +26,7 @@ The REST API documentation can be found on [developer.onebusaway.org](https://de
2626
### Gradle
2727

2828
```kotlin
29-
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.52")
29+
implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.53")
3030
```
3131

3232
### Maven
@@ -35,7 +35,7 @@ implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.52")
3535
<dependency>
3636
<groupId>org.onebusaway</groupId>
3737
<artifactId>onebusaway-sdk-java</artifactId>
38-
<version>0.1.0-alpha.52</version>
38+
<version>0.1.0-alpha.53</version>
3939
</dependency>
4040
```
4141

@@ -335,6 +335,25 @@ OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder()
335335
.build();
336336
```
337337

338+
### Connection pooling
339+
340+
To customize the underlying OkHttp connection pool, configure the client using the `maxIdleConnections` and `keepAliveDuration` methods:
341+
342+
```java
343+
import java.time.Duration;
344+
import org.onebusaway.client.OnebusawaySdkClient;
345+
import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient;
346+
347+
OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder()
348+
.fromEnv()
349+
// If `maxIdleConnections` is set, then `keepAliveDuration` must be set, and vice versa.
350+
.maxIdleConnections(10)
351+
.keepAliveDuration(Duration.ofMinutes(2))
352+
.build();
353+
```
354+
355+
If both options are unset, OkHttp's default connection pool settings are used.
356+
338357
### HTTPS
339358

340359
> [!NOTE]

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repositories {
88

99
allprojects {
1010
group = "org.onebusaway"
11-
version = "0.1.0-alpha.52" // x-release-please-version
11+
version = "0.1.0-alpha.53" // x-release-please-version
1212
}
1313

1414
subprojects {

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import java.time.Duration
77
import java.util.concurrent.CancellationException
88
import java.util.concurrent.CompletableFuture
99
import java.util.concurrent.ExecutorService
10+
import java.util.concurrent.TimeUnit
1011
import javax.net.ssl.HostnameVerifier
1112
import javax.net.ssl.SSLSocketFactory
1213
import javax.net.ssl.X509TrustManager
1314
import okhttp3.Call
1415
import okhttp3.Callback
16+
import okhttp3.ConnectionPool
1517
import okhttp3.Dispatcher
1618
import okhttp3.HttpUrl.Companion.toHttpUrl
1719
import okhttp3.Interceptor
@@ -34,7 +36,7 @@ import org.onebusaway.core.http.HttpResponse
3436
import org.onebusaway.errors.OnebusawaySdkIoException
3537

3638
class OkHttpClient
37-
private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient {
39+
internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient {
3840

3941
override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
4042
val call = newCall(request, requestOptions)
@@ -202,6 +204,8 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
202204

203205
private var timeout: Timeout = Timeout.default()
204206
private var proxy: Proxy? = null
207+
private var maxIdleConnections: Int? = null
208+
private var keepAliveDuration: Duration? = null
205209
private var dispatcherExecutorService: ExecutorService? = null
206210
private var sslSocketFactory: SSLSocketFactory? = null
207211
private var trustManager: X509TrustManager? = null
@@ -213,6 +217,28 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
213217

214218
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
215219

220+
/**
221+
* Sets the maximum number of idle connections kept by the underlying [ConnectionPool].
222+
*
223+
* If this is set, then [keepAliveDuration] must also be set.
224+
*
225+
* If unset, then OkHttp's default is used.
226+
*/
227+
fun maxIdleConnections(maxIdleConnections: Int?) = apply {
228+
this.maxIdleConnections = maxIdleConnections
229+
}
230+
231+
/**
232+
* Sets the keep-alive duration for idle connections in the underlying [ConnectionPool].
233+
*
234+
* If this is set, then [maxIdleConnections] must also be set.
235+
*
236+
* If unset, then OkHttp's default is used.
237+
*/
238+
fun keepAliveDuration(keepAliveDuration: Duration?) = apply {
239+
this.keepAliveDuration = keepAliveDuration
240+
}
241+
216242
fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply {
217243
this.dispatcherExecutorService = dispatcherExecutorService
218244
}
@@ -242,6 +268,22 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
242268
.apply {
243269
dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) }
244270

271+
val maxIdleConnections = maxIdleConnections
272+
val keepAliveDuration = keepAliveDuration
273+
if (maxIdleConnections != null && keepAliveDuration != null) {
274+
connectionPool(
275+
ConnectionPool(
276+
maxIdleConnections,
277+
keepAliveDuration.toNanos(),
278+
TimeUnit.NANOSECONDS,
279+
)
280+
)
281+
} else {
282+
check((maxIdleConnections != null) == (keepAliveDuration != null)) {
283+
"Both or none of `maxIdleConnections` and `keepAliveDuration` must be set, but only one was set"
284+
}
285+
}
286+
245287
val sslSocketFactory = sslSocketFactory
246288
val trustManager = trustManager
247289
if (sslSocketFactory != null && trustManager != null) {

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
4747
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
4848
private var dispatcherExecutorService: ExecutorService? = null
4949
private var proxy: Proxy? = null
50+
private var maxIdleConnections: Int? = null
51+
private var keepAliveDuration: Duration? = null
5052
private var sslSocketFactory: SSLSocketFactory? = null
5153
private var trustManager: X509TrustManager? = null
5254
private var hostnameVerifier: HostnameVerifier? = null
@@ -75,6 +77,46 @@ class OnebusawaySdkOkHttpClient private constructor() {
7577
/** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
7678
fun proxy(proxy: Optional<Proxy>) = proxy(proxy.getOrNull())
7779

80+
/**
81+
* The maximum number of idle connections kept by the underlying OkHttp connection pool.
82+
*
83+
* If this is set, then [keepAliveDuration] must also be set.
84+
*
85+
* If unset, then OkHttp's default is used.
86+
*/
87+
fun maxIdleConnections(maxIdleConnections: Int?) = apply {
88+
this.maxIdleConnections = maxIdleConnections
89+
}
90+
91+
/**
92+
* Alias for [Builder.maxIdleConnections].
93+
*
94+
* This unboxed primitive overload exists for backwards compatibility.
95+
*/
96+
fun maxIdleConnections(maxIdleConnections: Int) =
97+
maxIdleConnections(maxIdleConnections as Int?)
98+
99+
/**
100+
* Alias for calling [Builder.maxIdleConnections] with `maxIdleConnections.orElse(null)`.
101+
*/
102+
fun maxIdleConnections(maxIdleConnections: Optional<Int>) =
103+
maxIdleConnections(maxIdleConnections.getOrNull())
104+
105+
/**
106+
* The keep-alive duration for idle connections in the underlying OkHttp connection pool.
107+
*
108+
* If this is set, then [maxIdleConnections] must also be set.
109+
*
110+
* If unset, then OkHttp's default is used.
111+
*/
112+
fun keepAliveDuration(keepAliveDuration: Duration?) = apply {
113+
this.keepAliveDuration = keepAliveDuration
114+
}
115+
116+
/** Alias for calling [Builder.keepAliveDuration] with `keepAliveDuration.orElse(null)`. */
117+
fun keepAliveDuration(keepAliveDuration: Optional<Duration>) =
118+
keepAliveDuration(keepAliveDuration.getOrNull())
119+
78120
/**
79121
* The socket factory used to secure HTTPS connections.
80122
*
@@ -317,6 +359,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
317359
OkHttpClient.builder()
318360
.timeout(clientOptions.timeout())
319361
.proxy(proxy)
362+
.maxIdleConnections(maxIdleConnections)
363+
.keepAliveDuration(keepAliveDuration)
320364
.dispatcherExecutorService(dispatcherExecutorService)
321365
.sslSocketFactory(sslSocketFactory)
322366
.trustManager(trustManager)

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
4747
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
4848
private var dispatcherExecutorService: ExecutorService? = null
4949
private var proxy: Proxy? = null
50+
private var maxIdleConnections: Int? = null
51+
private var keepAliveDuration: Duration? = null
5052
private var sslSocketFactory: SSLSocketFactory? = null
5153
private var trustManager: X509TrustManager? = null
5254
private var hostnameVerifier: HostnameVerifier? = null
@@ -75,6 +77,46 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
7577
/** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
7678
fun proxy(proxy: Optional<Proxy>) = proxy(proxy.getOrNull())
7779

80+
/**
81+
* The maximum number of idle connections kept by the underlying OkHttp connection pool.
82+
*
83+
* If this is set, then [keepAliveDuration] must also be set.
84+
*
85+
* If unset, then OkHttp's default is used.
86+
*/
87+
fun maxIdleConnections(maxIdleConnections: Int?) = apply {
88+
this.maxIdleConnections = maxIdleConnections
89+
}
90+
91+
/**
92+
* Alias for [Builder.maxIdleConnections].
93+
*
94+
* This unboxed primitive overload exists for backwards compatibility.
95+
*/
96+
fun maxIdleConnections(maxIdleConnections: Int) =
97+
maxIdleConnections(maxIdleConnections as Int?)
98+
99+
/**
100+
* Alias for calling [Builder.maxIdleConnections] with `maxIdleConnections.orElse(null)`.
101+
*/
102+
fun maxIdleConnections(maxIdleConnections: Optional<Int>) =
103+
maxIdleConnections(maxIdleConnections.getOrNull())
104+
105+
/**
106+
* The keep-alive duration for idle connections in the underlying OkHttp connection pool.
107+
*
108+
* If this is set, then [maxIdleConnections] must also be set.
109+
*
110+
* If unset, then OkHttp's default is used.
111+
*/
112+
fun keepAliveDuration(keepAliveDuration: Duration?) = apply {
113+
this.keepAliveDuration = keepAliveDuration
114+
}
115+
116+
/** Alias for calling [Builder.keepAliveDuration] with `keepAliveDuration.orElse(null)`. */
117+
fun keepAliveDuration(keepAliveDuration: Optional<Duration>) =
118+
keepAliveDuration(keepAliveDuration.getOrNull())
119+
78120
/**
79121
* The socket factory used to secure HTTPS connections.
80122
*
@@ -317,6 +359,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
317359
OkHttpClient.builder()
318360
.timeout(clientOptions.timeout())
319361
.proxy(proxy)
362+
.maxIdleConnections(maxIdleConnections)
363+
.keepAliveDuration(keepAliveDuration)
320364
.dispatcherExecutorService(dispatcherExecutorService)
321365
.sslSocketFactory(sslSocketFactory)
322366
.trustManager(trustManager)

0 commit comments

Comments
 (0)