Class RecordingSubscriber<T>
- java.lang.Object
-
- com.oracle.coherence.concurrent.executor.subscribers.RecordingSubscriber<T>
-
- Type Parameters:
T- the type of result received
- All Implemented Interfaces:
Task.Subscriber<T>
public class RecordingSubscriber<T> extends Object implements Task.Subscriber<T>
ATask.Subscriberthat records iteration with aTask.Coordinator.- Author:
- bo
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBooleanf_fCompletedCompleted flag.protected AtomicBooleanf_fErroredError flag.protected AtomicBooleanf_fUsedTracks whether thisRecordingSubscriberhas ever been subscribed to aTask.Coordinator.protected CopyOnWriteArrayList<T>f_listItemsItems received by this subscriber.protected AtomicReference<Task.Subscription<? extends T>>f_subscriptionTheTask.Subscription.protected AtomicReference<Throwable>f_throwableFailure cause.
-
Constructor Summary
Constructors Constructor Description RecordingSubscriber()Constructs aRecordingSubscriber.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TgetFirst()Returns the first item that was received the by theTask.Subscriber.TgetLast()Returns the last item that was received the by theTask.Subscriber.ThrowablegetThrowable()booleanisCompleted()Determines if theRecordingSubscriberwas completed by aTask.Coordinator.booleanisError()Determines if theRecordingSubscriberwas published an error by aTask.Coordinator.booleanisSubscribed()Determines if theRecordingSubscriberhas been subscribed to aTask.Coordinator.voidonComplete()Invoked by aTask.Coordinatorwhen it is known that no additionalTask.Subscribermethod invocations will occur or has already been terminated by an error.voidonError(Throwable throwable)Invoked by aTask.Coordinatorwhen an unrecoverable error was encountered, after which no otherTask.Subscribermethods are invoked.voidonNext(T item)Invoked when aTask.Coordinatorhas produced an item for consumption.voidonSubscribe(Task.Subscription<? extends T> subscription)Invoked prior to theTask.SubscribermethodsTask.Subscriber.onComplete(),Task.Subscriber.onError(Throwable)andTask.Subscriber.onNext(Object)being invoked for aTask.Subscriptionto aTask.Coordinator.booleanreceived(T item)Determines if the specified item was received.intsize()Determines the number of items theRecordingSubscriberhas received.
-
-
-
Field Detail
-
f_fUsed
protected final AtomicBoolean f_fUsed
Tracks whether thisRecordingSubscriberhas ever been subscribed to aTask.Coordinator.RecordingSubscribers are not reusable.
-
f_fCompleted
protected final AtomicBoolean f_fCompleted
Completed flag.
-
f_fErrored
protected final AtomicBoolean f_fErrored
Error flag.
-
f_throwable
protected final AtomicReference<Throwable> f_throwable
Failure cause.
-
f_listItems
protected final CopyOnWriteArrayList<T> f_listItems
Items received by this subscriber.
-
f_subscription
protected final AtomicReference<Task.Subscription<? extends T>> f_subscription
TheTask.Subscription.
-
-
Constructor Detail
-
RecordingSubscriber
public RecordingSubscriber()
Constructs aRecordingSubscriber.
-
-
Method Detail
-
onComplete
public void onComplete()
Description copied from interface:Task.SubscriberInvoked by aTask.Coordinatorwhen it is known that no additionalTask.Subscribermethod invocations will occur or has already been terminated by an error.After this method is invoked no other
Task.Subscribermethods will be called.If this method throws an exception, the
Task.Subscriberwill be closed.- Specified by:
onCompletein interfaceTask.Subscriber<T>
-
onError
public void onError(Throwable throwable)
Description copied from interface:Task.SubscriberInvoked by aTask.Coordinatorwhen an unrecoverable error was encountered, after which no otherTask.Subscribermethods are invoked.If this method throws an exception, the
Task.Subscriberwill be closed.- Specified by:
onErrorin interfaceTask.Subscriber<T>- Parameters:
throwable- the error
-
onNext
public void onNext(T item)
Description copied from interface:Task.SubscriberInvoked when aTask.Coordinatorhas produced an item for consumption.If this method throws an exception, the
Task.Subscriberwill be closed.- Specified by:
onNextin interfaceTask.Subscriber<T>- Parameters:
item- the item (possiblynull)
-
onSubscribe
public void onSubscribe(Task.Subscription<? extends T> subscription)
Description copied from interface:Task.SubscriberInvoked prior to theTask.SubscribermethodsTask.Subscriber.onComplete(),Task.Subscriber.onError(Throwable)andTask.Subscriber.onNext(Object)being invoked for aTask.Subscriptionto aTask.Coordinator.- Specified by:
onSubscribein interfaceTask.Subscriber<T>- Parameters:
subscription- theTask.Subscription
-
isError
public boolean isError()
Determines if theRecordingSubscriberwas published an error by aTask.Coordinator.- Returns:
trueifonError(Throwable)was invokedfalseotherwise
-
isCompleted
public boolean isCompleted()
Determines if theRecordingSubscriberwas completed by aTask.Coordinator.- Returns:
trueifonComplete()was invoked,falseotherwise
-
isSubscribed
public boolean isSubscribed()
Determines if theRecordingSubscriberhas been subscribed to aTask.Coordinator.- Returns:
trueif theRecordingSubscriberhas been subscribed,falseotherwise
-
received
public boolean received(T item)
Determines if the specified item was received.- Parameters:
item- the item- Returns:
trueif the item has been received,falseotherwise
-
getFirst
public T getFirst()
Returns the first item that was received the by theTask.Subscriber.- Returns:
- the first item or
nullif no items have been received
-
getLast
public T getLast()
Returns the last item that was received the by theTask.Subscriber.- Returns:
- the last item or
nullif no items have been received
-
size
public int size()
Determines the number of items theRecordingSubscriberhas received.- Returns:
- the number of items
-
-