Skip to content

Commit b8ce3a4

Browse files
committed
update simplepool-migration.md
1 parent f844295 commit b8ce3a4

1 file changed

Lines changed: 47 additions & 21 deletions

File tree

src/concern/module/simplepool-migration.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ try {
4545

4646
## Migration Patterns
4747

48-
### Pattern 1: Simple Request
48+
### Pattern 1: Simple Borrow/Return (with .get)
4949

5050
**Before:**
5151
```java
52-
Http2Client client = Http2Client.getInstance();
5352
ClientConnection connection = null;
5453
try {
55-
connection = client.borrowConnection(10, uri, Http2Client.WORKER,
56-
Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true));
54+
connection = client.borrowConnection(uri, worker, pool, options).get();
5755

5856
// Send request
5957
connection.sendRequest(request, callback);
@@ -67,10 +65,11 @@ try {
6765

6866
**After:**
6967
```java
70-
Http2Client client = Http2Client.getInstance();
68+
import com.networknt.client.simplepool.SimpleConnectionState;
69+
7170
SimpleConnectionState.ConnectionToken token = null;
7271
try {
73-
token = client.borrow(uri, Http2Client.WORKER, Http2Client.BUFFER_POOL, true);
72+
token = client.borrow(uri, worker, pool, options);
7473
ClientConnection connection = token.connection().getRawConnection();
7574

7675
// Send request
@@ -83,30 +82,34 @@ try {
8382
}
8483
```
8584

86-
### Pattern 2: With OptionMap
85+
### Pattern 2: With Timeout
86+
87+
The new `borrow()` method handles timeouts internally through configuration rather than as a method parameter.
8788

8889
**Before:**
8990
```java
90-
OptionMap options = OptionMap.builder()
91-
.set(UndertowOptions.ENABLE_HTTP2, true)
92-
.set(Options.KEEP_ALIVE, true)
93-
.getMap();
94-
95-
ClientConnection conn = client.borrowConnection(10, uri, worker, bufferPool, options);
91+
// Note: The deprecated method took a timeout parameter (e.g., 10 seconds)
92+
ClientConnection connection = client.borrowConnection(10, uri, worker, pool, options);
9693
```
9794

9895
**After:**
9996
```java
100-
OptionMap options = OptionMap.builder()
101-
.set(UndertowOptions.ENABLE_HTTP2, true)
102-
.set(Options.KEEP_ALIVE, true)
103-
.getMap();
104-
105-
ConnectionToken token = client.borrow(uri, worker, bufferPool, options);
106-
ClientConnection conn = token.connection().getRawConnection();
97+
// Note: timeout parameter is removed in the new API
98+
ConnectionToken token = client.borrow(uri, worker, pool, options);
99+
ClientConnection connection = token.connection().getRawConnection();
107100
```
108101

109-
### Pattern 3: HTTP/1.1 vs HTTP/2
102+
### Pattern 3: Async (IoFuture)
103+
104+
**Before:**
105+
```java
106+
IoFuture<ClientConnection> future = client.borrowConnection(uri, worker, pool, options);
107+
```
108+
109+
**Migration Rule:**
110+
The async `IoFuture<ClientConnection>` pattern **cannot** be directly migrated because the new `borrow()` method is synchronous. These usages should be migrated to a different async pattern or kept on the old API until fully deprecated.
111+
112+
### Pattern 4: HTTP/1.1 vs HTTP/2
110113

111114
```java
112115
// HTTP/2 (multiplexed)
@@ -238,6 +241,29 @@ try {
238241
}
239242
```
240243

244+
### Cannot find symbol ConnectionToken
245+
**Symptom:** Compilation error stating `Cannot find symbol class ConnectionToken`.
246+
247+
**Cause:** Missing import for `SimpleConnectionState`.
248+
249+
**Fix:** Add the required import:
250+
```java
251+
import com.networknt.client.simplepool.SimpleConnectionState;
252+
```
253+
254+
### getRawConnection() returns null
255+
**Symptom:** `NullPointerException` or unexpected behavior because `token.connection().getRawConnection()` returns `null`.
256+
257+
**Cause:** The connection has not been properly established yet.
258+
259+
**Fix:** Check `token.connection().isOpen()` before attempting to use the raw connection:
260+
```java
261+
if (token.connection().isOpen()) {
262+
ClientConnection connection = token.connection().getRawConnection();
263+
// use connection
264+
}
265+
```
266+
241267
### Metrics Show Zero
242268
**Cause:** Metrics not enabled
243269

0 commit comments

Comments
 (0)