Class ChannelConsumers

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

public final class ChannelConsumers extends Object
Provides additional functionality for managing ChannelConsumers.
  • Constructor Details

    • ChannelConsumers

      public ChannelConsumers()
  • Method Details

    • acceptAll

      public static <T> io.activej.promise.Promise<Void> acceptAll(ChannelConsumer<T> output, Iterator<? extends T> it)
      Passes iterator's values to the output until it hasNext(), then returns a promise of null as a marker of completion.

      If there was an exception while accepting iterator, a promise of exception will be returned.

      Type Parameters:
      T - a data type of passed values
      Parameters:
      output - a ChannelConsumer, which accepts the iterator
      it - an Iterator which provides some values
      Returns:
      a promise of null as a marker of completion
    • acceptAll

      public static <T> io.activej.promise.Promise<Void> acceptAll(ChannelConsumer<T> output, List<? extends T> list)
    • recycling

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

      public static ChannelConsumer<io.activej.bytebuf.ByteBuf> outputStreamAsChannelConsumer(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 eventloop thread.

      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 eventloop thread

      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
    • channelConsumerAsOutputStream

      public static OutputStream channelConsumerAsOutputStream(io.activej.eventloop.Eventloop eventloop, ChannelConsumer<io.activej.bytebuf.ByteBuf> channelConsumer)
      Creates an OutputStream out of a ChannelConsumer<io.activej.bytebuf.ByteBuf>.

      Asynchronous operations are executed in a context of a specified Eventloop

      Passed ChannelSupplier<io.activej.bytebuf.ByteBuf> will be closed once a resulting OutputStream is closed or in case an error occurs while reading data.

      OutputStream's methods are blocking, so they should not be called from an eventloop thread

      Parameters:
      eventloop - an eventloop that will execute asynchronous operations
      channelConsumer - a ChannelSupplier<io.activej.bytebuf.ByteBuf> that is transformed to an OutputStream
      Returns:
      an OutputStream out ouf a ChannelSupplier<io.activej.bytebuf.ByteBuf>