Skip to content

Commit f5422b7

Browse files
chore(internal): codegen related update
1 parent fc6f1e3 commit f5422b7

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

terminal-java-client-okhttp/src/main/kotlin/shop/terminal/api/client/okhttp/OkHttpClient.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import java.net.Proxy
66
import java.time.Duration
77
import java.util.concurrent.CancellationException
88
import java.util.concurrent.CompletableFuture
9+
import java.util.concurrent.ExecutorService
910
import javax.net.ssl.HostnameVerifier
1011
import javax.net.ssl.SSLSocketFactory
1112
import javax.net.ssl.X509TrustManager
1213
import okhttp3.Call
1314
import okhttp3.Callback
15+
import okhttp3.Dispatcher
1416
import okhttp3.HttpUrl.Companion.toHttpUrl
1517
import okhttp3.MediaType
1618
import okhttp3.MediaType.Companion.toMediaType
@@ -198,6 +200,7 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
198200

199201
private var timeout: Timeout = Timeout.default()
200202
private var proxy: Proxy? = null
203+
private var dispatcherExecutorService: ExecutorService? = null
201204
private var sslSocketFactory: SSLSocketFactory? = null
202205
private var trustManager: X509TrustManager? = null
203206
private var hostnameVerifier: HostnameVerifier? = null
@@ -208,6 +211,10 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
208211

209212
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
210213

214+
fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply {
215+
this.dispatcherExecutorService = dispatcherExecutorService
216+
}
217+
211218
fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply {
212219
this.sslSocketFactory = sslSocketFactory
213220
}
@@ -229,6 +236,8 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
229236
.callTimeout(timeout.request())
230237
.proxy(proxy)
231238
.apply {
239+
dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) }
240+
232241
val sslSocketFactory = sslSocketFactory
233242
val trustManager = trustManager
234243
if (sslSocketFactory != null && trustManager != null) {

terminal-java-client-okhttp/src/main/kotlin/shop/terminal/api/client/okhttp/TerminalOkHttpClient.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.net.Proxy
77
import java.time.Clock
88
import java.time.Duration
99
import java.util.Optional
10+
import java.util.concurrent.ExecutorService
1011
import javax.net.ssl.HostnameVerifier
1112
import javax.net.ssl.SSLSocketFactory
1213
import javax.net.ssl.X509TrustManager
@@ -44,11 +45,31 @@ class TerminalOkHttpClient private constructor() {
4445
class Builder internal constructor() {
4546

4647
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
48+
private var dispatcherExecutorService: ExecutorService? = null
4749
private var proxy: Proxy? = null
4850
private var sslSocketFactory: SSLSocketFactory? = null
4951
private var trustManager: X509TrustManager? = null
5052
private var hostnameVerifier: HostnameVerifier? = null
5153

54+
/**
55+
* The executor service to use for running HTTP requests.
56+
*
57+
* Defaults to OkHttp's
58+
* [default executor service](https://github.com/square/okhttp/blob/ace792f443b2ffb17974f5c0d1cecdf589309f26/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Dispatcher.kt#L98-L104).
59+
*
60+
* This class takes ownership of the executor service and shuts it down when closed.
61+
*/
62+
fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply {
63+
this.dispatcherExecutorService = dispatcherExecutorService
64+
}
65+
66+
/**
67+
* Alias for calling [Builder.dispatcherExecutorService] with
68+
* `dispatcherExecutorService.orElse(null)`.
69+
*/
70+
fun dispatcherExecutorService(dispatcherExecutorService: Optional<ExecutorService>) =
71+
dispatcherExecutorService(dispatcherExecutorService.getOrNull())
72+
5273
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
5374

5475
/** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
@@ -307,6 +328,7 @@ class TerminalOkHttpClient private constructor() {
307328
OkHttpClient.builder()
308329
.timeout(clientOptions.timeout())
309330
.proxy(proxy)
331+
.dispatcherExecutorService(dispatcherExecutorService)
310332
.sslSocketFactory(sslSocketFactory)
311333
.trustManager(trustManager)
312334
.hostnameVerifier(hostnameVerifier)

terminal-java-client-okhttp/src/main/kotlin/shop/terminal/api/client/okhttp/TerminalOkHttpClientAsync.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.net.Proxy
77
import java.time.Clock
88
import java.time.Duration
99
import java.util.Optional
10+
import java.util.concurrent.ExecutorService
1011
import javax.net.ssl.HostnameVerifier
1112
import javax.net.ssl.SSLSocketFactory
1213
import javax.net.ssl.X509TrustManager
@@ -44,11 +45,31 @@ class TerminalOkHttpClientAsync private constructor() {
4445
class Builder internal constructor() {
4546

4647
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
48+
private var dispatcherExecutorService: ExecutorService? = null
4749
private var proxy: Proxy? = null
4850
private var sslSocketFactory: SSLSocketFactory? = null
4951
private var trustManager: X509TrustManager? = null
5052
private var hostnameVerifier: HostnameVerifier? = null
5153

54+
/**
55+
* The executor service to use for running HTTP requests.
56+
*
57+
* Defaults to OkHttp's
58+
* [default executor service](https://github.com/square/okhttp/blob/ace792f443b2ffb17974f5c0d1cecdf589309f26/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Dispatcher.kt#L98-L104).
59+
*
60+
* This class takes ownership of the executor service and shuts it down when closed.
61+
*/
62+
fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply {
63+
this.dispatcherExecutorService = dispatcherExecutorService
64+
}
65+
66+
/**
67+
* Alias for calling [Builder.dispatcherExecutorService] with
68+
* `dispatcherExecutorService.orElse(null)`.
69+
*/
70+
fun dispatcherExecutorService(dispatcherExecutorService: Optional<ExecutorService>) =
71+
dispatcherExecutorService(dispatcherExecutorService.getOrNull())
72+
5273
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
5374

5475
/** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
@@ -307,6 +328,7 @@ class TerminalOkHttpClientAsync private constructor() {
307328
OkHttpClient.builder()
308329
.timeout(clientOptions.timeout())
309330
.proxy(proxy)
331+
.dispatcherExecutorService(dispatcherExecutorService)
310332
.sslSocketFactory(sslSocketFactory)
311333
.trustManager(trustManager)
312334
.hostnameVerifier(hostnameVerifier)

0 commit comments

Comments
 (0)