Package io.activej.csp.consumer
Interface ChannelConsumer<T>
- All Superinterfaces:
io.activej.async.process.AsyncCloseable
- All Known Implementing Classes:
AbstractChannelConsumer,ChannelFileWriter,OfAnotherReactor,OfAsyncConsumer,OfConsumer,OfException,OfLazyProvider,OfOutputStream,OfPromise,Recycling
public interface ChannelConsumer<T>
extends io.activej.async.process.AsyncCloseable
This interface represents consumer of data items that should be used serially
(each consecutive
accept(Object) operation should be called only after
previous accept(Object) operation finishes)
After consumer is closed, all subsequent calls to accept(Object) will
return a completed exceptionally promise.
If any exception is caught while consuming data items, AsyncCloseable.closeEx(Exception)
method should be called. All resources should be freed and the caught exception
should be propagated to all related processes.
If accept(Object) takes null as argument, it represents end-of-stream
and means that no additional data should be consumed.
-
Field Summary
Fields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Method Summary
Modifier and TypeMethodDescriptionio.activej.promise.Promise<Void>Consumes a provided value and returns aPromiseas a marker of success.default io.activej.promise.Promise<Void>Passes iterator's values to theoutputuntil ithasNext(), then returns a promise ofnullas a marker of completion.default io.activej.promise.Promise<Void>default io.activej.promise.Promise<Void>Accepts provided items and returnsPromiseas a marker of completion.default io.activej.promise.Promise<Void>default ChannelConsumer<T>async()default ChannelConsumer<T>Creates a wrapper ChannelConsumer - when itsaccept(T value)is called, current ChannelConsumer will accept the value only of it passesPredicatetest.default <V> ChannelConsumer<V>Creates a wrapper ChannelConsumer - when itsaccept(T value)is called,fnwill be applied to the providedvaluefirst and the result of thefnwill be accepted by current ChannelConsumer.default <V> ChannelConsumer<V>Creates a wrapper ChannelConsumer - when itsaccept(T value)is called,fnwill be applied to the providedvaluefirst and the result of thefnwill be accepted by current ChannelConsumer asynchronously.default ChannelConsumer<T>Creates a wrapper ChannelConsumer - when itsaccept(T value)is called, if providedvaluedoesn't equalnull, it will be accepted by the providedfnfirst and then by this ChannelConsumer.default <R> RTransforms currentChannelConsumerwith providedChannelConsumerTransformer.default ChannelConsumer<T>withAcknowledgement(UnaryOperator<io.activej.promise.Promise<Void>> fn) Creates a wrapper ChannelConsumer - after itsaccept(T value)is called and completed, an acknowledgement is returned.default ChannelConsumer<T>withExecutor(io.activej.async.process.AsyncExecutor executor) Creates a wrapper ChannelConsumer which executes current ChannelConsumer'saccept(T value)within theexecutor.Methods inherited from interface io.activej.async.process.AsyncCloseable
close, closeEx
-
Method Details
-
accept
Consumes a provided value and returns aPromiseas a marker of success. -
acceptEndOfStream
-
acceptAll
Accepts provided items and returnsPromiseas a marker of completion. If one of the items was accepted with an error, subsequent items will be recycled and aPromiseof exception will be returned. -
acceptAll
Passes iterator's values to theoutputuntil ithasNext(), then returns a promise ofnullas a marker of completion.If there was an exception while accepting iterator, a promise of exception will be returned.
- Parameters:
it- anIteratorwhich provides some values- Returns:
- a promise of
nullas a marker of completion
-
acceptAll
- See Also:
-
transformWith
Transforms currentChannelConsumerwith providedChannelConsumerTransformer.- Type Parameters:
R- result value after transformation- Parameters:
fn- transformer of theChannelConsumer- Returns:
- result of transformation applied to the current
ChannelConsumer
-
async
-
withExecutor
Creates a wrapper ChannelConsumer which executes current ChannelConsumer'saccept(T value)within theexecutor.- Parameters:
executor- executes ChannelConsumer- Returns:
- a wrapper of current ChannelConsumer which executes
in provided
executor
-
peek
Creates a wrapper ChannelConsumer - when itsaccept(T value)is called, if providedvaluedoesn't equalnull, it will be accepted by the providedfnfirst and then by this ChannelConsumer.- Parameters:
fn-Consumerwhich accepts the value passed byapply(T value)- Returns:
- a wrapper ChannelConsumer
-
map
Creates a wrapper ChannelConsumer - when itsaccept(T value)is called,fnwill be applied to the providedvaluefirst and the result of thefnwill be accepted by current ChannelConsumer. If providevalueisnull,fnwon't be applied.- Type Parameters:
V- type of data accepted and returned by thefnand accepted by ChannelConsumer- Parameters:
fn-Functionto be applied to the value ofapply(T value)- Returns:
- a wrapper ChannelConsumer
-
mapAsync
Creates a wrapper ChannelConsumer - when itsaccept(T value)is called,fnwill be applied to the providedvaluefirst and the result of thefnwill be accepted by current ChannelConsumer asynchronously. If providedvalueisnull,fnwon't be applied.- Type Parameters:
V- type of data accepted by thefnand ChannelConsumer- Parameters:
fn-Functionto be applied to the value ofapply(T value)- Returns:
- a wrapper ChannelConsumer
-
filter
Creates a wrapper ChannelConsumer - when itsaccept(T value)is called, current ChannelConsumer will accept the value only of it passesPredicatetest.- Parameters:
predicate-Predicatewhich is used to filter accepted value- Returns:
- a wrapper ChannelConsumer
-
withAcknowledgement
Creates a wrapper ChannelConsumer - after itsaccept(T value)is called and completed, an acknowledgement is returned. An acknowledgement is aSettablePromisewhich is accepted by the providedfnand then materialized.- Parameters:
fn- a function applied to theSettablePromisewhich is then materialized and returned- Returns:
- a wrapper ChannelConsumer
-