java.lang.Object
io.helidon.common.reactive.EmittingPublisher<T>
- Type Parameters:
T
- type of emitted item
- All Implemented Interfaces:
Flow.Publisher<T>
Emitting publisher for manual publishing on the same thread.
EmittingPublisher
doesn't have any buffering capability and propagates backpressure
directly by returning false
from emit(Object)
in case there
is no demand, or cancel
signal has been received.
For publishing with buffering in case of backpressure use BufferedEmittingPublisher
.
This publisher allows only a single subscriber.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
complete()
Properly complete the stream, set publisher to completed state and sendonComplete
signal downstream.static <T> EmittingPublisher<T>
create()
Create newEmittingPublisher
.boolean
Emit one item to the stream, if there is enough requested and publisher is not cancelled, item is signaled to downstream asonNext
and method returns true.void
Properly fail the stream, set publisher to cancelled state and sendonError
signal downstream.Return cause of fail, if publisher is in failed state.boolean
Check if demand is higher than 0.boolean
Check if publisher has been cancelled.boolean
Check if publisher has been completed.boolean
isFailed()
Check if publisher has been failed.boolean
Check if downstream requested unbounded number of items, eg.void
Executed when cancel signal from downstream arrive.void
onRequest
(BiConsumer<Long, Long> requestCallback) Callback executed when request signal from downstream arrive.void
subscribe
(Flow.Subscriber<? super T> subscriber)
-
Method Details
-
create
Create newEmittingPublisher
.- Type Parameters:
T
- type of emitted item- Returns:
- brand new
EmittingPublisher
-
subscribe
- Specified by:
subscribe
in interfaceFlow.Publisher<T>
-
fail
Properly fail the stream, set publisher to cancelled state and sendonError
signal downstream. SignalonError
is sent only once, any other call to this method is no-op.- Parameters:
throwable
- Sent asonError
signal
-
complete
public void complete()Properly complete the stream, set publisher to completed state and sendonComplete
signal downstream. SignalonComplete
is sent only once, any other call to this method is no-op. -
emit
Emit one item to the stream, if there is enough requested and publisher is not cancelled, item is signaled to downstream asonNext
and 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
Return cause of fail, if publisher is in failed state.- Returns:
- optional cause of fail
-
onCancel
Executed when cancel signal from downstream arrive.- Parameters:
cancelCallback
- to be executed
-
onRequest
Callback executed when request signal from downstream arrive.- param
n
the requested count. - param
result
the 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
-