Skip to content

Commit e7e3c8d

Browse files
release: 7.5.2 (#556)
* chore(client): refactor closing / shutdown * chore(internal): support running formatters directly * release: 7.5.2 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 95a334a commit e7e3c8d

File tree

14 files changed

+153
-13
lines changed

14 files changed

+153
-13
lines changed

.release-please-manifest.json

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

CHANGELOG.md

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

3+
## 7.5.2 (2025-08-20)
4+
5+
Full Changelog: [v7.5.1...v7.5.2](https://github.com/Finch-API/finch-api-java/compare/v7.5.1...v7.5.2)
6+
7+
### Chores
8+
9+
* **client:** refactor closing / shutdown ([133f431](https://github.com/Finch-API/finch-api-java/commit/133f4314793c2b74f97970d257b1c9d25c9ed3de))
10+
* **internal:** support running formatters directly ([fb89e60](https://github.com/Finch-API/finch-api-java/commit/fb89e608a0822ba5122f9ea5e3fa0fa561b1f388))
11+
312
## 7.5.1 (2025-08-14)
413

514
Full Changelog: [v7.5.0...v7.5.1](https://github.com/Finch-API/finch-api-java/compare/v7.5.0...v7.5.1)

README.md

Lines changed: 5 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/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/7.5.1)
6-
[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/7.5.1/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.5.1)
5+
[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/7.5.2)
6+
[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/7.5.2/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.5.2)
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.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.5.1).
18+
The REST API documentation can be found on [developer.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.5.2).
1919

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

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

2828
```kotlin
29-
implementation("com.tryfinch.api:finch-java:7.5.1")
29+
implementation("com.tryfinch.api:finch-java:7.5.2")
3030
```
3131

3232
### Maven
@@ -35,7 +35,7 @@ implementation("com.tryfinch.api:finch-java:7.5.1")
3535
<dependency>
3636
<groupId>com.tryfinch.api</groupId>
3737
<artifactId>finch-java</artifactId>
38-
<version>7.5.1</version>
38+
<version>7.5.2</version>
3939
</dependency>
4040
```
4141

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 = "com.tryfinch.api"
11-
version = "7.5.1" // x-release-please-version
11+
version = "7.5.2" // x-release-please-version
1212
}
1313

1414
subprojects {

finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class FinchOkHttpClient private constructor() {
126126
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127127
*
128128
* Defaults to a dedicated cached thread pool.
129+
*
130+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
129131
*/
130132
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
131133
clientOptions.streamHandlerExecutor(streamHandlerExecutor)

finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class FinchOkHttpClientAsync private constructor() {
126126
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127127
*
128128
* Defaults to a dedicated cached thread pool.
129+
*
130+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
129131
*/
130132
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
131133
clientOptions.streamHandlerExecutor(streamHandlerExecutor)

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class FinchClientAsyncImpl(private val clientOptions: ClientOptions) : FinchClie
200200
@get:JsonProperty("provider_id") val providerId: String,
201201
)
202202

203-
override fun close() = clientOptions.httpClient.close()
203+
override fun close() = clientOptions.close()
204204

205205
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
206206
FinchClientAsync.WithRawResponse {

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class FinchClientImpl(private val clientOptions: ClientOptions) : FinchClient {
189189
@get:JsonProperty("provider_id") val providerId: String,
190190
)
191191

192-
override fun close() = clientOptions.httpClient.close()
192+
override fun close() = clientOptions.close()
193193

194194
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
195195
FinchClient.WithRawResponse {

finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.time.Duration
1414
import java.util.Base64
1515
import java.util.Optional
1616
import java.util.concurrent.Executor
17+
import java.util.concurrent.ExecutorService
1718
import java.util.concurrent.Executors
1819
import java.util.concurrent.ThreadFactory
1920
import java.util.concurrent.atomic.AtomicLong
@@ -27,6 +28,8 @@ private constructor(
2728
* The HTTP client to use in the SDK.
2829
*
2930
* Use the one published in `finch-java-client-okhttp` or implement your own.
31+
*
32+
* This class takes ownership of the client and closes it when closed.
3033
*/
3134
@get:JvmName("httpClient") val httpClient: HttpClient,
3235
/**
@@ -48,6 +51,8 @@ private constructor(
4851
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
4952
*
5053
* Defaults to a dedicated cached thread pool.
54+
*
55+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
5156
*/
5257
@get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor,
5358
/**
@@ -186,6 +191,8 @@ private constructor(
186191
* The HTTP client to use in the SDK.
187192
*
188193
* Use the one published in `finch-java-client-okhttp` or implement your own.
194+
*
195+
* This class takes ownership of the client and closes it when closed.
189196
*/
190197
fun httpClient(httpClient: HttpClient) = apply {
191198
this.httpClient = PhantomReachableClosingHttpClient(httpClient)
@@ -214,9 +221,14 @@ private constructor(
214221
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
215222
*
216223
* Defaults to a dedicated cached thread pool.
224+
*
225+
* This class takes ownership of the executor and shuts it down, if possible, when closed.
217226
*/
218227
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
219-
this.streamHandlerExecutor = streamHandlerExecutor
228+
this.streamHandlerExecutor =
229+
if (streamHandlerExecutor is ExecutorService)
230+
PhantomReachableExecutorService(streamHandlerExecutor)
231+
else streamHandlerExecutor
220232
}
221233

222234
/**
@@ -493,4 +505,19 @@ private constructor(
493505
)
494506
}
495507
}
508+
509+
/**
510+
* Closes these client options, relinquishing any underlying resources.
511+
*
512+
* This is purposefully not inherited from [AutoCloseable] because the client options are
513+
* long-lived and usually should not be synchronously closed via try-with-resources.
514+
*
515+
* It's also usually not necessary to call this method at all. the default client automatically
516+
* releases threads and connections if they remain idle, but if you are writing an application
517+
* that needs to aggressively release unused resources, then you may call this method.
518+
*/
519+
fun close() {
520+
httpClient.close()
521+
(streamHandlerExecutor as? ExecutorService)?.shutdown()
522+
}
496523
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.tryfinch.api.core
2+
3+
import java.util.concurrent.Callable
4+
import java.util.concurrent.ExecutorService
5+
import java.util.concurrent.Future
6+
import java.util.concurrent.TimeUnit
7+
8+
/**
9+
* A delegating wrapper around an [ExecutorService] that shuts it down once it's only phantom
10+
* reachable.
11+
*
12+
* This class ensures the [ExecutorService] is shut down even if the user forgets to do it.
13+
*/
14+
internal class PhantomReachableExecutorService(private val executorService: ExecutorService) :
15+
ExecutorService {
16+
init {
17+
closeWhenPhantomReachable(this) { executorService.shutdown() }
18+
}
19+
20+
override fun execute(command: Runnable) = executorService.execute(command)
21+
22+
override fun shutdown() = executorService.shutdown()
23+
24+
override fun shutdownNow(): MutableList<Runnable> = executorService.shutdownNow()
25+
26+
override fun isShutdown(): Boolean = executorService.isShutdown
27+
28+
override fun isTerminated(): Boolean = executorService.isTerminated
29+
30+
override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean =
31+
executorService.awaitTermination(timeout, unit)
32+
33+
override fun <T : Any?> submit(task: Callable<T>): Future<T> = executorService.submit(task)
34+
35+
override fun <T : Any?> submit(task: Runnable, result: T): Future<T> =
36+
executorService.submit(task, result)
37+
38+
override fun submit(task: Runnable): Future<*> = executorService.submit(task)
39+
40+
override fun <T : Any?> invokeAll(
41+
tasks: MutableCollection<out Callable<T>>
42+
): MutableList<Future<T>> = executorService.invokeAll(tasks)
43+
44+
override fun <T : Any?> invokeAll(
45+
tasks: MutableCollection<out Callable<T>>,
46+
timeout: Long,
47+
unit: TimeUnit,
48+
): MutableList<Future<T>> = executorService.invokeAll(tasks, timeout, unit)
49+
50+
override fun <T : Any?> invokeAny(tasks: MutableCollection<out Callable<T>>): T =
51+
executorService.invokeAny(tasks)
52+
53+
override fun <T : Any?> invokeAny(
54+
tasks: MutableCollection<out Callable<T>>,
55+
timeout: Long,
56+
unit: TimeUnit,
57+
): T = executorService.invokeAny(tasks, timeout, unit)
58+
}

0 commit comments

Comments
 (0)