- java.lang.Object
-
- io.helidon.common.reactive.EmittingPublisher<T>
-
- Type Parameters:
T- type of emitted item
- All Implemented Interfaces:
Flow.Publisher<T>
public class EmittingPublisher<T> extends Object implements Flow.Publisher<T>
Emitting publisher for manual publishing on the same thread.EmittingPublisherdoesn't have any buffering capability and propagates backpressure directly by returningfalsefromemit(Object)in case there is no demand, orcancelsignal has been received.For publishing with buffering in case of backpressure use
BufferedEmittingPublisher.This publisher allows only a single subscriber.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcomplete()Properly complete the stream, set publisher to completed state and sendonCompletesignal downstream.static <T> EmittingPublisher<T>create()Create newEmittingPublisher.booleanemit(T item)Emit one item to the stream, if there is enough requested and publisher is not cancelled, item is signaled to downstream asonNextand method returns true.voidfail(Throwable throwable)Properly fail the stream, set publisher to cancelled state and sendonErrorsignal downstream.Optional<Throwable>failCause()Return cause of fail, if publisher is in failed state.booleanhasRequests()Check if demand is higher than 0.booleanisCancelled()Check if publisher has been cancelled.booleanisCompleted()Check if publisher has been completed.booleanisFailed()Check if publisher has been failed.booleanisUnbounded()Check if downstream requested unbounded number of items, eg.voidonCancel(Runnable cancelCallback)Executed when cancel signal from downstream arrive.voidonRequest(BiConsumer<Long,Long> requestCallback)Callback executed when request signal from downstream arrive.voidsubscribe(Flow.Subscriber<? super T> subscriber)
-
-
-
Method Detail
-
create
public static <T> EmittingPublisher<T> create()
Create newEmittingPublisher.- Type Parameters:
T- type of emitted item- Returns:
- brand new
EmittingPublisher
-
subscribe
public void subscribe(Flow.Subscriber<? super T> subscriber)
- Specified by:
subscribein interfaceFlow.Publisher<T>
-
fail
public void fail(Throwable throwable)
Properly fail the stream, set publisher to cancelled state and sendonErrorsignal downstream. SignalonErroris sent only once, any other call to this method is no-op.- Parameters:
throwable- Sent asonErrorsignal
-
complete
public void complete()
Properly complete the stream, set publisher to completed state and sendonCompletesignal downstream. SignalonCompleteis sent only once, any other call to this method is no-op.
-
emit
public boolean emit(T item)
Emit one item to the stream, if there is enough requested and publisher is not cancelled, item is signaled to downstream asonNextand method returns true. If there is requested less than 1, nothing is sent and method returns false.- Parameters:
item- to be sent downstream- Returns:
- true if item successfully sent, false if canceled or no demand
- Throws:
IllegalStateException- if publisher is completed
-
isCompleted
public boolean isCompleted()
Check if publisher has been completed.- Returns:
- true if so
-
isCancelled
public boolean isCancelled()
Check if publisher has been cancelled.- Returns:
- true if so
-
isFailed
public boolean isFailed()
Check if publisher has been failed.- Returns:
- true if so
-
hasRequests
public boolean hasRequests()
Check if demand is higher than 0. Returned value should be used as informative and can change asynchronously.- Returns:
- true if so
-
isUnbounded
public boolean isUnbounded()
Check if downstream requested unbounded number of items, eg. there is no backpressure.- Returns:
- true if so
-
failCause
public Optional<Throwable> failCause()
Return cause of fail, if publisher is in failed state.- Returns:
- optional cause of fail
-
onCancel
public void onCancel(Runnable cancelCallback)
Executed when cancel signal from downstream arrive.- Parameters:
cancelCallback- to be executed
-
onRequest
public void onRequest(BiConsumer<Long,Long> requestCallback)
Callback executed when request signal from downstream arrive.- param
nthe requested count. - param
resultthe current total cumulative requested count, ranges between [0,Long.MAX_VALUE] where the max indicates that this publisher is unbounded.
- Parameters:
requestCallback- to be executed
- param
-
-