Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
3eb00db
codegen metadata
stainless-app[bot] Feb 18, 2026
e300271
codegen metadata
stainless-app[bot] Feb 18, 2026
310204a
codegen metadata
stainless-app[bot] Feb 18, 2026
ab13da3
codegen metadata
stainless-app[bot] Feb 18, 2026
f575f93
codegen metadata
stainless-app[bot] Feb 18, 2026
699a9ab
codegen metadata
stainless-app[bot] Feb 18, 2026
75ee73b
codegen metadata
stainless-app[bot] Feb 18, 2026
24e34ef
codegen metadata
stainless-app[bot] Feb 18, 2026
c4b7231
codegen metadata
stainless-app[bot] Feb 19, 2026
5844adc
codegen metadata
stainless-app[bot] Feb 19, 2026
e4137df
codegen metadata
stainless-app[bot] Feb 19, 2026
41aa28e
codegen metadata
stainless-app[bot] Feb 19, 2026
7d47bdf
codegen metadata
stainless-app[bot] Feb 19, 2026
6895361
codegen metadata
stainless-app[bot] Feb 19, 2026
d3ea058
codegen metadata
stainless-app[bot] Feb 19, 2026
17843ee
codegen metadata
stainless-app[bot] Feb 19, 2026
2de6a82
codegen metadata
stainless-app[bot] Feb 19, 2026
6389eb0
chore(internal): make `OkHttp` constructor internal
stainless-app[bot] Feb 19, 2026
7d04245
feat(client): add connection pooling option
stainless-app[bot] Feb 19, 2026
97860e9
codegen metadata
stainless-app[bot] Feb 19, 2026
87b2388
codegen metadata
stainless-app[bot] Feb 19, 2026
21e0ea0
codegen metadata
stainless-app[bot] Feb 19, 2026
34b1918
codegen metadata
stainless-app[bot] Feb 19, 2026
bfd0467
codegen metadata
stainless-app[bot] Feb 19, 2026
7f5bf68
codegen metadata
stainless-app[bot] Feb 19, 2026
70ff296
codegen metadata
stainless-app[bot] Feb 19, 2026
46b4a32
codegen metadata
stainless-app[bot] Feb 19, 2026
35a2a97
codegen metadata
stainless-app[bot] Feb 19, 2026
d8583ac
codegen metadata
stainless-app[bot] Feb 19, 2026
0ba3098
codegen metadata
stainless-app[bot] Feb 20, 2026
2b20e32
codegen metadata
stainless-app[bot] Feb 20, 2026
e272c1d
codegen metadata
stainless-app[bot] Feb 20, 2026
3cdab4c
codegen metadata
stainless-app[bot] Feb 20, 2026
18bc94e
codegen metadata
stainless-app[bot] Feb 20, 2026
aa08362
codegen metadata
stainless-app[bot] Feb 20, 2026
50f3d5c
codegen metadata
stainless-app[bot] Feb 20, 2026
566dbe8
codegen metadata
stainless-app[bot] Feb 20, 2026
4509a2f
codegen metadata
stainless-app[bot] Feb 20, 2026
8bab754
codegen metadata
stainless-app[bot] Feb 20, 2026
8c3b135
codegen metadata
stainless-app[bot] Feb 20, 2026
3383699
codegen metadata
stainless-app[bot] Feb 20, 2026
46e6c0f
codegen metadata
stainless-app[bot] Feb 20, 2026
d81a366
chore(internal): remove mock server code
stainless-app[bot] Feb 20, 2026
e1413d2
chore: update mock server docs
stainless-app[bot] Feb 20, 2026
c0452dd
codegen metadata
stainless-app[bot] Feb 20, 2026
99b5c9d
codegen metadata
stainless-app[bot] Feb 20, 2026
067776d
codegen metadata
stainless-app[bot] Feb 20, 2026
0f98d98
codegen metadata
stainless-app[bot] Feb 20, 2026
a00ea1c
codegen metadata
stainless-app[bot] Feb 20, 2026
95935e2
codegen metadata
stainless-app[bot] Feb 20, 2026
207b156
codegen metadata
stainless-app[bot] Feb 20, 2026
3125bfe
codegen metadata
stainless-app[bot] Feb 21, 2026
9b1949f
codegen metadata
stainless-app[bot] Feb 21, 2026
dc7b129
codegen metadata
stainless-app[bot] Feb 21, 2026
6815230
codegen metadata
stainless-app[bot] Feb 21, 2026
8f25952
codegen metadata
stainless-app[bot] Feb 21, 2026
2fb8588
codegen metadata
stainless-app[bot] Feb 21, 2026
83395da
codegen metadata
stainless-app[bot] Feb 21, 2026
57a6661
codegen metadata
stainless-app[bot] Feb 21, 2026
6825c01
codegen metadata
stainless-app[bot] Feb 21, 2026
6e6ede8
codegen metadata
stainless-app[bot] Feb 21, 2026
484757e
codegen metadata
stainless-app[bot] Feb 21, 2026
c971f87
codegen metadata
stainless-app[bot] Feb 21, 2026
217b529
codegen metadata
stainless-app[bot] Feb 21, 2026
2dfa1b4
codegen metadata
stainless-app[bot] Feb 21, 2026
965e49a
codegen metadata
stainless-app[bot] Feb 21, 2026
bf504ff
codegen metadata
stainless-app[bot] Feb 21, 2026
993a76f
codegen metadata
stainless-app[bot] Feb 21, 2026
bd880d2
codegen metadata
stainless-app[bot] Feb 21, 2026
cd809b2
codegen metadata
stainless-app[bot] Feb 21, 2026
fb7ff81
codegen metadata
stainless-app[bot] Feb 21, 2026
db6963b
codegen metadata
stainless-app[bot] Feb 22, 2026
8501a8f
codegen metadata
stainless-app[bot] Feb 22, 2026
e13213d
codegen metadata
stainless-app[bot] Feb 22, 2026
6a049b6
codegen metadata
stainless-app[bot] Feb 22, 2026
4a7c64c
codegen metadata
stainless-app[bot] Feb 22, 2026
7a0eeff
codegen metadata
stainless-app[bot] Feb 22, 2026
68fb214
codegen metadata
stainless-app[bot] Feb 22, 2026
052831c
codegen metadata
stainless-app[bot] Feb 22, 2026
af8475a
codegen metadata
stainless-app[bot] Feb 22, 2026
8454aec
codegen metadata
stainless-app[bot] Feb 22, 2026
2928b77
codegen metadata
stainless-app[bot] Feb 22, 2026
764eb12
codegen metadata
stainless-app[bot] Feb 22, 2026
e5907af
codegen metadata
stainless-app[bot] Feb 22, 2026
f60def4
codegen metadata
stainless-app[bot] Feb 22, 2026
c37c7f3
codegen metadata
stainless-app[bot] Feb 22, 2026
5d8a14c
codegen metadata
stainless-app[bot] Feb 22, 2026
2d08e16
codegen metadata
stainless-app[bot] Feb 22, 2026
1e72318
codegen metadata
stainless-app[bot] Feb 23, 2026
668fa3e
chore: configure new SDK language
stainless-app[bot] Feb 23, 2026
ca45e3f
codegen metadata
stainless-app[bot] Feb 23, 2026
d904904
codegen metadata
stainless-app[bot] Feb 23, 2026
75baeb5
codegen metadata
stainless-app[bot] Feb 23, 2026
2591dad
codegen metadata
stainless-app[bot] Feb 23, 2026
9c2e151
codegen metadata
stainless-app[bot] Feb 23, 2026
8d15cc5
codegen metadata
stainless-app[bot] Feb 23, 2026
c1b7b28
codegen metadata
stainless-app[bot] Feb 23, 2026
82f10e5
codegen metadata
stainless-app[bot] Feb 23, 2026
0be5941
codegen metadata
stainless-app[bot] Feb 23, 2026
b65553b
codegen metadata
stainless-app[bot] Feb 23, 2026
002cbd3
codegen metadata
stainless-app[bot] Feb 23, 2026
d9e4d49
codegen metadata
stainless-app[bot] Feb 23, 2026
087d030
codegen metadata
stainless-app[bot] Feb 23, 2026
32dcc40
codegen metadata
stainless-app[bot] Feb 24, 2026
9620d8d
codegen metadata
stainless-app[bot] Feb 24, 2026
0ff4b01
codegen metadata
stainless-app[bot] Feb 24, 2026
7200382
codegen metadata
stainless-app[bot] Feb 24, 2026
2ddd597
codegen metadata
stainless-app[bot] Feb 24, 2026
331f288
codegen metadata
stainless-app[bot] Feb 24, 2026
2a25981
codegen metadata
stainless-app[bot] Feb 24, 2026
6123d9b
codegen metadata
stainless-app[bot] Feb 24, 2026
cbdf15f
codegen metadata
stainless-app[bot] Feb 24, 2026
bd93cca
codegen metadata
stainless-app[bot] Feb 24, 2026
66fcd6e
codegen metadata
stainless-app[bot] Feb 24, 2026
439aad5
codegen metadata
stainless-app[bot] Feb 24, 2026
ba82cbb
codegen metadata
stainless-app[bot] Feb 24, 2026
6584151
codegen metadata
stainless-app[bot] Feb 24, 2026
b83c0cf
chore: make `Properties` more resilient to `null`
stainless-app[bot] Feb 24, 2026
9edbed1
chore: drop apache dependency
stainless-app[bot] Feb 24, 2026
49ac8f8
codegen metadata
stainless-app[bot] Feb 24, 2026
c617ddd
codegen metadata
stainless-app[bot] Feb 24, 2026
53ac98e
codegen metadata
stainless-app[bot] Feb 24, 2026
559832d
codegen metadata
stainless-app[bot] Feb 24, 2026
a278cca
codegen metadata
stainless-app[bot] Feb 24, 2026
6553441
codegen metadata
stainless-app[bot] Feb 24, 2026
edbeb45
codegen metadata
stainless-app[bot] Feb 24, 2026
0be828e
codegen metadata
stainless-app[bot] Feb 25, 2026
4fb82d1
codegen metadata
stainless-app[bot] Feb 25, 2026
1b7a7e9
codegen metadata
stainless-app[bot] Feb 25, 2026
88228ee
codegen metadata
stainless-app[bot] Feb 25, 2026
1de9f60
codegen metadata
stainless-app[bot] Feb 25, 2026
9b12b7e
codegen metadata
stainless-app[bot] Feb 25, 2026
bf5f75a
codegen metadata
stainless-app[bot] Feb 25, 2026
7e9327a
codegen metadata
stainless-app[bot] Feb 25, 2026
b122223
codegen metadata
stainless-app[bot] Feb 25, 2026
5ab493e
codegen metadata
stainless-app[bot] Feb 25, 2026
e4c5df2
codegen metadata
stainless-app[bot] Feb 25, 2026
59e3901
codegen metadata
stainless-app[bot] Feb 25, 2026
ce88f4a
codegen metadata
stainless-app[bot] Feb 25, 2026
47e0e22
chore(internal): expand imports
stainless-app[bot] Feb 25, 2026
f811bc9
codegen metadata
stainless-app[bot] Feb 25, 2026
f38c66b
codegen metadata
stainless-app[bot] Feb 25, 2026
1bbaced
codegen metadata
stainless-app[bot] Feb 25, 2026
67c8763
codegen metadata
stainless-app[bot] Feb 25, 2026
cd69b79
codegen metadata
stainless-app[bot] Feb 25, 2026
4da39e4
codegen metadata
stainless-app[bot] Feb 25, 2026
d340970
codegen metadata
stainless-app[bot] Feb 25, 2026
788d824
codegen metadata
stainless-app[bot] Feb 26, 2026
318fc99
codegen metadata
stainless-app[bot] Feb 26, 2026
3d63cf3
codegen metadata
stainless-app[bot] Feb 26, 2026
0428df8
codegen metadata
stainless-app[bot] Feb 26, 2026
b72b222
codegen metadata
stainless-app[bot] Feb 26, 2026
4e068ed
codegen metadata
stainless-app[bot] Feb 26, 2026
73f2ab2
codegen metadata
stainless-app[bot] Feb 26, 2026
f619337
codegen metadata
stainless-app[bot] Feb 26, 2026
2a140d6
codegen metadata
stainless-app[bot] Feb 26, 2026
08c56f2
codegen metadata
stainless-app[bot] Feb 26, 2026
13e52be
codegen metadata
stainless-app[bot] Feb 26, 2026
442d0a6
release: 0.7.0
stainless-app[bot] Feb 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.6.0"
".": "0.7.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 44
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sent%2Fsent-dm-433bfd8c688a6b6d2d4f964bb59121d692798f4e2bb6cb47f6110c4f0e1f638d.yml
openapi_spec_hash: 5378295d401c8c1152c1946cc7dbd69f
config_hash: 43a0daa5b05d44a1620e3da0ea6f4fdc
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sent%2Fsent-dm-b9aa36b06cd84a78b33b8e5bb723b0d395e31be20ecbb12847009168222db5ae.yml
openapi_spec_hash: 5d5c842901df91f69170c30f68ab0d92
config_hash: d475a61f5b59375bf562f85f19b80409
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.7.0 (2026-02-26)

