Top Description Inners Fields Constructors Methods
rx.subjects

public final Class UnicastSubject<T>

extends Subject<T, T>
Class Inheritance
Type Parameters
<T>
the input and output value type
Imports
java.util.Queue, java.util.concurrent.atomic.*, rx.*, rx.exceptions.*, rx.functions.Action0, rx.internal.operators.*, rx.internal.util.atomic.*, rx.internal.util.unsafe.*

A Subject variant which buffers events until a single Subscriber arrives and replays them to it and potentially switches to direct delivery once the Subscriber caught up and requested an unlimited amount. In this case, the buffered values are no longer retained. If the Subscriber requests a limited amount, queueing is involved and only those values are retained which weren't requested by the Subscriber at that time.

Since
1.3

Nested and Inner Type Summary

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

The single-consumption replaying state.

Field Summary

Modifier and TypeField and Description
pack-priv final UnicastSubject.State<T>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the input and output value type
T
>
UnicastSubject<T>

Returns:

the created UnicastSubject instance
create
()

Constructs an empty UnicastSubject instance with the default capacity hint of 16 elements.

public static <
the input and output value type
T
>
UnicastSubject<T>

Returns:

the created BufferUntilSubscriber instance
create
(int
the capacity hint for the internal queue
capacityHint
)

Constructs an empty UnicastSubject instance with a capacity hint.

public static <
the input and output value type
T
>
UnicastSubject<T>

Returns:

the created UnicastSubject instance
create
(boolean
deliver pending next events before error.
delayError
)

Constructs an empty UnicastSubject instance with the default capacity hint of 16 elements.

public static <
the input and output value type
T
>
UnicastSubject<T>

Returns:

the created BufferUntilSubscriber instance
create
(int
the capacity hint for the internal queue
capacityHint
,
Action0
the optional callback to call when subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence. It will be called at most once.
onTerminated
)

Constructs an empty UnicastSubject instance with a capacity hint and an Action0 instance to call if the subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence.

public static <
the input and output value type
T
>
UnicastSubject<T>

Returns:

the created BufferUntilSubscriber instance
create
(int
the capacity hint for the internal queue
capacityHint
,
Action0
the optional callback to call when subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence. It will be called at most once.
onTerminated
,
boolean
flag indicating whether to deliver pending next events before error.
delayError
)

Constructs an empty UnicastSubject instance with a capacity hint, delay error flag and Action0 instance to call if the subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence.

public boolean
hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.
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.
Inherited from rx.subjects.Subject:
toSerialized

Field Detail

stateback to summary
pack-priv final UnicastSubject.State<T> state

Constructor Detail

UnicastSubjectback to summary
private UnicastSubject(UnicastSubject.State<T> state)

Method Detail

createback to summary
public static <T> UnicastSubject<T> create()

Constructs an empty UnicastSubject instance with the default capacity hint of 16 elements.

Parameters
<T>
the input and output value type
Returns:UnicastSubject<T>

the created UnicastSubject instance

createback to summary
public static <T> UnicastSubject<T> create(int capacityHint)

Constructs an empty UnicastSubject instance with a capacity hint.

The capacity hint determines the internal queue's island size: the larger it is the less frequent allocation will happen if there is no subscriber or the subscriber hasn't caught up.

Parameters
<T>
the input and output value type
capacityHint:int

the capacity hint for the internal queue

Returns:UnicastSubject<T>

the created BufferUntilSubscriber instance

createback to summary
public static <T> UnicastSubject<T> create(boolean delayError)

Constructs an empty UnicastSubject instance with the default capacity hint of 16 elements.

Parameters
<T>
the input and output value type
delayError:boolean

deliver pending next events before error.

Returns:UnicastSubject<T>

the created UnicastSubject instance

createback to summary
public static <T> UnicastSubject<T> create(int capacityHint, Action0 onTerminated)

Constructs an empty UnicastSubject instance with a capacity hint and an Action0 instance to call if the subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence.

The capacity hint determines the internal queue's island size: the larger it is the less frequent allocation will happen if there is no subscriber or the subscriber hasn't caught up.

Parameters
<T>
the input and output value type
capacityHint:int

the capacity hint for the internal queue

onTerminated:Action0

the optional callback to call when subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence. It will be called at most once.

Returns:UnicastSubject<T>

the created BufferUntilSubscriber instance

createback to summary
public static <T> UnicastSubject<T> create(int capacityHint, Action0 onTerminated, boolean delayError)

Constructs an empty UnicastSubject instance with a capacity hint, delay error flag and Action0 instance to call if the subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence.

The capacity hint determines the internal queue's island size: the larger it is the less frequent allocation will happen if there is no subscriber or the subscriber hasn't caught up.

Parameters
<T>
the input and output value type
capacityHint:int

the capacity hint for the internal queue

onTerminated:Action0

the optional callback to call when subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence. It will be called at most once.

delayError:boolean

flag indicating whether to deliver pending next events before error.

