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
&PublisherSource
whose outgoing signals to itsPublisherSource.Subscriber
s can be controlled.Behavior beyond simply delegating signals to the
PublisherSource.Subscriber
is accomplished by aFunction<Subscriber<? super T>, Subscriber<? super T>>
. ThisFunction
is invoked for everysubscribe(Subscriber)
invocation, and the result is used as the delegate for subsequentonSubscribe(Subscription)
,onNext(Object[])
,onComplete()
, andonError(Throwable)
calls. SeeTestPublisher.Builder
for 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 class
TestPublisher.Builder<T>
Allows for creatingTestPublisher
s 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 aTestPublisher
with the defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Handles a subscriber to thisPublisher
.boolean
isSubscribed()
void
onComplete()
Completes thePublisherSource.Subscriber
.void
onError(java.lang.Throwable t)
void
onNext(T... items)
Delivers theitems
, one at a time, to thePublisherSource.Subscriber
.void
onSubscribe(PublisherSource.Subscription subscription)
void
subscribe(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:
true
if thisTestPublisher
has been subscribed to,false
otherwise.
-
handleSubscribe
protected void handleSubscribe(PublisherSource.Subscriber<? super T> subscriber)
Description copied from class:Publisher
Handles a subscriber to thisPublisher
.- Specified by:
handleSubscribe
in classPublisher<T>
- Parameters:
subscriber
- the subscriber.
-
subscribe
public void subscribe(PublisherSource.Subscriber<? super T> subscriber)
Description copied from interface:PublisherSource
Subscribe for the result(s) of thisPublisherSource
.- Specified by:
subscribe
in interfacePublisherSource<T>
- Parameters:
subscriber
- to subscribe for the result.
-
onSubscribe
public void onSubscribe(PublisherSource.Subscription subscription)
Delivers thePublisherSource.Subscription
to thePublisherSource.Subscriber
'sPublisherSource.Subscriber.onSubscribe(Subscription)
.In the case of
auto-on-subscribe
, the delegatingPublisherSource.Subscription
sent to thePublisherSource.Subscriber
by 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)
-
-