Top Description Inners Fields Constructors Methods
rx.internal.operators

public final Class CachedObservable<T>

extends Observable<T>
Class Inheritance
Type Parameters
<T>
the source element type
Imports
java.util.concurrent.atomic.*, rx.*, rx.exceptions.*, rx.internal.util.LinkedArrayList, rx.subscriptions.SerialSubscription

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
CachedObservable.CachedSubscribe<
the value type emitted
T
>

Manages the subscription of child subscribers by setting up a replay producer and performs auto-connection of the very first subscription.

pack-priv static class
CachedObservable.CacheState<T>

Contains the active child producers and the values to replay.

pack-priv static class
CachedObservable.ReplayProducer<T>

Keeps track of the current request amount and the replay position for a child Subscriber.

Field Summary

Modifier and TypeField and Description
private final CachedObservable.CacheState<T>
state

The cache and replay state.

Constructor Summary

AccessConstructor and Description
private
CachedObservable(Observable.OnSubscribe<T>
the shared OnSubscribe implementation
onSubscribe
,
CachedObservable.CacheState<T>
the cache state object
state
)

Private constructor because state needs to be shared between the Observable body and the onSubscribe function.

Method Summary

Modifier and TypeMethod and Description
public static <
the value type
T
>
CachedObservable<T>

Returns:

the CachedObservable instance
from
(Observable<? extends T>
the source Observable to cache
source
)

Creates a cached Observable with a default capacity hint of 16.

public static <
the value type
T
>
CachedObservable<T>

Returns:

the CachedObservable instance
from
(Observable<? extends T>
the source Observable to cache
source
,
int
the hint for the internal buffer size
capacityHint
)

Creates a cached Observable with the given capacity hint.

pack-priv boolean

Returns:

true if this CachedObservable 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.

Inherited from rx.Observable:
allambambambambambambambambambambWithasObservablebufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbufferbuffercachecachecacheWithInitialCapacitycastcollectcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestcombineLatestDelayErrorcomposeconcatconcatconcatconcatconcatconcatconcatconcatconcatconcatconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatDelayErrorconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatEagerconcatMapconcatMapDelayErrorconcatMapEagerconcatMapEagerconcatMapEagerconcatMapIterableconcatWithcontainscountcountLongcreatecreatecreatecreatedebouncedebouncedebouncedefaultIfEmptydeferdelaydelaydelaydelaydelaySubscriptiondelaySubscriptiondelaySubscriptiondelaySubscriptiondematerializedistinctdistinctdistinctUntilChangeddistinctUntilChangeddistinctUntilChangeddoAfterTerminatedoOnCompleteddoOnEachdoOnEachdoOnErrordoOnNextdoOnRequestdoOnSubscribedoOnTerminatedoOnUnsubscribeelementAtelementAtOrDefaultemptyerrorexistsfilterfinallyDofirstfirstfirstOrDefaultfirstOrDefaultflatMapflatMapflatMapflatMapflatMapflatMapflatMapCompletableflatMapCompletableflatMapCompletableflatMapIterableflatMapIterableflatMapIterableflatMapIterableflatMapSingleflatMapSingleflatMapSingleforEachforEachforEachfromfromfromfromfromfromCallablegroupBygroupBygroupBygroupBygroupJoinignoreElementsintervalintervalintervalintervalisEmptyjoinjustjustjustjustjustjustjustjustjustjustlastlastlastOrDefaultlastOrDefaultliftlimitmapmaterializemergemergemergemergemergemergemergemergemergemergemergemergemergemergemergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeDelayErrormergeWithnestneverobserveOnobserveOnobserveOnobserveOnofTypeonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureBufferonBackpressureDroponBackpressureDroponBackpressureLatestonErrorResumeNextonErrorResumeNextonErrorReturnonExceptionResumeNextonTerminateDetachpublishpublishrangerangerebatchRequestsreducereducerepeatrepeatrepeatrepeatrepeatWhenrepeatWhenreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayreplayretryretryretryretryWhenretryWhensamplesamplesamplescanscansequenceEqualsequenceEqualserializesharesinglesinglesingleOrDefaultsingleOrDefaultskipskipskipskipLastskipLastskipLastskipUntilskipWhilesortedsortedstartWithstartWithstartWithstartWithstartWithstartWithstartWithstartWithstartWithstartWithstartWithsubscribesubscribesubscribesubscribesubscribesubscribesubscribeOnsubscribeOnswitchIfEmptyswitchMapswitchMapDelayErrorswitchOnNextswitchOnNextDelayErrortaketaketaketakeFirsttakeLasttakeLasttakeLasttakeLasttakeLasttakeLastBuffertakeLastBuffertakeLastBuffertakeLastBuffertakeLastBuffertakeUntiltakeUntiltakeWhiletesttestthrottleFirstthrottleFirstthrottleLastthrottleLastthrottleWithTimeoutthrottleWithTimeouttimeIntervaltimeIntervaltimeouttimeouttimeouttimeouttimeouttimeouttimeouttimeouttimertimertimertimertimestamptimestamptotoBlockingtoCompletabletoListtoMaptoMaptoMaptoMultimaptoMultimaptoMultimaptoMultimaptoSingletoSortedListtoSortedListtoSortedListtoSortedListunsafeCreateunsafeSubscribeunsubscribeOnusingusingwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwindowwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromwithLatestFromzipzipzipzipzipzipzipzipzipzipzipzipWithzipWith

