Skip to content

Commit 7aaa5dc

Browse files
chore(internal): codegen related update (#224)
1 parent 310e6dc commit 7aaa5dc

347 files changed

Lines changed: 46622 additions & 4800 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
171171
@JvmStatic fun builder() = Builder()
172172
}
173173

174-
class Builder {
174+
class Builder internal constructor() {
175175

176176
private var baseUrl: HttpUrl? = null
177177
// The default timeout is 1 minute.

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class OrbOkHttpClient private constructor() {
2222
@JvmStatic fun fromEnv(): OrbClient = builder().fromEnv().build()
2323
}
2424

25-
class Builder {
25+
/** A builder for [OrbOkHttpClient]. */
26+
class Builder internal constructor() {
2627

2728
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
2829
private var baseUrl: String = ClientOptions.PRODUCTION_URL

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class OrbOkHttpClientAsync private constructor() {
2222
@JvmStatic fun fromEnv(): OrbClientAsync = builder().fromEnv().build()
2323
}
2424

25-
class Builder {
25+
/** A builder for [OrbOkHttpClientAsync]. */
26+
class Builder internal constructor() {
2627

2728
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
2829
private var baseUrl: String = ClientOptions.PRODUCTION_URL

orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,28 @@ import com.withorb.api.services.blocking.SubscriptionService
1818
import com.withorb.api.services.blocking.TopLevelService
1919
import com.withorb.api.services.blocking.WebhookService
2020

21+
/**
22+
* A client for interacting with the Orb REST API synchronously. You can also switch to asynchronous
23+
* execution via the [async] method.
24+
*
25+
* This client performs best when you create a single instance and reuse it for all interactions
26+
* with the REST API. This is because each client holds its own connection pool and thread pools.
27+
* Reusing connections and threads reduces latency and saves memory. The client also handles rate
28+
* limiting per client. This means that creating and using multiple instances at the same time will
29+
* not respect rate limits.
30+
*
31+
* The threads and connections that are held will be released automatically if they remain idle. But
32+
* if you are writing an application that needs to aggressively release unused resources, then you
33+
* may call [close].
34+
*/
2135
interface OrbClient {
2236

37+
/**
38+
* Returns a version of this client that uses asynchronous execution.
39+
*
40+
* The returned client shares its resources, like its connection pool and thread pools, with
41+
* this client.
42+
*/
2343
fun async(): OrbClientAsync
2444

2545
fun topLevel(): TopLevelService
@@ -46,9 +66,22 @@ interface OrbClient {
4666

4767
fun subscriptions(): SubscriptionService
4868

69+
fun webhooks(): WebhookService
70+
4971
fun alerts(): AlertService
5072

5173
fun dimensionalPriceGroups(): DimensionalPriceGroupService
5274

53-
fun webhooks(): WebhookService
75+
/**
76+
* Closes this client, relinquishing any underlying resources.
77+
*
78+
* This is purposefully not inherited from [AutoCloseable] because the client is long-lived and
79+
* usually should not be synchronously closed via try-with-resources.
80+
*
81+
* It's also usually not necessary to call this method at all. the default HTTP client
82+
* automatically releases threads and connections if they remain idle, but if you are writing an
83+
* application that needs to aggressively release unused resources, then you may call this
84+
* method.
85+
*/
86+
fun close()
5487
}

orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,28 @@ import com.withorb.api.services.async.PriceServiceAsync
1717
import com.withorb.api.services.async.SubscriptionServiceAsync
1818
import com.withorb.api.services.async.TopLevelServiceAsync
1919

20+
/**
21+
* A client for interacting with the Orb REST API asynchronously. You can also switch to synchronous
22+
* execution via the [sync] method.
23+
*
24+
* This client performs best when you create a single instance and reuse it for all interactions
25+
* with the REST API. This is because each client holds its own connection pool and thread pools.
26+
* Reusing connections and threads reduces latency and saves memory. The client also handles rate
27+
* limiting per client. This means that creating and using multiple instances at the same time will
28+
* not respect rate limits.
29+
*
30+
* The threads and connections that are held will be released automatically if they remain idle. But
31+
* if you are writing an application that needs to aggressively release unused resources, then you
32+
* may call [close].
33+
*/
2034
interface OrbClientAsync {
2135

36+
/**
37+
* Returns a version of this client that uses synchronous execution.
38+
*
39+
* The returned client shares its resources, like its connection pool and thread pools, with
40+
* this client.
41+
*/
2242
fun sync(): OrbClient
2343

2444
fun topLevel(): TopLevelServiceAsync
@@ -48,4 +68,17 @@ interface OrbClientAsync {
4868
fun alerts(): AlertServiceAsync
4969

5070
fun dimensionalPriceGroups(): DimensionalPriceGroupServiceAsync
71+
72+
/**
73+
* Closes this client, relinquishing any underlying resources.
74+
*
75+
* This is purposefully not inherited from [AutoCloseable] because the client is long-lived and
76+
* usually should not be synchronously closed via try-with-resources.
77+
*
78+
* It's also usually not necessary to call this method at all. the default HTTP client
79+
* automatically releases threads and connections if they remain idle, but if you are writing an
80+
* application that needs to aggressively release unused resources, then you may call this
81+
* method.
82+
*/
83+
fun close()
5184
}

orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import com.withorb.api.services.async.SubscriptionServiceAsyncImpl
3333
import com.withorb.api.services.async.TopLevelServiceAsync
3434
import com.withorb.api.services.async.TopLevelServiceAsyncImpl
3535

36-
class OrbClientAsyncImpl
37-
constructor(
36+
class OrbClientAsyncImpl(
3837
private val clientOptions: ClientOptions,
3938
) : OrbClientAsync {
4039

@@ -131,4 +130,6 @@ constructor(
131130

132131
override fun dimensionalPriceGroups(): DimensionalPriceGroupServiceAsync =
133132
dimensionalPriceGroups
133+
134+
override fun close() = clientOptions.httpClient.close()
134135
}

orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import com.withorb.api.services.blocking.TopLevelServiceImpl
3535
import com.withorb.api.services.blocking.WebhookService
3636
import com.withorb.api.services.blocking.WebhookServiceImpl
3737

38-
class OrbClientImpl
39-
constructor(
38+
class OrbClientImpl(
4039
private val clientOptions: ClientOptions,
4140
) : OrbClient {
4241

@@ -119,9 +118,11 @@ constructor(
119118

120119
override fun subscriptions(): SubscriptionService = subscriptions
121120

121+
override fun webhooks(): WebhookService = webhooks
122+
122123
override fun alerts(): AlertService = alerts
123124

124125
override fun dimensionalPriceGroups(): DimensionalPriceGroupService = dimensionalPriceGroups
125126

126-
override fun webhooks(): WebhookService = webhooks
127+
override fun close() = clientOptions.httpClient.close()
127128
}

orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ private constructor(
3737
@JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build()
3838
}
3939

40-
class Builder {
40+
/** A builder for [ClientOptions]. */
41+
class Builder internal constructor() {
4142

4243
private var httpClient: HttpClient? = null
4344
private var jsonMapper: JsonMapper = jsonMapper()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.withorb.api.core
2+
3+
import com.withorb.api.core.http.Headers
4+
import com.withorb.api.core.http.QueryParams
5+
6+
/** An interface representing parameters passed to a service method. */
7+
interface Params {
8+
/** The full set of headers in the parameters, including both fixed and additional headers. */
9+
fun _headers(): Headers
10+
11+
/**
12+
* The full set of query params in the parameters, including both fixed and additional query
13+
* params.
14+
*/
15+
fun _queryParams(): QueryParams
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@file:JvmName("PrepareRequest")
2+
3+
package com.withorb.api.core
4+
5+
import com.withorb.api.core.http.HttpRequest
6+
import java.util.concurrent.CompletableFuture
7+
8+
@JvmSynthetic
9+
internal fun HttpRequest.prepare(clientOptions: ClientOptions, params: Params): HttpRequest =
10+
toBuilder()
11+
.putAllQueryParams(clientOptions.queryParams)
12+
.replaceAllQueryParams(params._queryParams())
13+
.putAllHeaders(clientOptions.headers)
14+
.replaceAllHeaders(params._headers())
15+
.build()
16+
17+
@JvmSynthetic
18+
internal fun HttpRequest.prepareAsync(
19+
clientOptions: ClientOptions,
20+
params: Params
21+
): CompletableFuture<HttpRequest> =
22+
// This async version exists to make it easier to add async specific preparation logic in the
23+
// future.
24+
CompletableFuture.completedFuture(prepare(clientOptions, params))

0 commit comments

Comments
 (0)