chore: collapse duplicated adapter idioms in sdk-io-okio3 and sdk-async-reactor#186
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
apiCheckstays green with noapiDump.SlicedOkioBufferedSource— extractdrainRemaining()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 privatedrainRemaining()helper holds the slice-accounting rule (remaining -= bytes.size) once; each override is now acheckOpen()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-okio3adapters — centralize the wrapper cacheForeignSourceAdapterandForeignSinkAdaptereach opened with the same two cache fields and the same identity-keyed "wrap once perokio.Buffer" lookup, differing only inread/sinkvswrite/source. The idiom now lives in a smallinternal OkioBufferWrapperCache. Each adapter holds its own instance (a per-adapterval), 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— extractdeferMono()/logEvent()executeMonoandsendMonowere the sameMono.deferbridge — per-subscription MDC capture,Mono.fromFuture, and two verbose lifecycle log hooks — differing only inexecuteAsyncvssendAsync. A privatedeferMono(supplier)takes the future supplier and each public function becomes a one-liner;logEventholds 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:buildpasses locally — tests, ktlint, detekt, andapiCheckall green.Closes #180