$ show ReactiveX/RxJava
RxJava 4 is a reactive programming library for the JVM, implementing the Reactive Streams specification via `java.util.concurrent.Flow` (Publisher/Subscriber). It provides six core reactive types: `Flowable` (backpressured), `Observable` (unbounded), `Single` (single value), `Maybe` (optional value), `Completable` (completion signal), and the new `Streamable` (pull-based streaming with `CompletionStage`). The library offers a comprehensive set of operators (map, filter, flatMap, concat, merge, window, buffer, etc.) for composing asynchronous data flows, along with schedulers for threading control (`Schedulers.computation()`, `Schedulers.io()`, `Schedulers.virtual()` for virtual threads). It includes advanced features like operator fusion (`QueueFuseable`), backpressure strategies, and configurable operator parameters via immutable records. The architecture is modular: each operator is a final class extending the base reactive type with an inner observer/subscriber class managing state. External dependencies are minimal (only JDK standard library), and the library is designed for embedding in applications, frameworks, and Android. Key entry points are the static factory methods on `Flowable`, `Observable`, `Single`, `Maybe`, `Completable`, and `Streamable`. Data flows are constructed by chaining operators that transform and combine reactive streams, with lifecycle managed through `Disposable` and `Subscription` contracts.
The LLM identified 4 files worth highlighting for reuse:
A utility class that wraps reactive signals (value, error, completion, disposable, subscription) into a single `Object` for internal queue-based communication. It uses sentinel objects and marker interfaces to distinguish signal types without instanceof checks, enabling efficient and type-safe notification passing in operator fusion and queue-drain patterns. This class is self-contained (no internal imports) and can be extracted for any reactive or event-driven system requiring a compact, thread-safe signaling mechanism.
An immutable Java record that encapsulates operator configuration parameters (buffer size, delay-error flag, error mode) with constructor validation. It replaces traditional overloaded methods with a single config object, reducing API surface and improving discoverability. The pattern is reusable for any library that needs to parameterize operations without method explosion, and demonstrates clean use of records for configuration.
A utility class providing static methods for atomic subscription lifecycle management: `setOnce`, `replace`, `dispose`, `deferredSetOnce`, `deferredRequest`, and `cancel`. It uses `AtomicReference<Subscription>` and `AtomicLong` for thread-safe operations, and includes sentinel values for cancelled/requested states. This class is self-contained and can be reused in any reactive or async library that needs to manage `Subscription` objects with backpressure support.
An interface defining fusion mode constants (`NONE`, `SYNC`, `ASYNC`, `ANY`) and the `requestFusion(int mode)` method for operator fusion negotiation. It enables synchronous or asynchronous fusion between upstream and downstream operators, eliminating intermediate queues and reducing overhead. This interface is a core part of RxJava's performance optimization strategy and can be adopted by any reactive library seeking to implement fusion.