Implement non-blocking trySend and tryReceive methods#262
Open
Implement non-blocking trySend and tryReceive methods#262
Conversation
Add a non-blocking O(1) method that returns a best-effort estimate of the number of elements in a channel, computed as the difference between send and receive operations initiated. Designed for monitoring, metrics export, and debugging - not for control flow. Includes comprehensive Javadoc with anti-patterns, recommended usage, and a monitoring code example. Tests cover buffered, unlimited, and rendezvous channels, concurrent modification, closed/error states, and waiting senders beyond buffer capacity.
Add non-blocking operations to the Channel implementation and the Source/Sink interfaces. These methods are essential for integration with event loops (e.g., Netty, Vert.x) where blocking the thread is prohibited. - Added 'trySend(T)' and 'tryReceive()' to Channel, Source, and Sink. - Implemented high-performance, lock-free versions in Channel.java. - Provided default implementations in interfaces using 'Select' fallback for binary compatibility. - Updated documentation with usage examples and clear guidance on non-blocking scenarios. - Refactored 'flows' and 'kafka' modules to use the new API in critical non-blocking callbacks, removing unnecessary 'InterruptedException' handling.
…nels.md Add explanatory comments for the transient RESUMING state in tryUpdateCellReceive, matching the existing comments in the blocking updateCellReceive variant. Revert unrelated cosmetic changes to channels.md from the trySend/tryReceive PR, keeping only the new non-blocking operations section and a contention caveat note.
…ered-values test Clarify Sink/Source Javadoc: replace "spuriously" with explicit explanation of what happens under contention. Add test verifying that tryReceiveOrClosed returns ChannelError immediately when error() is called on a channel with buffered values.
Remove narrating comments (CAS unsuccessful, reserving cell, etc.) that just restate what the code does. Keep comments that explain why, matching the style of the blocking variants.
…nt spinning loops
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.
Summary
trySend/tryReceive(andOrClosedvariants) onChannel,Sink, andSourcefor integration with non-blocking frameworks (Netty, Vert.x, etc.)Channelusing CAS-based cell reservation with pre-check optimization to avoid unnecessary CAS attemptsFromFlowPublisher,KafkaDrain, andKafkaStageto usetrySendinstead of blockingsendChannel.estimateSize()for monitoring and observabilitychannels.mddocumentationResolves #187