Package io.activej.csp.consumer
Class ChannelConsumers
java.lang.Object
io.activej.csp.consumer.ChannelConsumers
Provides static factories for instantiating various
ChannelConsumers.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ChannelConsumer<T>ofAnotherReactor(io.activej.reactor.Reactor anotherReactor, ChannelConsumer<T> anotherReactorConsumer) static <T> ChannelConsumer<T>ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer) WrapsAsyncConsumerinChannelConsumer.static <T> ChannelConsumer<T>ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer, @Nullable io.activej.async.process.AsyncCloseable closeable) WrapsAsyncConsumerinChannelConsumer.static <T> ChannelConsumer<T>ofConsumer(io.activej.common.function.ConsumerEx<T> consumer) Wraps aConsumerExinChannelConsumer.static <T> ChannelConsumer<T>ofConsumer(io.activej.common.function.ConsumerEx<T> consumer, @Nullable io.activej.async.process.AsyncCloseable closeable) static <T> ChannelConsumer<T>Creates a consumer which always returns aPromiseof exception when accepting values.static <T> ChannelConsumer<T>ofLazyProvider(Supplier<? extends ChannelConsumer<T>> provider) Returns aChannelConsumerwrapped inSupplierand calls itsaccept()whenaccept()method is called.static ChannelConsumer<io.activej.bytebuf.ByteBuf>ofOutputStream(Executor executor, OutputStream outputStream) Creates an asynchronousChannelConsumer<io.activej.bytebuf.ByteBuf>out of someOutputStream.static <T> ChannelConsumer<T>ofPromise(io.activej.promise.Promise<? extends ChannelConsumer<T>> promise) UnwrapsChannelConsumerof providedPromise.static ChannelConsumer<io.activej.bytebuf.ByteBuf>ofSocket(ITcpSocket socket) WrapsITcpSocket.write(ByteBuf)operation intoChannelConsumer.static <T> ChannelConsumer<T>ofSupplier(io.activej.async.function.AsyncConsumer<ChannelSupplier<T>> supplierConsumer) static <T> ChannelConsumer<T>ofSupplier(io.activej.async.function.AsyncConsumer<ChannelSupplier<T>> supplierConsumer, ChannelQueue<T> queue) static <T extends io.activej.common.recycle.Recyclable>
ChannelConsumer<T>
-
Constructor Details
-
ChannelConsumers
public ChannelConsumers()
-
-
Method Details
-
ofAsyncConsumer
public static <T> ChannelConsumer<T> ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer) WrapsAsyncConsumerinChannelConsumer. -
ofAsyncConsumer
public static <T> ChannelConsumer<T> ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable) WrapsAsyncConsumerinChannelConsumer.- Type Parameters:
T- type of data to be consumed- Parameters:
consumer-AsyncConsumerto be wrappedcloseable- aAsyncCloseable, which will be set to the returnedChannelConsumer- Returns:
ChannelConsumerwhich wrapsAsyncConsumer
-
ofConsumer
Wraps aConsumerExinChannelConsumer. -
ofConsumer
public static <T> ChannelConsumer<T> ofConsumer(io.activej.common.function.ConsumerEx<T> consumer, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable) -
ofException
Creates a consumer which always returns aPromiseof exception when accepting values.- Type Parameters:
T- type of data to be consumed- Parameters:
e- an exception which is wrapped in returnedPromisewhenaccept()is called- Returns:
- a
ChannelConsumerwhich always returns aPromiseof exception when accepts values
-
ofSupplier
public static <T> ChannelConsumer<T> ofSupplier(io.activej.async.function.AsyncConsumer<ChannelSupplier<T>> supplierConsumer) - See Also:
-
ofSupplier
public static <T> ChannelConsumer<T> ofSupplier(io.activej.async.function.AsyncConsumer<ChannelSupplier<T>> supplierConsumer, ChannelQueue<T> queue) -
ofPromise
public static <T> ChannelConsumer<T> ofPromise(io.activej.promise.Promise<? extends ChannelConsumer<T>> promise) UnwrapsChannelConsumerof providedPromise. If provided Promise is already successfully completed, its result will be returned, otherwise anChannelConsumeris created, which waits for the Promise to be completed before accepting any value. APromiseof Exception will be returned ifPromisewas completed with an exception.- Type Parameters:
T- type of data to be consumed- Parameters:
promise-PromiseofChannelConsumer- Returns:
ChannelConsumerof a given promise
-
ofAnotherReactor
public static <T> ChannelConsumer<T> ofAnotherReactor(io.activej.reactor.Reactor anotherReactor, ChannelConsumer<T> anotherReactorConsumer) -
ofLazyProvider
public static <T> ChannelConsumer<T> ofLazyProvider(Supplier<? extends ChannelConsumer<T>> provider) Returns aChannelConsumerwrapped inSupplierand calls itsaccept()whenaccept()method is called.- Parameters:
provider- provider of theChannelConsumer- Returns:
- a
ChannelConsumerwhich was wrapped in theprovider
-
ofSocket
WrapsITcpSocket.write(ByteBuf)operation intoChannelConsumer.- Returns:
ChannelConsumerof ByteBufs that will be sent to network
-
recycling
-
ofOutputStream
public static ChannelConsumer<io.activej.bytebuf.ByteBuf> ofOutputStream(Executor executor, OutputStream outputStream) Creates an asynchronousChannelConsumer<io.activej.bytebuf.ByteBuf>out of someOutputStream.I/O operations are executed using a specified
Executor, so that the channel consumer operations does not block the reactor.Passed
OutputStreamwill be closed once a resultingChannelConsumer<io.activej.bytebuf.ByteBuf>is closed or in case an error occurs during channel consumer operations.This method should be called from within reactor
- Parameters:
executor- an executor that will execute blocking I/OoutputStream- anOutputStreamthat is transformed into aChannelConsumer<io.activej.bytebuf.ByteBuf>- Returns:
- a
ChannelConsumer<io.activej.bytebuf.ByteBuf>out ouf anOutputStream
-