Class ChannelConsumers

java.lang.Object
io.activej.csp.consumer.ChannelConsumers

public class ChannelConsumers extends Object
Provides static factories for instantiating various ChannelConsumers.
  • Constructor Details

    • ChannelConsumers

      public ChannelConsumers()
  • Method Details

    • ofAsyncConsumer

      public static <T> ChannelConsumer<T> ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer)
      Wraps AsyncConsumer in ChannelConsumer.
      See Also:
    • ofAsyncConsumer

      public static <T> ChannelConsumer<T> ofAsyncConsumer(io.activej.async.function.AsyncConsumer<T> consumer, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable)
      Wraps AsyncConsumer in ChannelConsumer.
      Type Parameters:
      T - type of data to be consumed
      Parameters:
      consumer - AsyncConsumer to be wrapped
      closeable - a AsyncCloseable, which will be set to the returned ChannelConsumer
      Returns:
      ChannelConsumer which wraps AsyncConsumer
    • ofConsumer

      public static <T> ChannelConsumer<T> ofConsumer(io.activej.common.function.ConsumerEx<T> consumer)
      Wraps a ConsumerEx in ChannelConsumer.
    • ofConsumer

      public static <T> ChannelConsumer<T> ofConsumer(io.activej.common.function.ConsumerEx<T> consumer, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable)
    • ofException

      public static <T> ChannelConsumer<T> ofException(Exception e)
      Creates a consumer which always returns a Promise of exception when accepting values.
      Type Parameters:
      T - type of data to be consumed
      Parameters:
      e - an exception which is wrapped in returned Promise when accept() is called
      Returns:
      a ChannelConsumer which always returns a Promise of 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)
      Unwraps ChannelConsumer of provided Promise. If provided Promise is already successfully completed, its result will be returned, otherwise an ChannelConsumer is created, which waits for the Promise to be completed before accepting any value. A Promise of Exception will be returned if Promise was completed with an exception.
      Type Parameters:
      T - type of data to be consumed
      Parameters:
      promise - Promise of ChannelConsumer
      Returns:
      ChannelConsumer of 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 a ChannelConsumer wrapped in Supplier and calls its accept() when accept() method is called.
      Parameters:
      provider - provider of the ChannelConsumer
      Returns:
      a ChannelConsumer which was wrapped in the provider
    • ofSocket

      public static ChannelConsumer<io.activej.bytebuf.ByteBuf> ofSocket(ITcpSocket socket)
      Returns:
      ChannelConsumer of ByteBufs that will be sent to network
    • recycling

      public static <T extends io.activej.common.recycle.Recyclable> ChannelConsumer<T> recycling()
    • ofOutputStream

      public static ChannelConsumer<io.activej.bytebuf.ByteBuf> ofOutputStream(Executor executor, OutputStream outputStream)
      Creates an asynchronous ChannelConsumer<io.activej.bytebuf.ByteBuf> out of some OutputStream.

      I/O operations are executed using a specified Executor, so that the channel consumer operations does not block the reactor.

      Passed OutputStream will be closed once a resulting ChannelConsumer<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/O
      outputStream - an OutputStream that is transformed into a ChannelConsumer<io.activej.bytebuf.ByteBuf>
      Returns:
      a ChannelConsumer<io.activej.bytebuf.ByteBuf> out ouf an OutputStream