Top Description Inners Fields Constructors Methods
io.reactivex.rxjava3.internal.operators.observable

public final Class ObservableCache<T>

extends AbstractObservableWithUpstream<T, T>
implements Observer<T>
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.core.Observer
Type Parameters
<T>
the source element type
Imports
java.util.concurrent.atomic.*, io.reactivex.rxjava3.core.*, io.reactivex.rxjava3.disposables.Disposable

An observable which auto-connects to another observable, caches the elements from that observable but allows terminating the connection and completing the cache.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ObservableCache.CacheDisposable<
the value type
T
>

Hosts the downstream consumer and its current requested and replay states.

pack-priv static class
ObservableCache.Node<
the element type
T
>

Represents a segment of the cached item list as part of a linked-node-list structure.

Field Summary

Modifier and TypeField and Description
pack-priv final int
capacityHint

The number of items per cached nodes.

pack-priv volatile boolean
done

True if the source has terminated.

pack-priv static final ObservableCache.CacheDisposable<T>[]
EMPTY

A shared instance of an empty array of observers to avoid creating a new empty array when all observers dispose.

pack-priv Throwable
error

If observers is TERMINATED, this holds the terminal error if not null.

pack-priv final ObservableCache.Node<T>
head

The starting point of the cached items.

pack-priv final AtomicReference<ObservableCache.CacheDisposable<T>[]>
observers

The current known array of observer state to notify.

pack-priv final AtomicBoolean
once

The subscription to the source should happen at most once.

pack-priv volatile long
size

The total number of elements in the list available for reads.

pack-priv ObservableCache.Node<T>
tail

The current tail of the linked structure holding the items.

pack-priv int
tailOffset

How many items have been put into the tail node so far.

pack-priv static final ObservableCache.CacheDisposable<T>[]
TERMINATED

A shared instance indicating the source has no more events and there is no need to remember observers anymore.

Inherited from io.reactivex.rxjava3.internal.operators.observable.AbstractObservableWithUpstream:
source

Constructor Summary

AccessConstructor and Description
public
ObservableCache(Observable<T>
the source to subscribe to for the first incoming observer
source
,
int
the number of items expected (reduce allocation frequency)
capacityHint
)

Constructs an empty, non-connected cache.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(ObservableCache.CacheDisposable<T>
the consumer to add
consumer
)

Atomically adds the consumer to the observers copy-on-write array if the source has not yet terminated.

pack-priv long

Returns:

the number of currently cached event count
cachedEventCount
()

Returns the number of events currently cached.

pack-priv boolean

Returns:

true if the cache has observers
hasObservers
()

Returns true if there are observers subscribed to this observable.

pack-priv boolean

Returns:

true if already connected
isConnected
()

Check if this cached observable is connected to its source.

public void
onComplete()

Implements io.reactivex.rxjava3.core.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
public void
onNext(T
the item emitted by the Observable
t
)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Provides the Observer with a new item to observe.
public void
pack-priv void
remove(ObservableCache.CacheDisposable<T>
the consumer to remove
consumer
)

Atomically removes the consumer from the observers copy-on-write array.

pack-priv void
replay(ObservableCache.CacheDisposable<T>
the consumer to continue replaying items to
consumer
)

Replays the contents of this cache to the given consumer based on its current state and number of items requested by it.

protected void
subscribeActual(Observer<? super T> t)

Inherited from io.reactivex.rxjava3.internal.operators.observable.AbstractObservableWithUpstream:
source

Field Detail

capacityHintback to summary
pack-priv final int capacityHint

The number of items per cached nodes.

doneback to summary
pack-priv volatile boolean done

True if the source has terminated.

EMPTYback to summary
pack-priv static final ObservableCache.CacheDisposable<T>[] EMPTY

A shared instance of an empty array of observers to avoid creating a new empty array when all observers dispose.

Annotations
@SuppressWarnings:rawtypes
errorback to summary
pack-priv Throwable error

If observers is TERMINATED, this holds the terminal error if not null.

observersback to summary
pack-priv final AtomicReference<ObservableCache.CacheDisposable<T>[]> observers

The current known array of observer state to notify.

onceback to summary
pack-priv final AtomicBoolean once

The subscription to the source should happen at most once.

sizeback to summary
pack-priv volatile long size

The total number of elements in the list available for reads.

tailback to summary
pack-priv ObservableCache.Node<T> tail

The current tail of the linked structure holding the items.

tailOffsetback to summary
pack-priv int tailOffset

How many items have been put into the tail node so far.

TERMINATEDback to summary
pack-priv static final ObservableCache.CacheDisposable<T>[] TERMINATED

A shared instance indicating the source has no more events and there is no need to remember observers anymore.

Annotations
@SuppressWarnings:rawtypes

Constructor Detail