Full Changelog: [v0.6.0...v0.7.0](https://github.com/sentdm/sent-dm-java/compare/v0.6.0...v0.7.0)

### Features

* **client:** add connection pooling option ([7d04245](https://github.com/sentdm/sent-dm-java/commit/7d04245815d1ad0a7690adf6f53ae98e574bc56c))


### Chores

* configure new SDK language ([668fa3e](https://github.com/sentdm/sent-dm-java/commit/668fa3ea4e37e9a6d4b27768069f6e8745c4702c))
* drop apache dependency ([9edbed1](https://github.com/sentdm/sent-dm-java/commit/9edbed1de0c2d3bcfc04a50de05bab10174d70dd))
* **internal:** expand imports ([47e0e22](https://github.com/sentdm/sent-dm-java/commit/47e0e221dc542bd54edfffdccdec5f55db08f352))
* **internal:** make `OkHttp` constructor internal ([6389eb0](https://github.com/sentdm/sent-dm-java/commit/6389eb0a1cebb8e7291af86de87578f426601c14))
* **internal:** remove mock server code ([d81a366](https://github.com/sentdm/sent-dm-java/commit/d81a3667dd4f8d761f6f4e5ff90dc2fcb3882a1c))
* make `Properties` more resilient to `null` ([b83c0cf](https://github.com/sentdm/sent-dm-java/commit/b83c0cf94dedc9bc6b4b9057a0c26332e3ef2541))
* update mock server docs ([e1413d2](https://github.com/sentdm/sent-dm-java/commit/e1413d2932000755edf64a0422f5cd99a9f82544))

## 0.6.0 (2026-02-18)

Full Changelog: [v0.5.1...v0.6.0](https://github.com/sentdm/sent-dm-java/compare/v0.5.1...v0.6.0)
Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

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

[![Maven Central](https://img.shields.io/maven-central/v/dm.sent/sent-dm-java)](https://central.sonatype.com/artifact/dm.sent/sent-dm-java/0.6.0)
[![javadoc](https://javadoc.io/badge2/dm.sent/sent-dm-java/0.6.0/javadoc.svg)](https://javadoc.io/doc/dm.sent/sent-dm-java/0.6.0)
[![Maven Central](https://img.shields.io/maven-central/v/dm.sent/sent-dm-java)](https://central.sonatype.com/artifact/dm.sent/sent-dm-java/0.7.0)
[![javadoc](https://javadoc.io/badge2/dm.sent/sent-dm-java/0.7.0/javadoc.svg)](https://javadoc.io/doc/dm.sent/sent-dm-java/0.7.0)

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

The Sent Dm Java SDK provides convenient access to the [Sent Dm REST API](https://docs.sent.dm) from applications written in Java.

It is generated with [Stainless](https://www.stainless.com/).

## MCP Server

Use the Sent Dm MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.

[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=%40sentdm%2Fsentdm-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBzZW50ZG0vc2VudGRtLW1jcCJdLCJlbnYiOnsiU0VOVF9ETV9BUElfS0VZIjoiTXkgQVBJIEtleSJ9fQ)
[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22%40sentdm%2Fsentdm-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40sentdm%2Fsentdm-mcp%22%5D%2C%22env%22%3A%7B%22SENT_DM_API_KEY%22%3A%22My%20API%20Key%22%7D%7D)

> Note: You may need to set environment variables in your MCP client.

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

The REST API documentation can be found on [docs.sent.dm](https://docs.sent.dm). Javadocs are available on [javadoc.io](https://javadoc.io/doc/dm.sent/sent-dm-java/0.6.0).
The REST API documentation can be found on [docs.sent.dm](https://docs.sent.dm). Javadocs are available on [javadoc.io](https://javadoc.io/doc/dm.sent/sent-dm-java/0.7.0).

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

Expand All @@ -24,7 +33,7 @@ The REST API documentation can be found on [docs.sent.dm](https://docs.sent.dm).
### Gradle

```kotlin
implementation("dm.sent:sent-dm-java:0.6.0")
implementation("dm.sent:sent-dm-java:0.7.0")
```

### Maven
Expand All @@ -33,7 +42,7 @@ implementation("dm.sent:sent-dm-java:0.6.0")
<dependency>
<groupId>dm.sent</groupId>
<artifactId>sent-dm-java</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</dependency>
```

Expand Down Expand Up @@ -391,6 +400,25 @@ SentDmClient client = SentDmOkHttpClient.builder()
.build();
```

### Connection pooling

To customize the underlying OkHttp connection pool, configure the client using the `maxIdleConnections` and `keepAliveDuration` methods:

```java
import dm.sent.client.SentDmClient;
import dm.sent.client.okhttp.SentDmOkHttpClient;
import java.time.Duration;

SentDmClient client = SentDmOkHttpClient.builder()
.fromEnv()
// If `maxIdleConnections` is set, then `keepAliveDuration` must be set, and vice versa.
.maxIdleConnections(10)
.keepAliveDuration(Duration.ofMinutes(2))
.build();
```

If both options are unset, OkHttp's default connection pool settings are used.

### HTTPS

> [!NOTE]
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {

allprojects {
group = "dm.sent"
version = "0.6.0" // x-release-please-version
version = "0.7.0" // x-release-please-version
}

subprojects {
Expand Down
41 changes: 0 additions & 41 deletions scripts/mock

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,7 @@ set -e

cd "$(dirname "$0")/.."

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

function prism_is_running() {
curl --silent "http://localhost:4010" >/dev/null 2>&1
}

kill_server_on_port() {
pids=$(lsof -t -i tcp:"$1" || echo "")
if [ "$pids" != "" ]; then
kill "$pids"
echo "Stopped $pids."
fi
}

function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}

if ! is_overriding_api_base_url && ! prism_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon
fi

if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
else
echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
echo
fi

echo "==> Running tests"
./gradlew test "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import java.time.Duration
import java.util.concurrent.CancellationException
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.TimeUnit
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.X509TrustManager
import okhttp3.Call
import okhttp3.Callback
import okhttp3.ConnectionPool
import okhttp3.Dispatcher
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
Expand All @@ -33,7 +35,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import okio.BufferedSink

class OkHttpClient
private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient {
internal constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient {

override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
val call = newCall(request, requestOptions)
Expand Down Expand Up @@ -200,6 +202,8 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien

private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
private var maxIdleConnections: Int? = null
private var keepAliveDuration: Duration? = null
private var dispatcherExecutorService: ExecutorService? = null
private var sslSocketFactory: SSLSocketFactory? = null
private var trustManager: X509TrustManager? = null
Expand All @@ -211,6 +215,28 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien

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

/**
* Sets the maximum number of idle connections kept by the underlying [ConnectionPool].
*
* If this is set, then [keepAliveDuration] must also be set.
*
* If unset, then OkHttp's default is used.
*/
fun maxIdleConnections(maxIdleConnections: Int?) = apply {
this.maxIdleConnections = maxIdleConnections
}

/**
* Sets the keep-alive duration for idle connections in the underlying [ConnectionPool].
*
* If this is set, then [maxIdleConnections] must also be set.
*
* If unset, then OkHttp's default is used.
*/
fun keepAliveDuration(keepAliveDuration: Duration?) = apply {
this.keepAliveDuration = keepAliveDuration
}

fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply {
this.dispatcherExecutorService = dispatcherExecutorService
}
Expand Down Expand Up @@ -240,6 +266,22 @@ private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClien
.apply {
dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) }

val maxIdleConnections = maxIdleConnections
val keepAliveDuration = keepAliveDuration
if (maxIdleConnections != null && keepAliveDuration != null) {
connectionPool(
ConnectionPool(
maxIdleConnections,
keepAliveDuration.toNanos(),
TimeUnit.NANOSECONDS,
)
)
} else {
check((maxIdleConnections != null) == (keepAliveDuration != null)) {
"Both or none of `maxIdleConnections` and `keepAliveDuration` must be set, but only one was set"
}
}

val sslSocketFactory = sslSocketFactory
val trustManager = trustManager
if (sslSocketFactory != null && trustManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SentDmOkHttpClient private constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var dispatcherExecutorService: ExecutorService? = null
private var proxy: Proxy? = null
private var maxIdleConnections: Int? = null
private var keepAliveDuration: Duration? = null
private var sslSocketFactory: SSLSocketFactory? = null
private var trustManager: X509TrustManager? = null
private var hostnameVerifier: HostnameVerifier? = null
Expand Down Expand Up @@ -75,6 +77,46 @@ class SentDmOkHttpClient private constructor() {
/** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
fun proxy(proxy: Optional<Proxy>) = proxy(proxy.getOrNull())

/**
* The maximum number of idle connections kept by the underlying OkHttp connection pool.
*
* If this is set, then [keepAliveDuration] must also be set.
*
* If unset, then OkHttp's default is used.
*/
fun maxIdleConnections(maxIdleConnections: Int?) = apply {
this.maxIdleConnections = maxIdleConnections
}

/**
* Alias for [Builder.maxIdleConnections].
*
* This unboxed primitive overload exists for backwards compatibility.
*/
fun maxIdleConnections(maxIdleConnections: Int) =
maxIdleConnections(maxIdleConnections as Int?)

/**
* Alias for calling [Builder.maxIdleConnections] with `maxIdleConnections.orElse(null)`.
*/
fun maxIdleConnections(maxIdleConnections: Optional<Int>) =
maxIdleConnections(maxIdleConnections.getOrNull())

/**
* The keep-alive duration for idle connections in the underlying OkHttp connection pool.
*
* If this is set, then [maxIdleConnections] must also be set.
*
* If unset, then OkHttp's default is used.
*/
fun keepAliveDuration(keepAliveDuration: Duration?) = apply {
this.keepAliveDuration = keepAliveDuration
}

/** Alias for calling [Builder.keepAliveDuration] with `keepAliveDuration.orElse(null)`. */
fun keepAliveDuration(keepAliveDuration: Optional<Duration>) =
keepAliveDuration(keepAliveDuration.getOrNull())

/**
* The socket factory used to secure HTTPS connections.
*
Expand Down Expand Up @@ -321,6 +363,8 @@ class SentDmOkHttpClient private constructor() {
OkHttpClient.builder()
.timeout(clientOptions.timeout())
.proxy(proxy)
.maxIdleConnections(maxIdleConnections)
.keepAliveDuration(keepAliveDuration)
.dispatcherExecutorService(dispatcherExecutorService)
.sslSocketFactory(sslSocketFactory)
.trustManager(trustManager)
Expand Down
Loading
Loading