Skip to content

Commit 0fac99b

Browse files
docs: more code comments
1 parent cc42cf6 commit 0fac99b

File tree

120 files changed

+517
-4
lines changed

Some content is hidden

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

120 files changed

+517
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t
376376

377377
### Retries
378378

379-
The SDK automatically retries 2 times by default, with a short exponential backoff.
379+
The SDK automatically retries 2 times by default, with a short exponential backoff between requests.
380380

381381
Only the following error types are retried:
382382

@@ -386,7 +386,7 @@ Only the following error types are retried:
386386
- 429 Rate Limit
387387
- 5xx Internal
388388

389-
The API may also explicitly instruct the SDK to retry or not retry a response.
389+
The API may also explicitly instruct the SDK to retry or not retry a request.
390390

391391
To set a custom number of retries, configure the client using the `maxRetries` method:
392392

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import com.withorb.api.client.OrbClient
77
import com.withorb.api.client.OrbClientImpl
88
import com.withorb.api.core.ClientOptions
99
import com.withorb.api.core.Timeout
10+
import com.withorb.api.core.http.AsyncStreamResponse
1011
import com.withorb.api.core.http.Headers
12+
import com.withorb.api.core.http.HttpClient
1113
import com.withorb.api.core.http.QueryParams
1214
import com.withorb.api.core.jsonMapper
1315
import java.net.Proxy
@@ -20,13 +22,22 @@ import javax.net.ssl.SSLSocketFactory
2022
import javax.net.ssl.X509TrustManager
2123
import kotlin.jvm.optionals.getOrNull
2224

25+
/**
26+
* A class that allows building an instance of [OrbClient] with [OkHttpClient] as the underlying
27+
* [HttpClient].
28+
*/
2329
class OrbOkHttpClient private constructor() {
2430

2531
companion object {
2632

27-
/** Returns a mutable builder for constructing an instance of [OrbOkHttpClient]. */
33+
/** Returns a mutable builder for constructing an instance of [OrbClient]. */
2834
@JvmStatic fun builder() = Builder()
2935

36+
/**
37+
* Returns a client configured using system properties and environment variables.
38+
*
39+
* @see ClientOptions.Builder.fromEnv
40+
*/
3041
@JvmStatic fun fromEnv(): OrbClient = builder().fromEnv().build()
3142
}
3243

@@ -103,23 +114,58 @@ class OrbOkHttpClient private constructor() {
103114
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
104115
}
105116

117+
/**
118+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
119+
*
120+
* Defaults to [com.withorb.api.core.jsonMapper]. The default is usually sufficient and
121+
* rarely needs to be overridden.
122+
*/
106123
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
107124

125+
/**
126+
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127+
*
128+
* Defaults to a dedicated cached thread pool.
129+
*/
108130
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
109131
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
110132
}
111133

134+
/**
135+
* The clock to use for operations that require timing, like retries.
136+
*
137+
* This is primarily useful for using a fake clock in tests.
138+
*
139+
* Defaults to [Clock.systemUTC].
140+
*/
112141
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
113142

143+
/**
144+
* The base URL to use for every request.
145+
*
146+
* Defaults to the production environment: `https://api.withorb.com/v1`.
147+
*/
114148
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
115149

116150
/** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
117151
fun baseUrl(baseUrl: Optional<String>) = baseUrl(baseUrl.getOrNull())
118152

153+
/**
154+
* Whether to call `validate` on every response before returning it.
155+
*
156+
* Defaults to false, which means the shape of the response will not be validated upfront.
157+
* Instead, validation will only occur for the parts of the response that are accessed.
158+
*/
119159
fun responseValidation(responseValidation: Boolean) = apply {
120160
clientOptions.responseValidation(responseValidation)
121161
}
122162

163+
/**
164+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
165+
* retries.
166+
*
167+
* Defaults to [Timeout.default].
168+
*/
123169
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
124170

125171
/**
@@ -131,6 +177,21 @@ class OrbOkHttpClient private constructor() {
131177
*/
132178
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
133179

180+
/**
181+
* The maximum number of times to retry failed requests, with a short exponential backoff
182+
* between requests.
183+
*
184+
* Only the following error types are retried:
185+
* - Connection errors (for example, due to a network connectivity problem)
186+
* - 408 Request Timeout
187+
* - 409 Conflict
188+
* - 429 Rate Limit
189+
* - 5xx Internal
190+
*
191+
* The API may also explicitly instruct the SDK to retry or not retry a request.
192+
*
193+
* Defaults to 2.
194+
*/
134195
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
135196

