Package io.servicetalk.concurrent.api
Class TestPublisher<T>
- java.lang.Object
-
- io.servicetalk.concurrent.api.Publisher<T>
-
- io.servicetalk.concurrent.api.TestPublisher<T>
-
- Type Parameters:
T- Type of the items emitted by thisTestPublisher.
- All Implemented Interfaces:
PublisherSource<T>
public final class TestPublisher<T> extends Publisher<T> implements PublisherSource<T>
APublisher&PublisherSourcewhose outgoing signals to itsPublisherSource.Subscribers can be controlled.Behavior beyond simply delegating signals to the
PublisherSource.Subscriberis accomplished by aFunction<Subscriber<? super T>, Subscriber<? super T>>. ThisFunctionis invoked for everysubscribe(Subscriber)invocation, and the result is used as the delegate for subsequentonSubscribe(Subscription),onNext(Object[]),onComplete(), andonError(Throwable)calls. SeeTestPublisher.Builderfor more information.Defaults
- Allows sequential but not concurrent subscribers.
- Asserts that
onNext(Object[])is not called without sufficient demand. - Sends
onSubscribe(Subscription)automatically when subscribed to.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTestPublisher.Builder<T>Allows for creatingTestPublishers with non-default settings.-
Nested classes/interfaces inherited from interface io.servicetalk.concurrent.PublisherSource
PublisherSource.Processor<T,R>, PublisherSource.Subscriber<T>, PublisherSource.Subscription
-
-
Constructor Summary
Constructors Constructor Description TestPublisher()Create aTestPublisherwith the defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidhandleSubscribe(PublisherSource.Subscriber<? super T> subscriber)Handles a subscriber to thisPublisher.booleanisSubscribed()voidonComplete()Completes thePublisherSource.Subscriber.voidonError(java.lang.Throwable t)voidonNext(T... items)Delivers theitems, one at a time, to thePublisherSource.Subscriber.voidonSubscribe(PublisherSource.Subscription subscription)voidsubscribe(PublisherSource.Subscriber<? super T> subscriber)Subscribe for the result(s) of thisPublisherSource.-
Methods inherited from class io.servicetalk.concurrent.api.Publisher
afterCancel, afterFinally, afterFinally, afterOnComplete, afterOnError, afterOnNext, afterOnSubscribe, afterRequest, afterSubscriber, afterSubscription, beforeCancel, beforeFinally, beforeFinally, beforeOnComplete, beforeOnError, beforeOnNext, beforeOnSubscribe, beforeRequest, beforeSubscriber, beforeSubscription, buffer, collect, completableOrError, concat, concat, concat, defer, empty, failed, filter, firstOrElse, firstOrError, flatMapCompletable, flatMapCompletable, flatMapCompletableDelayError, flatMapCompletableDelayError, flatMapCompletableDelayError, flatMapConcatIterable, flatMapMerge, flatMapMerge, flatMapMergeDelayError, flatMapMergeDelayError, flatMapMergeDelayError, flatMapMergeSingle, flatMapMergeSingle, flatMapMergeSingleDelayError, flatMapMergeSingleDelayError, flatMapMergeSingleDelayError, forEach, from, from, fromBlockingIterable, fromInputStream, fromIterable, groupBy, groupBy, groupToMany, groupToMany, idleTimeout, idleTimeout, idleTimeout, idleTimeout, ignoreElements, liftAsync, liftSync, liftSyncToSingle, map, multicastToExactly, multicastToExactly, never, publishAndSubscribeOn, publishAndSubscribeOnOverride, publishOn, publishOnOverride, range, range, recoverWith, repeat, repeatWhen, retry, retryWhen, scanWith, scanWith, subscribeInternal, subscribeOn, subscribeOnOverride, subscribeShareContext, takeAtMost, takeUntil, takeWhile, toCompletionStage, toCompletionStage, toFuture, toFuture, toInputStream, toInputStream, toIterable, toIterable, whenCancel, whenFinally, whenFinally, whenOnComplete, whenOnError, whenOnNext, whenOnSubscribe, whenRequest, whenSubscriber, whenSubscription
-
-
-
-
Method Detail
-
isSubscribed
public boolean isSubscribed()
- Returns:
trueif thisTestPublisherhas been subscribed to,falseotherwise.
-
handleSubscribe
protected void handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Description copied from class:PublisherHandles a subscriber to thisPublisher.- Specified by:
handleSubscribein classPublisher<T>- Parameters:
subscriber- the subscriber.
-
subscribe
public void subscribe(PublisherSource.Subscriber<? super T> subscriber)
Description copied from interface:PublisherSourceSubscribe for the result(s) of thisPublisherSource.- Specified by:
subscribein interfacePublisherSource<T>- Parameters:
subscriber- to subscribe for the result.
-
onSubscribe
public void onSubscribe(PublisherSource.Subscription subscription)
Delivers thePublisherSource.Subscriptionto thePublisherSource.Subscriber'sPublisherSource.Subscriber.onSubscribe(Subscription).In the case of
auto-on-subscribe, the delegatingPublisherSource.Subscriptionsent to thePublisherSource.Subscriberby the auto-on-subscribe will switch tosubscription.- Parameters:
subscription- thePublisherSource.Subscription
-
onNext
@SafeVarargs public final void onNext(@Nullable T... items)Delivers theitems, one at a time, to thePublisherSource.Subscriber.- Parameters:
items- the items to deliver.- See Also:
PublisherSource.Subscriber.onNext(Object)
-
onComplete
public void onComplete()
Completes thePublisherSource.Subscriber.- See Also:
PublisherSource.Subscriber.onComplete()
-
onError
public void onError(java.lang.Throwable t)
- Parameters:
t- the error to deliver.- See Also:
PublisherSource.Subscriber.onError(Throwable)
-
-