Top Description Inners Fields Constructors Methods
rx.internal.operators

public final Class OperatorMerge<T>

extends Object
implements Observable.Operator<T, Observable<? extends T>>
Class Inheritance
All Implemented Interfaces
rx.Observable.Operator, rx.functions.Func1, rx.functions.Function
Type Parameters
<T>
the type of the items emitted by both the source and merged Observables
Imports
java.util.*, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.atomic.AtomicLong, rx.*, .Observable, .Observable.Operator, rx.exceptions.*, rx.internal.util.*, rx.internal.util.atomic.*, rx.internal.util.unsafe.*, rx.subscriptions.CompositeSubscription

Flattens a list of Observables into one Observable, without any transformation.

You can combine the items emitted by multiple Observables so that they act like a single Observable, by using the merge operation.

The instance(true) call behaves like OperatorMerge except that if any of the merged Observables notify of an error via onError, mergeDelayError will refrain from propagating that error notification until all of the merged Observables have finished emitting items.

Even if multiple merged Observables send onError notifications, mergeDelayError will only invoke the onError method of its Observers once.

This operation allows an Observer to receive all successfully emitted items from all of the source Observables without being interrupted by an error notification from one of them.

Note

If this is used on an Observable that never completes, it will never call onError and will effectively swallow errors.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
OperatorMerge.HolderDelayErrors

Lazy initialization via inner-class holder.

pack-priv static class
OperatorMerge.HolderNoDelay

Lazy initialization via inner-class holder.

pack-priv static class
pack-priv static class
pack-priv static class
OperatorMerge.MergeSubscriber<
the value type
T
>

The subscriber that observes Observables.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
OperatorMerge(boolean delayErrors, int maxConcurrent)

Method Summary

Modifier and TypeMethod and Description
public Subscriber<Observable<? extends T>>
call(final Subscriber<? super T> child)

Implements rx.functions.Func1.call.

public static <
the common value type
T
>
OperatorMerge<T>

Returns:

a singleton instance of this stateless operator.
instance
(boolean
should the merge delay errors?
delayErrors
)

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

Returns:

the Operator instance with the given settings
instance
(boolean
if true, errors are delayed till all sources terminate, if false the first error will be emitted and all sequences unsubscribed
delayErrors
,
int
the maximum number of concurrent subscriptions or Integer.MAX_VALUE for unlimited
maxConcurrent
)

Creates a new instance of the operator with the given delayError and maxConcurrency settings.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delayErrorsback to summary
pack-priv final boolean delayErrors
maxConcurrentback to summary
pack-priv final int maxConcurrent

Constructor Detail

OperatorMergeback to summary
pack-priv OperatorMerge(boolean delayErrors, int maxConcurrent)

Method Detail

callback to summary
public Subscriber<Observable<? extends T>> call(final Subscriber<? super T> child)

Implements rx.functions.Func1.call.

Annotations
@Override
instanceback to summary
public static <T> OperatorMerge<T> instance(boolean delayErrors)
Parameters
<T>
the common value type
delayErrors:boolean

should the merge delay errors?

Returns:OperatorMerge<T>

a singleton instance of this stateless operator.

Annotations
@SuppressWarnings:unchecked
instanceback to summary
public static <T> OperatorMerge<T> instance(boolean delayErrors, int maxConcurrent)

Creates a new instance of the operator with the given delayError and maxConcurrency settings.

Parameters
<T>
the value type
delayErrors:boolean

if true, errors are delayed till all sources terminate, if false the first error will be emitted and all sequences unsubscribed

maxConcurrent:int

the maximum number of concurrent subscriptions or Integer.MAX_VALUE for unlimited

Returns:OperatorMerge<T>

the Operator instance with the given settings

rx.internal.operators back to summary

pack-priv final Class OperatorMerge.HolderDelayErrors

extends Object
Class Inheritance

Lazy initialization via inner-class holder.

Field Summary

Modifier and TypeField and Description
pack-priv static final OperatorMerge<Object>
INSTANCE

A singleton instance.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final OperatorMerge<Object> INSTANCE

A singleton instance.

Constructor Detail

HolderDelayErrorsback to summary
pack-priv HolderDelayErrors()
rx.internal.operators back to summary

pack-priv final Class OperatorMerge.HolderNoDelay

extends Object
Class Inheritance

Lazy initialization via inner-class holder.

Field Summary

Modifier and TypeField and Description
pack-priv static final OperatorMerge<Object>
INSTANCE

A singleton instance.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final OperatorMerge<Object> INSTANCE

A singleton instance.

Constructor Detail

