refactor: use ByteBuffer fluent API chains with JDK 9 covariant returns#3139
Merged
Conversation
Motivation: JDK 9 changed ByteBuffer.clear(), limit(int), flip(), rewind() to return ByteBuffer instead of Buffer, enabling fluent method chaining. Modification: Consolidate separate buffer.clear() + buffer.limit(n) statements into single expressions passed directly to channel.read()/channel.receive(). Chain buffer.clear().flip() in TlsEngineHelpers.emptyReadBuffer. - TcpConnection.innerRead: 4 statements → 3 - UdpConnection.innerRead: 3 statements → 1 - UdpListener.innerReceive: 3 statements → 1 - TlsEngineHelpers.emptyReadBuffer: 2 statements → 1 Result: More concise I/O code leveraging JDK 9+ ByteBuffer covariant returns. Semantically identical — clear/limit/flip order unchanged. Tests: - sbt "actor-tests / Test / testOnly org.apache.pekko.io.TcpConnectionSpec" — 34/34 passed - sbt "actor-tests / Test / testOnly org.apache.pekko.io.UdpIntegrationSpec" — 7/7 passed References: Refs #3136
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.
Motivation
JDK 9 changed
ByteBuffer.clear(),limit(int),flip(),rewind()to returnByteBufferinstead ofBuffer, enabling fluent method chaining. Previously these returnedBuffer, requiring either explicit casts or separate statements.Modification
Consolidate separate
buffer.clear()+buffer.limit(n)statements into single expressions passed directly tochannel.read()/channel.receive(). Chainbuffer.clear().flip()inTlsEngineHelpers.emptyReadBuffer.TcpConnection.innerReadUdpConnection.innerReadUdpListener.innerReceiveTlsEngineHelpers.emptyReadBufferResult
More concise I/O code leveraging JDK 9+ ByteBuffer covariant returns. Semantically identical — clear/limit/flip execution order unchanged.
Tests
sbt "actor-tests / Test / testOnly org.apache.pekko.io.TcpConnectionSpec"— 34/34 passedsbt "actor-tests / Test / testOnly org.apache.pekko.io.UdpIntegrationSpec"— 7/7 passedReferences
Refs #3136