or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

completable.mddisposables.mdflowable.mdindex.mdmaybe.mdobservable.mdschedulers.mdsingle.mdsubjects.md
tile.json

tessl/maven-io-reactivex-rxjava3--rxjava

Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.reactivex.rxjava3/rxjava@3.0.x

To install, run

npx @tessl/cli install tessl/maven-io-reactivex-rxjava3--rxjava@3.0.0

index.mddocs/

RxJava

RxJava is a comprehensive reactive programming library for the Java Virtual Machine that implements the Reactive Extensions pattern, enabling developers to compose asynchronous and event-based programs using observable sequences. It provides five reactive types (Observable, Flowable, Single, Maybe, Completable), extensive operators for data transformation, flexible scheduling, and built-in backpressure handling.

Package Information

  • Package Name: rxjava
  • Package Type: maven
  • Group ID: io.reactivex.rxjava3
  • Language: Java
  • Installation:
    <dependency>
        <groupId>io.reactivex.rxjava3</groupId>
        <artifactId>rxjava</artifactId>
        <version>3.0.0</version>
    </dependency>
  • Gradle: implementation 'io.reactivex.rxjava3:rxjava:3.0.0'

Core Imports

import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.rxjava3.disposables.Disposable;

For specific functionality:

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Completable;

Basic Usage

import io.reactivex.rxjava3.core.*;
import io.reactivex.rxjava3.schedulers.Schedulers;

// Simple Observable sequence
Observable.just("Hello", "World")
    .map(String::toUpperCase)
    .subscribe(System.out::println);

// Backpressured Flowable with scheduling
Flowable.range(1, 10)
    .map(i -> i * i)
    .subscribeOn(Schedulers.computation())
    .observeOn(Schedulers.single())
    .subscribe(System.out::println);

// Single value operations
Single.just("Hello")
    .map(String::length)
    .subscribe(length -> System.out.println("Length: " + length));

// Completion signaling
Completable.fromRunnable(() -> System.out.println("Task completed"))
    .delay(1, TimeUnit.SECONDS)
    .subscribe();

Architecture

RxJava is built around several key components:

  • Reactive Types: Five core types (Observable, Flowable, Single, Maybe, Completable) for different data emission patterns
  • Observer Pattern: Publishers emit data to subscribers following the reactive streams protocol
  • Functional Operators: 200+ operators for transforming, filtering, combining, and manipulating data streams
  • Scheduler System: Abstraction over concurrency with built-in schedulers for different execution contexts
  • Backpressure Handling: Flow control mechanisms in Flowable to handle fast producers and slow consumers
  • Resource Management: Disposable pattern for subscription lifecycle and memory management

Capabilities

Observable Streams

Non-backpressured reactive streams for handling sequences of 0 to N items with comprehensive operator support.

public abstract class Observable<T> implements ObservableSource<T> {
    // Static factory methods
    public static <T> Observable<T> just(T item);
    public static <T> Observable<T> fromIterable(Iterable<? extends T> source);
    public static Observable<Long> interval(long period, TimeUnit unit);
    
    // Instance methods
    public final <R> Observable<R> map(Function<? super T, ? extends R> mapper);
    public final Observable<T> filter(Predicate<? super T> predicate);
    public final Disposable subscribe(Consumer<? super T> onNext);
}

Observable API

Flowable Streams

Backpressured reactive streams implementing the Reactive Streams specification for handling sequences with flow control.

public abstract class Flowable<T> implements Publisher<T> {
    // Static factory methods
    public static <T> Flowable<T> just(T item);
    public static <T> Flowable<T> fromIterable(Iterable<? extends T> source);
    public static Flowable<Long> interval(long period, TimeUnit unit);
    
    // Instance methods
    public final <R> Flowable<R> map(Function<? super T, ? extends R> mapper);
    public final Flowable<T> onBackpressureBuffer();
    public final Disposable subscribe(Consumer<? super T> onNext);
}

Flowable API

Single Values

Reactive type for operations that emit exactly one item or an error, ideal for single-value async operations.

public abstract class Single<T> implements SingleSource<T> {
    // Static factory methods
    public static <T> Single<T> just(T item);
    public static <T> Single<T> fromCallable(Callable<? extends T> callable);
    
    // Instance methods
    public final <R> Single<R> map(Function<? super T, ? extends R> mapper);
    public final Disposable subscribe(Consumer<? super T> onSuccess);
}

Single API

Optional Values

Reactive type for operations that emit zero or one item, perfect for optional async operations.

public abstract class Maybe<T> implements MaybeSource<T> {
    // Static factory methods
    public static <T> Maybe<T> just(T item);
    public static <T> Maybe<T> empty();
    public static <T> Maybe<T> fromCallable(Callable<? extends T> callable);
    
    // Instance methods
    public final <R> Maybe<R> map(Function<? super T, ? extends R> mapper);
    public final Disposable subscribe(Consumer<? super T> onSuccess);
}

Maybe API

Completion Signaling

Reactive type for operations that only signal completion or error without emitting items.

public abstract class Completable implements CompletableSource {
    // Static factory methods
    public static Completable complete();
    public static Completable fromRunnable(Runnable run);
    public static Completable error(Throwable error);
    
    // Instance methods
    public final Completable andThen(CompletableSource next);
    public final Disposable subscribe(Action onComplete);
}

Completable API

Scheduling and Concurrency

Scheduler system providing abstraction over different execution contexts and threading models.

public final class Schedulers {
    public static Scheduler computation();
    public static Scheduler io();
    public static Scheduler single();
    public static Scheduler trampoline();
    public static Scheduler from(Executor executor);
}

public abstract class Scheduler {
    public abstract Worker createWorker();
    public Disposable scheduleDirect(Runnable run);
    public Disposable scheduleDirect(Runnable run, long delay, TimeUnit unit);
}

Schedulers and Concurrency

Resource Management

Disposable pattern for managing subscriptions and preventing memory leaks in reactive streams.

public interface Disposable {
    void dispose();
    boolean isDisposed();
}

public final class CompositeDisposable implements Disposable, DisposableContainer {
    public boolean add(Disposable disposable);
    public boolean remove(Disposable disposable);
    public void clear();
}

Resource Management

Subjects and Processors

Hot observables that act as both observer and observable, enabling multicasting of events to multiple subscribers.

public final class PublishSubject<T> extends Subject<T> {
    public static <T> PublishSubject<T> create();
    public void onNext(T value);
    public void onError(Throwable error);
    public void onComplete();
}

public final class PublishProcessor<T> extends FlowableProcessor<T> {
    public static <T> PublishProcessor<T> create();
    public void onNext(T value);
    public void onError(Throwable error);
    public void onComplete();
}

Subjects and Processors

Types

// Core observer interfaces
public interface Observer<T> {
    void onSubscribe(Disposable d);
    void onNext(T t);
    void onError(Throwable e);
    void onComplete();
}

public interface SingleObserver<T> {
    void onSubscribe(Disposable d);
    void onSuccess(T t);
    void onError(Throwable e);
}

public interface MaybeObserver<T> {
    void onSubscribe(Disposable d);
    void onSuccess(T t);
    void onError(Throwable e);
    void onComplete();
}

public interface CompletableObserver {
    void onSubscribe(Disposable d);
    void onError(Throwable e);
    void onComplete();
}

// Functional interfaces
public interface Consumer<T> {
    void accept(T t) throws Throwable;
}

public interface Function<T, R> {
    R apply(T t) throws Throwable;
}

public interface Predicate<T> {
    boolean test(T t) throws Throwable;
}

public interface Action {
    void run() throws Throwable;
}