Skip to content

chore: collapse duplicated adapter idioms in sdk-io-okio3 and sdk-async-reactor#186

Merged
OmarAlJarrah merged 1 commit into
mainfrom
chore/collapse-adapter-idioms
Jun 25, 2026
Merged

chore: collapse duplicated adapter idioms in sdk-io-okio3 and sdk-async-reactor#186
OmarAlJarrah merged 1 commit into
mainfrom
chore/collapse-adapter-idioms

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Three small, behavior-preserving internal refactors that remove copy-pasted blocks across the two adapter modules so each shared contract lives in exactly one place. All three are independently mergeable and leave the public surface untouched, so apiCheck stays green with no apiDump.

SlicedOkioBufferedSource — extract drainRemaining()

The three "read everything left in the window" overrides (readByteArray(), readUtf8(), readString(charset)) carried an identical realize-offset / drain / decrement body and differed only in how they decode the drained bytes. A private drainRemaining() helper holds the slice-accounting rule (remaining -= bytes.size) once; each override is now a checkOpen() plus a decode. checkOpen() still runs ahead of the drain in every override, and the empty-window path is preserved (String(EMPTY_BYTES, …) is "").

sdk-io-okio3 adapters — centralize the wrapper cache

ForeignSourceAdapter and ForeignSinkAdapter each opened with the same two cache fields and the same identity-keyed "wrap once per okio.Buffer" lookup, differing only in read/sink vs write/source. The idiom now lives in a small internal OkioBufferWrapperCache. Each adapter holds its own instance (a per-adapter val), so the identity cache stays scoped to one adapter and the "not safe for concurrent use" contract is unchanged — no shared or global state.

Reactor — extract deferMono() / logEvent()

executeMono and sendMono were the same Mono.defer bridge — per-subscription MDC capture, Mono.fromFuture, and two verbose lifecycle log hooks — differing only in executeAsync vs sendAsync. A private deferMono(supplier) takes the future supplier and each public function becomes a one-liner; logEvent holds the shared verbose-log block. Coldness, per-subscription MDC capture, and cancellation propagation are all preserved.

Validation

./gradlew :sdk-io-okio3:build :sdk-async-reactor:build passes locally — tests, ktlint, detekt, and apiCheck all green.

Closes #180

…nc-reactor

Three behavior-preserving internal refactors that remove copy-pasted blocks
so each shared contract lives in one place:

- SlicedOkioBufferedSource: extract a private drainRemaining() helper for the
  three full-slice reads (readByteArray/readUtf8/readString), which differed
  only in how they decode the drained bytes. checkOpen() still runs ahead of
  the drain in every override.
- sdk-io-okio3 adapters: lift the identity-keyed "wrap once per okio.Buffer"
  cache out of ForeignSourceAdapter and ForeignSinkAdapter into a small
  per-adapter OkioBufferWrapperCache, so the wrapper-reuse rationale and lookup
  live once. Each adapter keeps its own instance; no shared state.
- Reactor: extract deferMono()/logEvent() from executeMono/sendMono, which were
  the same Mono.defer bridge differing only in executeAsync vs sendAsync. MDC is
  still captured per subscription, coldness and cancellation are unchanged.

Public surface is untouched, so apiCheck stays green with no apiDump.
@OmarAlJarrah OmarAlJarrah merged commit 21421e0 into main Jun 25, 2026
1 check passed
@OmarAlJarrah OmarAlJarrah deleted the chore/collapse-adapter-idioms branch June 25, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdk-io-okio3 + sdk-async-reactor: collapse duplicated adapter idioms

1 participant