ObservableCacheback to summary
public ObservableCache(Observable<T> source, int capacityHint)

Constructs an empty, non-connected cache.

Parameters
source:Observable<T>

the source to subscribe to for the first incoming observer

capacityHint:int

the number of items expected (reduce allocation frequency)

Annotations
@SuppressWarnings:unchecked

Method Detail

addback to summary
pack-priv void add(ObservableCache.CacheDisposable<T> consumer)

Atomically adds the consumer to the observers copy-on-write array if the source has not yet terminated.

Parameters
consumer:ObservableCache.CacheDisposable<T>

the consumer to add

cachedEventCountback to summary
pack-priv long cachedEventCount()

Returns the number of events currently cached.

Returns:long

the number of currently cached event count

hasObserversback to summary
pack-priv boolean hasObservers()

Returns true if there are observers subscribed to this observable.

Returns:boolean

true if the cache has observers

isConnectedback to summary
pack-priv boolean isConnected()

Check if this cached observable is connected to its source.

Returns:boolean

true if already connected

onCompleteback to summary
public void onComplete()

Implements io.reactivex.rxjava3.core.Observer.onComplete.

Doc from io.reactivex.rxjava3.core.Observer.onComplete.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@SuppressWarnings:unchecked
@Override
onErrorback to summary
public void onError(Throwable t)
Annotations
@SuppressWarnings:unchecked
@Override
onNextback to summary
public void onNext(T t)

Implements io.reactivex.rxjava3.core.Observer.onNext.

Doc from io.reactivex.rxjava3.core.Observer.onNext.

Provides the Observer with a new item to observe.

The Observable may call this method 0 or more times.

The Observable will not call this method again after it calls either onComplete or onError.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Disposable d)
Annotations
@Override
removeback to summary
pack-priv void remove(ObservableCache.CacheDisposable<T> consumer)

Atomically removes the consumer from the observers copy-on-write array.

Parameters
consumer:ObservableCache.CacheDisposable<T>

the consumer to remove

Annotations
@SuppressWarnings:unchecked
replayback to summary
pack-priv void replay(ObservableCache.CacheDisposable<T> consumer)

Replays the contents of this cache to the given consumer based on its current state and number of items requested by it.

Parameters
consumer:ObservableCache.CacheDisposable<T>

the consumer to continue replaying items to

subscribeActualback to summary
protected void subscribeActual(Observer<? super T> t)
Annotations
@Override
io.reactivex.rxjava3.internal.operators.observable back to summary

pack-priv final Class ObservableCache.CacheDisposable<T>

extends AtomicInteger
implements Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable
Type Parameters
<T>
the value type

Hosts the downstream consumer and its current requested and replay states. this holds the work-in-progress counter for the serialized replay.

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv final Observer<? super T>
pack-priv long
pack-priv ObservableCache.Node<T>
pack-priv int
pack-priv final ObservableCache<T>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
CacheDisposable(Observer<? super T>
the actual consumer
downstream
,
ObservableCache<T>
the parent that holds onto the cached items
parent
)

Constructs a new instance with the actual downstream consumer and the parent cache object.

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
Inherited from java.util.concurrent.atomic.AtomicInteger:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

disposedback to summary
pack-priv volatile boolean disposed
downstreamback to summary
pack-priv final Observer<? super T> downstream
indexback to summary
pack-priv long index
nodeback to summary
pack-priv ObservableCache.Node<T> node
offsetback to summary
pack-priv int offset
parentback to summary
pack-priv final ObservableCache<T> parent
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicInteger.serialVersionUID.

Constructor Detail

CacheDisposableback to summary
pack-priv CacheDisposable(Observer<? super T> downstream, ObservableCache<T> parent)

Constructs a new instance with the actual downstream consumer and the parent cache object.

Parameters
downstream:Observer<? super T>

the actual consumer

parent:ObservableCache<T>

the parent that holds onto the cached items

Method Detail

disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
io.reactivex.rxjava3.internal.operators.observable back to summary

pack-priv final Class ObservableCache.Node<T>

extends Object
Class Inheritance
  • java.lang.Object
  • io.reactivex.rxjava3.internal.operators.observable.ObservableCache.Node
Type Parameters
<T>
the element type

Represents a segment of the cached item list as part of a linked-node-list structure.

Field Summary

Modifier and TypeField and Description
pack-priv volatile ObservableCache.Node<T>
next

The next node if not null.

pack-priv final T[]
values

The array of values held by this node.

Constructor Summary

AccessConstructor and Description
pack-priv
Node(int capacityHint)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextback to summary
pack-priv volatile ObservableCache.Node<T> next

The next node if not null.

valuesback to summary
pack-priv final T[] values

The array of values held by this node.

Constructor Detail

Nodeback to summary
pack-priv Node(int capacityHint)
Annotations
@SuppressWarnings:unchecked