Returns:UnicastSubject<T>

the created BufferUntilSubscriber instance

hasObserversback to summary
public boolean hasObservers()

Implements abstract rx.subjects.Subject.hasObservers.

Doc from rx.subjects.Subject.hasObservers.

Indicates whether the Subject has Observers subscribed to it.

Returns:boolean

true if there is at least one Observer subscribed to this Subject, false otherwise

Annotations
@Override
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
rx.subjects back to summary

pack-priv final Class UnicastSubject.State<T>

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

The single-consumption replaying state.

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
caughtUp

Indicates the queue can be bypassed because the child has caught up with the replay.

pack-priv final boolean
delayError

Deliver pending next events before error.

pack-priv volatile boolean
done

Indicates the source has terminated.

pack-priv boolean
emitting

Emitter loop: emitting indicator.

pack-priv Throwable
error

In case the source emitted an error.

pack-priv boolean
missed

Emitter loop: missed emission indicator.

pack-priv final Queue<Object>
queue

The queue holding values until the subscriber arrives and catches up.

private static final long
pack-priv final AtomicReference<Subscriber<? super T>>
subscriber

The single subscriber.

pack-priv final AtomicReference<Action0>
terminateOnce

Atomically set to true on terminal condition.

Constructor Summary

AccessConstructor and Description
public
State(int
indicates how large each island in the Spsc queue should be to reduce allocation frequency
capacityHint
,
boolean
deliver pending next events before error.
delayError
,
Action0
the action to call when the subject reaches its terminal state or the single subscriber unsubscribes.
onTerminated
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
call(Subscriber<? super T>
the incoming Subscriber instance, not null
subscriber
)

Implements rx.functions.Action1.call.

Tries to set the given subscriber if not already set, sending an IllegalStateException to the subscriber otherwise.
pack-priv boolean

Returns:

true if this Subject reached a terminal state and the drain loop should quit
checkTerminated
(boolean
indicates the source has called onCompleted
done
,
boolean
indicates if there are no more source values in the queue
empty
,
boolean
indicates whether to deliver pending next events before error
delayError
,
Subscriber<? super T>
the target Subscriber to emit events to
s
)

Checks if one of the terminal conditions have been met: child unsubscribed, an error happened or the source terminated and the queue is empty

pack-priv void
doTerminate()

Call the optional termination action at most once.

public boolean
isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
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.
pack-priv void
replay()

Tries to replay the contents of the queue.

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.

Terminates the state by setting the done flag and tries to clear the queue.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

caughtUpback to summary
pack-priv volatile boolean caughtUp

Indicates the queue can be bypassed because the child has caught up with the replay.

delayErrorback to summary
pack-priv final boolean delayError

Deliver pending next events before error.

doneback to summary
pack-priv volatile boolean done

Indicates the source has terminated.

emittingback to summary
pack-priv boolean emitting

Emitter loop: emitting indicator. Guarded by this.

errorback to summary
pack-priv Throwable error

In case the source emitted an error.

missedback to summary
pack-priv boolean missed

Emitter loop: missed emission indicator. Guarded by this.

queueback to summary
pack-priv final Queue<Object> queue

The queue holding values until the subscriber arrives and catches up.

serialVersionUIDback to summary
private static final long serialVersionUID

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

subscriberback to summary
pack-priv final AtomicReference<Subscriber<? super T>> subscriber

The single subscriber.

terminateOnceback to summary
pack-priv final AtomicReference<Action0> terminateOnce

Atomically set to true on terminal condition.

Constructor Detail

Stateback to summary
public State(int capacityHint, boolean delayError, Action0 onTerminated)

Constructor.

Parameters
capacityHint:int

indicates how large each island in the Spsc queue should be to reduce allocation frequency

delayError:boolean

deliver pending next events before error.

onTerminated:Action0

the action to call when the subject reaches its terminal state or the single subscriber unsubscribes.

Method Detail

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

Implements rx.functions.Action1.call.

Tries to set the given subscriber if not already set, sending an IllegalStateException to the subscriber otherwise.

Parameters
subscriber:Subscriber<? super T>

the incoming Subscriber instance, not null

Annotations
@Override
checkTerminatedback to summary
pack-priv boolean checkTerminated(boolean done, boolean empty, boolean delayError, Subscriber<? super T> s)

Checks if one of the terminal conditions have been met: child unsubscribed, an error happened or the source terminated and the queue is empty

Parameters
done:boolean

indicates the source has called onCompleted

empty:boolean

indicates if there are no more source values in the queue

delayError:boolean

indicates whether to deliver pending next events before error

s:Subscriber<? super T>

the target Subscriber to emit events to

Returns:boolean

true if this Subject reached a terminal state and the drain loop should quit

doTerminateback to summary
pack-priv void doTerminate()

Call the optional termination action at most once.

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
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
replayback to summary
pack-priv void replay()

Tries to replay the contents of the queue.

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.

Terminates the state by setting the done flag and tries to clear the queue. Should be called only when the child unsubscribes

Annotations
@Override