HolderNoDelayback to summary
pack-priv HolderNoDelay()
rx.internal.operators back to summary

pack-priv final Class OperatorMerge.InnerSubscriber<T>

extends Subscriber<T>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv final long
pack-priv static final int
pack-priv int
pack-priv final OperatorMerge.MergeSubscriber<T>
pack-priv volatile RxRingBuffer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
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
onStart()

Overrides rx.Subscriber.onStart.

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber.
public void
requestMore(long n)

Inherited from rx.Subscriber:
addisUnsubscribedrequestsetProducerunsubscribe

Field Detail

doneback to summary
pack-priv volatile boolean done
idback to summary
pack-priv final long id
LIMITback to summary
pack-priv static final int LIMIT
outstandingback to summary
pack-priv int outstanding
parentback to summary
pack-priv final OperatorMerge.MergeSubscriber<T> parent
queueback to summary
pack-priv volatile RxRingBuffer queue

Constructor Detail

InnerSubscriberback to summary
public InnerSubscriber(OperatorMerge.MergeSubscriber<T> parent, long id)

Method Detail

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
onStartback to summary
public void onStart()

Overrides rx.Subscriber.onStart.

Doc from rx.Subscriber.onStart.

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber. Override this method to add any useful initialization to your subscription, for instance to initiate backpressure.

Annotations
@Override
requestMoreback to summary
public void requestMore(long n)
rx.internal.operators back to summary

pack-priv final Class OperatorMerge.MergeProducer<T>

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

Field Summary

Modifier and TypeField and Description
private static final long
pack-priv final OperatorMerge.MergeSubscriber<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public long
produced(int n)

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.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

subscriberback to summary
pack-priv final OperatorMerge.MergeSubscriber<T> subscriber

Constructor Detail

MergeProducerback to summary
public MergeProducer(OperatorMerge.MergeSubscriber<T> subscriber)

Method Detail

producedback to summary
public long produced(int n)
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
rx.internal.operators back to summary

pack-priv final Class OperatorMerge.MergeSubscriber<T>

extends Subscriber<Observable<? extends T>>
Class Inheritance
Type Parameters
<T>
the value type

The subscriber that observes Observables.

Field Summary

Modifier and TypeField and Description
pack-priv final Subscriber<? super T>
pack-priv final boolean
pack-priv volatile boolean
pack-priv boolean
emitting

Guarded by this.

pack-priv static final OperatorMerge.InnerSubscriber<?>[]
EMPTY

An empty array to avoid creating new empty arrays in removeInner.

pack-priv volatile ConcurrentLinkedQueue<Throwable>
errors

Due to the emission loop, we need to store errors somewhere if !delayErrors.

pack-priv final Object
pack-priv volatile OperatorMerge.InnerSubscriber<?>[]
innerSubscribers

Copy-on-write array, guarded by innerGuard.

pack-priv long
lastId

Which was the last InnerSubscriber that emitted?

pack-priv int
lastIndex

What was its index in the innerSubscribers array?

pack-priv final int
pack-priv boolean
missed

Guarded by this.

pack-priv OperatorMerge.MergeProducer<T>
pack-priv volatile Queue<Object>
pack-priv int
pack-priv final int
pack-priv volatile CompositeSubscription
subscriptions

Hides rx.Subscriber.subscriptions.

Tracks the active subscriptions to sources.
pack-priv long
uniqueId

Used to generate unique InnerSubscriber IDs.

Constructor Summary

AccessConstructor and Description
public
MergeSubscriber(Subscriber<? super T> child, boolean delayErrors, int maxConcurrent)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv boolean

Returns:

true if the child unsubscribed or there are errors available and merge doesn't delay errors.
checkTerminate
()

Check if the operator reached some terminal state: child unsubscribed, an error was reported and we don't delay errors.

pack-priv void
emit()

pack-priv void
pack-priv void
emitLoop()

The standard emission loop serializing events and requests.

protected void
emitScalar(OperatorMerge.InnerSubscriber<T> subscriber, T value, long r)

protected void
emitScalar(T value, long r)