Field Detail

stateback to summary
private final CachedObservable.CacheState<T> state

The cache and replay state.

Constructor Detail

CachedObservableback to summary
private CachedObservable(Observable.OnSubscribe<T> onSubscribe, CachedObservable.CacheState<T> state)

Private constructor because state needs to be shared between the Observable body and the onSubscribe function.

Parameters
onSubscribe:Observable.OnSubscribe<T>

the shared OnSubscribe implementation

state:CachedObservable.CacheState<T>

the cache state object

Method Detail

fromback to summary
public static <T> CachedObservable<T> from(Observable<? extends T> source)

Creates a cached Observable with a default capacity hint of 16.

Parameters
<T>
the value type
source:Observable<? extends T>

the source Observable to cache

Returns:CachedObservable<T>

the CachedObservable instance

Annotations
@SuppressWarnings:cast
fromback to summary
public static <T> CachedObservable<T> from(Observable<? extends T> source, int capacityHint)

Creates a cached Observable with the given capacity hint.

Parameters
<T>
the value type
source:Observable<? extends T>

the source Observable to cache

capacityHint:int

the hint for the internal buffer size

Returns:CachedObservable<T>

the CachedObservable instance

hasObserversback to summary
pack-priv boolean hasObservers()

Returns true if there are observers subscribed to this observable.

Returns:boolean

true if this CachedObservable 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

rx.internal.operators back to summary

pack-priv final Class CachedObservable.CachedSubscribe<T>

extends AtomicBoolean
implements Observable.OnSubscribe<T>
Class Inheritance
All Implemented Interfaces
rx.Observable.OnSubscribe, rx.functions.Action1, rx.functions.Action, rx.functions.Function
Type Parameters
<T>
the value type emitted

Manages the subscription of child subscribers by setting up a replay producer and performs auto-connection of the very first subscription.

Field Summary

Modifier and TypeField and Description
private static final long
pack-priv final CachedObservable.CacheState<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
call(Subscriber<? super T> t)

Implements rx.functions.Action1.call.

Inherited from java.util.concurrent.atomic.AtomicBoolean:
compareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndSetgetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicBoolean.serialVersionUID.

stateback to summary
pack-priv final CachedObservable.CacheState<T> state

Constructor Detail

CachedSubscribeback to summary
public CachedSubscribe(CachedObservable.CacheState<T> state)

Method Detail

callback to summary
public void call(Subscriber<? super T> t)

Implements rx.functions.Action1.call.

Annotations
@Override
rx.internal.operators back to summary

pack-priv final Class CachedObservable.CacheState<T>

extends LinkedArrayList
implements Observer<T>
Class Inheritance
All Implemented Interfaces
rx.Observer

Contains the active child producers and the values to replay.

Field Summary

Modifier and TypeField and Description
pack-priv final SerialSubscription
connection

Holds onto the subscriber connected to source.

pack-priv static final CachedObservable.ReplayProducer<?>[]
EMPTY

The default empty array of producers.

pack-priv volatile boolean
isConnected

Set to true after connection.

pack-priv volatile CachedObservable.ReplayProducer<?>[]
producers

Guarded by connection (not this).

pack-priv final Observable<? extends T>
source

The source observable to connect to.

pack-priv boolean
sourceDone

Indicates that the source has completed emitting values or the Observable was forcefully terminated.

Constructor Summary

AccessConstructor and Description
public
CacheState(Observable<? extends T> source, int capacityHint)

Method Summary

Modifier and TypeMethod and Description
public void
addProducer(CachedObservable.ReplayProducer<T>
the downstream consumer's associated Producer instance
p
)

Adds a ReplayProducer to the producers array atomically.

public void
connect()

Connects the cache to the source.

pack-priv void
dispatch()

Signals all known children there is work to do.

public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
e
)

Implements rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
t
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
public void
removeProducer(CachedObservable.ReplayProducer<T>
the downstream consumer's associated Producer instance
p
)

Removes the ReplayProducer (if present) from the producers array atomically.

Inherited from rx.internal.util.LinkedArrayList:
addcapacityHintheadindexInTailsizetailtoString

Field Detail

connectionback to summary
pack-priv final SerialSubscription connection

Holds onto the subscriber connected to source.

EMPTYback to summary
pack-priv static final CachedObservable.ReplayProducer<?>[] EMPTY

The default empty array of producers.

isConnectedback to summary
pack-priv volatile boolean isConnected

Set to true after connection.