136197
fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) }
@@ -223,6 +284,11 @@ class OrbOkHttpClient private constructor() {
223284
clientOptions.removeAllQueryParams(keys)
224285
}
225286

287+
/**
288+
* Updates configuration using system properties and environment variables.
289+
*
290+
* @see ClientOptions.Builder.fromEnv
291+
*/
226292
fun fromEnv() = apply { clientOptions.fromEnv() }
227293

228294
/**

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import com.withorb.api.client.OrbClientAsync
77
import com.withorb.api.client.OrbClientAsyncImpl
88
import com.withorb.api.core.ClientOptions
99
import com.withorb.api.core.Timeout
10+
import com.withorb.api.core.http.AsyncStreamResponse
1011
import com.withorb.api.core.http.Headers
12+
import com.withorb.api.core.http.HttpClient
1113
import com.withorb.api.core.http.QueryParams
1214
import com.withorb.api.core.jsonMapper
1315
import java.net.Proxy
@@ -20,13 +22,22 @@ import javax.net.ssl.SSLSocketFactory
2022
import javax.net.ssl.X509TrustManager
2123
import kotlin.jvm.optionals.getOrNull
2224

25+
/**
26+
* A class that allows building an instance of [OrbClientAsync] with [OkHttpClient] as the
27+
* underlying [HttpClient].
28+
*/
2329
class OrbOkHttpClientAsync private constructor() {
2430

2531
companion object {
2632

27-
/** Returns a mutable builder for constructing an instance of [OrbOkHttpClientAsync]. */
33+
/** Returns a mutable builder for constructing an instance of [OrbClientAsync]. */
2834
@JvmStatic fun builder() = Builder()
2935

36+
/**
37+
* Returns a client configured using system properties and environment variables.
38+
*
39+
* @see ClientOptions.Builder.fromEnv
40+
*/
3041
@JvmStatic fun fromEnv(): OrbClientAsync = builder().fromEnv().build()
3142
}
3243

@@ -103,23 +114,58 @@ class OrbOkHttpClientAsync private constructor() {
103114
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
104115
}
105116

117+
/**
118+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
119+
*
120+
* Defaults to [com.withorb.api.core.jsonMapper]. The default is usually sufficient and
121+
* rarely needs to be overridden.
122+
*/
106123
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
107124

125+
/**
126+
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127+
*
128+
* Defaults to a dedicated cached thread pool.
129+
*/
108130
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
109131
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
110132
}
111133

134+
/**
135+
* The clock to use for operations that require timing, like retries.
136+
*
137+
* This is primarily useful for using a fake clock in tests.
138+
*
139+
* Defaults to [Clock.systemUTC].
140+
*/
112141
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
113142

143+
/**
144+
* The base URL to use for every request.
145+
*
146+
* Defaults to the production environment: `https://api.withorb.com/v1`.
147+
*/
114148
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
115149

116150
/** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
117151
fun baseUrl(baseUrl: Optional<String>) = baseUrl(baseUrl.getOrNull())
118152

153+
/**
154+
* Whether to call `validate` on every response before returning it.
155+
*
156+
* Defaults to false, which means the shape of the response will not be validated upfront.
157+
* Instead, validation will only occur for the parts of the response that are accessed.
158+
*/
119159
fun responseValidation(responseValidation: Boolean) = apply {
120160
clientOptions.responseValidation(responseValidation)
121161
}
122162

163+
/**
164+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
165+
* retries.
166+
*
167+
* Defaults to [Timeout.default].
168+
*/
123169
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
124170

125171
/**
@@ -131,6 +177,21 @@ class OrbOkHttpClientAsync private constructor() {
131177
*/
132178
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
133179

180+
/**
181+
* The maximum number of times to retry failed requests, with a short exponential backoff
182+
* between requests.
183+
*
184+
* Only the following error types are retried:
185+
* - Connection errors (for example, due to a network connectivity problem)
186+
* - 408 Request Timeout
187+
* - 409 Conflict
188+
* - 429 Rate Limit
189+
* - 5xx Internal
190+
*
191+
* The API may also explicitly instruct the SDK to retry or not retry a request.
192+
*
193+
* Defaults to 2.
194+
*/
134195
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
135196

136197
fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) }
@@ -223,6 +284,11 @@ class OrbOkHttpClientAsync private constructor() {
223284
clientOptions.removeAllQueryParams(keys)
224285
}
225286

287+
/**
288+
* Updates configuration using system properties and environment variables.
289+
*
290+
* @see ClientOptions.Builder.fromEnv
291+
*/
226292
fun fromEnv() = apply { clientOptions.fromEnv() }
227293

228294
/**

0 commit comments

Comments
 (0)