pack-priv CompositeSubscription
pack-priv Queue<Throwable>
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(Observable<? extends T>
the item emitted by the Observable
t
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
protected void
queueScalar(OperatorMerge.InnerSubscriber<T> subscriber, T value)

protected void
queueScalar(T value)

pack-priv void
private void
public void
requestMore(long n)

pack-priv void
tryEmit(OperatorMerge.InnerSubscriber<T>
the subscriber to one of the inner Observables running
subscriber
,
T
the value that inner Observable produced
value
)

Tries to emit the value directly to the child if no concurrent emission is happening at the moment.

pack-priv void
tryEmit(T
the scalar value the main Observable emitted through just()
value
)

Tries to emit the value directly to the child if no concurrent emission is happening at the moment.

Inherited from rx.Subscriber:
addisUnsubscribedonStartrequestsetProducerunsubscribe

Field Detail

childback to summary
pack-priv final Subscriber<? super T> child
delayErrorsback to summary
pack-priv final boolean delayErrors
doneback to summary
pack-priv volatile boolean done
emittingback to summary
pack-priv boolean emitting

Guarded by this.

EMPTYback to summary
pack-priv static final OperatorMerge.InnerSubscriber<?>[] EMPTY

An empty array to avoid creating new empty arrays in removeInner.

errorsback to summary
pack-priv volatile ConcurrentLinkedQueue<Throwable> errors

Due to the emission loop, we need to store errors somewhere if !delayErrors.

innerGuardback to summary
pack-priv final Object innerGuard
innerSubscribersback to summary
pack-priv volatile OperatorMerge.InnerSubscriber<?>[] innerSubscribers

Copy-on-write array, guarded by innerGuard.

lastIdback to summary
pack-priv long lastId

Which was the last InnerSubscriber that emitted? Accessed if emitting == true.

lastIndexback to summary
pack-priv int lastIndex

What was its index in the innerSubscribers array? Accessed if emitting == true.

maxConcurrentback to summary
pack-priv final int maxConcurrent
missedback to summary
pack-priv boolean missed

Guarded by this.

producerback to summary
pack-priv OperatorMerge.MergeProducer<T> producer

Hides rx.Subscriber.producer.

queueback to summary
pack-priv volatile Queue<Object> queue
scalarEmissionCountback to summary
pack-priv int scalarEmissionCount
scalarEmissionLimitback to summary
pack-priv final int scalarEmissionLimit
subscriptionsback to summary
pack-priv volatile CompositeSubscription subscriptions

Hides rx.Subscriber.subscriptions.

Tracks the active subscriptions to sources.

uniqueIdback to summary
pack-priv long uniqueId

Used to generate unique InnerSubscriber IDs. Modified from onNext only.

Constructor Detail

MergeSubscriberback to summary
public MergeSubscriber(Subscriber<? super T> child, boolean delayErrors, int maxConcurrent)

Method Detail

addInnerback to summary
pack-priv void addInner(OperatorMerge.InnerSubscriber<T> inner)
checkTerminateback to summary
pack-priv boolean checkTerminate()

Check if the operator reached some terminal state: child unsubscribed, an error was reported and we don't delay errors.

Returns:boolean

true if the child unsubscribed or there are errors available and merge doesn't delay errors.

emitback to summary
pack-priv void emit()
emitEmptyback to summary
pack-priv void emitEmpty()
emitLoopback to summary
pack-priv void emitLoop()

The standard emission loop serializing events and requests.

emitScalarback to summary
protected void emitScalar(OperatorMerge.InnerSubscriber<T> subscriber, T value, long r)
emitScalarback to summary
protected void emitScalar(T value, long r)
getOrCreateCompositeback to summary
pack-priv CompositeSubscription getOrCreateComposite()
getOrCreateErrorQueueback to summary
pack-priv Queue<Throwable> getOrCreateErrorQueue()
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(Observable<? extends 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:Observable<? extends T>

the item emitted by the Observable

Annotations
@Override
queueScalarback to summary
protected void queueScalar(OperatorMerge.InnerSubscriber<T> subscriber, T value)
queueScalarback to summary
protected void queueScalar(T value)
removeInnerback to summary
pack-priv void removeInner(OperatorMerge.InnerSubscriber<T> inner)
reportErrorback to summary
private void reportError()
requestMoreback to summary
public void requestMore(long n)
tryEmitback to summary
pack-priv void tryEmit(OperatorMerge.InnerSubscriber<T> subscriber, T value)

Tries to emit the value directly to the child if no concurrent emission is happening at the moment.

Since the scalar-value queue optimization applies to both the main source and the inner subscribers, we handle things in a shared manner.

Parameters
subscriber:OperatorMerge.InnerSubscriber<T>

the subscriber to one of the inner Observables running

value:T

the value that inner Observable produced

tryEmitback to summary
pack-priv void tryEmit(T value)

Tries to emit the value directly to the child if no concurrent emission is happening at the moment.

Since the scalar-value queue optimization applies to both the main source and the inner subscribers, we handle things in a shared manner.

Parameters
value:T

the scalar value the main Observable emitted through just()