producersback to summary
pack-priv volatile CachedObservable.ReplayProducer<?>[] producers

Guarded by connection (not this).

sourceback to summary
pack-priv final Observable<? extends T> source

The source observable to connect to.

sourceDoneback to summary
pack-priv boolean sourceDone

Indicates that the source has completed emitting values or the Observable was forcefully terminated.

Constructor Detail

CacheStateback to summary
public CacheState(Observable<? extends T> source, int capacityHint)

Method Detail

addProducerback to summary
public void addProducer(CachedObservable.ReplayProducer<T> p)

Adds a ReplayProducer to the producers array atomically.

Parameters
p:CachedObservable.ReplayProducer<T>

the downstream consumer's associated Producer instance

connectback to summary
public void connect()

Connects the cache to the source. Make sure this is called only once.

dispatchback to summary
pack-priv void dispatch()

Signals all known children there is work to do.

onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Doc from rx.Observer.onCompleted.

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

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

Annotations
@Override
onErrorback to summary
public void onError(Throwable e)

Implements rx.Observer.onError.

Doc from rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onCompleted.

Parameters
e:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements rx.Observer.onNext.

Doc from rx.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 onCompleted or onError.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override
removeProducerback to summary
public void removeProducer(CachedObservable.ReplayProducer<T> p)

Removes the ReplayProducer (if present) from the producers array atomically.

Parameters
p:CachedObservable.ReplayProducer<T>

the downstream consumer's associated Producer instance

rx.internal.operators back to summary

pack-priv final Class CachedObservable.ReplayProducer<T>

extends AtomicLong
implements Producer, Subscription
Class Inheritance
All Implemented Interfaces
rx.Subscription, rx.Producer

Keeps track of the current request amount and the replay position for a child Subscriber.

Field Summary

Modifier and TypeField and Description
pack-priv final Subscriber<? super T>
child

The actual child subscriber.

pack-priv Object[]
currentBuffer

Contains the reference to the buffer segment in replay.

pack-priv int
currentIndexInBuffer

Contains the index into the currentBuffer where the next value is expected.

pack-priv boolean
emitting

Indicates there is a replay going on; guarded by this.

pack-priv int
index

Contains the absolute index up until the values have been replayed so far.

pack-priv boolean
missed

Indicates there were some state changes/replay attempts; guarded by this.

private static final long
pack-priv final CachedObservable.CacheState<T>
state

The cache state object.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
public long

Returns:

the latest request amount after subtracting n
produced
(long
the produced item count, positive, not validated
n
)

Updates the request count to reflect values have been produced.

public void
replay()

Continue replaying available values if there are requests for them.

public void
request(long
the maximum number of items you want this Producer to produce, or Long.MAX_VALUE if you want the Producer to produce items at its own pace
n
)

Implements rx.Producer.request.

Request a certain maximum number of items from this Producer.
public void
unsubscribe()

Implements rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

childback to summary
pack-priv final Subscriber<? super T> child

The actual child subscriber.

currentBufferback to summary
pack-priv Object[] currentBuffer

Contains the reference to the buffer segment in replay. Accessed after reading state.size() and when emitting == true.

currentIndexInBufferback to summary
pack-priv int currentIndexInBuffer

Contains the index into the currentBuffer where the next value is expected. Accessed after reading state.size() and when emitting == true.

emittingback to summary
pack-priv boolean emitting

Indicates there is a replay going on; guarded by this.

indexback to summary
pack-priv int index

Contains the absolute index up until the values have been replayed so far.

missedback to summary
pack-priv boolean missed

Indicates there were some state changes/replay attempts; guarded by this.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicLong.serialVersionUID.

stateback to summary
pack-priv final CachedObservable.CacheState<T> state

The cache state object.

Constructor Detail

ReplayProducerback to summary
public ReplayProducer(Subscriber<? super T> child, CachedObservable.CacheState<T> state)

Method Detail

isUnsubscribedback to summary
public boolean isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Doc from rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.

Returns:boolean

true if this Subscription is currently unsubscribed, false otherwise

Annotations
@Override
producedback to summary
public long produced(long n)

Updates the request count to reflect values have been produced.

Parameters
n:long

the produced item count, positive, not validated

Returns:long

the latest request amount after subtracting n

replayback to summary
public void replay()

Continue replaying available values if there are requests for them.

requestback to summary
public void request(long n)

Implements rx.Producer.request.

Doc from rx.Producer.request.

Request a certain maximum number of items from this Producer. This is a way of requesting backpressure. To disable backpressure, pass Long.MAX_VALUE to this method.

Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example, the code below may result in Long.MAX_VALUE requests being actioned only.

request(100);
request(Long.MAX_VALUE-1);
Parameters
n:long

the maximum number of items you want this Producer to produce, or Long.MAX_VALUE if you want the Producer to produce items at its own pace

Annotations
@Override
unsubscribeback to summary
public void unsubscribe()

Implements rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

This allows deregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

Annotations
@Override