Class ChannelSuppliers

java.lang.Object
io.activej.csp.supplier.ChannelSuppliers

public class ChannelSuppliers extends Object
Provides additional functionality for managing ChannelSuppliers. Includes helper classes: ChannelSupplierOfException, ChannelSupplierOfIterator, ChannelSupplierOfValue, ChannelSupplierEmpty.
  • Constructor Details

    • ChannelSuppliers

      public ChannelSuppliers()
  • Method Details

    • ofAsyncSupplier

      public static <T> ChannelSupplier<T> ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier)
      See Also:
    • ofAsyncSupplier

      public static <T> ChannelSupplier<T> ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable)
      Wraps AsyncSupplier in ChannelSupplier, when get() is called, AsyncSupplier's get() will be executed.
      Type Parameters:
      T - data type wrapped in AsyncSupplier and ChannelSupplier
      Parameters:
      supplier - an AsyncSupplier to be wrapped in ChannelSupplier
      closeable - a Cancellable which will be set for the ChannelSupplier wrapper
      Returns:
      ChannelSupplier which wraps AsyncSupplier
    • ofSupplier

      public static <T> ChannelSupplier<T> ofSupplier(io.activej.common.function.SupplierEx<T> supplier)
      Wraps provided default Supplier to ChannelSupplier.
    • ofSupplier

      public static <T> ChannelSupplier<T> ofSupplier(io.activej.common.function.SupplierEx<T> supplier, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable)
      Wraps provided default Supplier to ChannelSupplier.
    • ofConsumer

      public static <T> ChannelSupplier<T> ofConsumer(Consumer<ChannelConsumer<T>> consumer, ChannelQueue<T> queue)
      Creates a ChannelSupplier received from ChannelQueue.
    • empty

      public static <T> ChannelSupplier<T> empty()
      Creates a ChannelSupplier which is empty (always returns a promise of null)
    • ofValue

      public static <T> ChannelSupplier<T> ofValue(T value)
      Creates a ChannelSupplier of one value. Returns a promise of the value when get is called for the first time, all subsequent calls will return null.
      Parameters:
      value - a value to be wrapped in ChannelSupplier
      Returns:
      a ChannelSupplier which wraps the value
    • ofValues

      public static <T> ChannelSupplier<T> ofValues()
      See Also:
    • ofValues

      public static <T> ChannelSupplier<T> ofValues(T value)
      See Also:
      • #ofValue(T)
    • ofValues

      @SafeVarargs public static <T> ChannelSupplier<T> ofValues(T... values)
      See Also:
    • ofException

      public static <T> ChannelSupplier<T> ofException(Exception e)
      Creates a ChannelSupplier which always returns a promise of exception.
    • ofList

      public static <T> ChannelSupplier<T> ofList(List<? extends T> list)
      See Also:
    • ofStream

      public static <T> ChannelSupplier<T> ofStream(Stream<? extends T> stream)
      See Also:
    • ofIterator

      public static <T> ChannelSupplier<T> ofIterator(Iterator<? extends T> iterator)
      Creates a ChannelSupplier which wraps the provided iterator and returns promises of iterator's values until hasNext() is true, when there are no more values left, a promise of null is returned.
      Parameters:
      iterator - an iterator to be wrapped in ChannelSupplier
      Returns:
      a ChannelSupplier which wraps elements of type
    • ofSocket

      public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofSocket(ITcpSocket socket)
      Wraps ITcpSocket.read() operation into ChannelSupplier
      Returns:
      ChannelSupplier of ByteBufs that are read from network
    • ofPromise

      public static <T> ChannelSupplier<T> ofPromise(io.activej.promise.Promise<? extends ChannelSupplier<T>> promise)
      Wraps promise of ChannelSupplier in ChannelSupplier or returns the ChannelSupplier from promise itself.

      If promise is completed, it will be materialized and its result (a ChannelSupplier) will be returned.

      Otherwise, when get() is called, it will wait until promise completes and promise result's (a ChannelSupplier) get() operation will be executed. If the promise completes exceptionally, a promise of exception will be returned.

      Parameters:
      promise - wraps a ChannelSupplier
      Returns:
      a ChannelSupplier of promise or a wrapper ChannelSupplier
    • ofAnotherReactor

      public static <T> ChannelSupplier<T> ofAnotherReactor(io.activej.reactor.Reactor anotherReactor, ChannelSupplier<T> anotherReactorSupplier)
    • ofLazyProvider

      public static <T> ChannelSupplier<T> ofLazyProvider(Supplier<? extends ChannelSupplier<T>> provider)
      Creates a ChannelSupplier wrapped in Supplier and calls its get() when get() method is called.
      Parameters:
      provider - a provider of ChannelSupplier
      Returns:
      a ChannelSupplier that was wrapped in the provider
    • concat

      public static <T> ChannelSupplier<T> concat(ChannelSupplier<? extends T> supplier1, ChannelSupplier<? extends T> supplier2)
      See Also:
    • concat

      @SafeVarargs public static <T> ChannelSupplier<T> concat(ChannelSupplier<? extends T>... suppliers)
      See Also:
    • concat

      public static <T> ChannelSupplier<T> concat(List<ChannelSupplier<? extends T>> suppliers)
      See Also:
    • concat

      public static <T> ChannelSupplier<T> concat(Iterator<? extends ChannelSupplier<? extends T>> iterator)
      Creates a new ChannelSupplier which on get() call returns the result wrapped in promise of the first ChannelSuppliers' promise that was successfully completed with a non-null result. If all the ChannelSuppliers of the iterator have a null promise result, a promise of null will be returned.

      If one of the ChannelSuppliers' promises completes with an exception, all subsequent elements of the iterator will be closed and a promise of exception will be returned.

      Type Parameters:
      T - type of data wrapped in the ChannelSuppliers
      Parameters:
      iterator - an iterator of ChannelSuppliers
      Returns:
      a ChannelSupplier of <T>
    • prefetch

      public static <T> ChannelSupplier<T> prefetch(int count, ChannelSupplier<T> actual)
    • prefetch

      public static <T> ChannelSupplier<T> prefetch(ChannelSupplier<T> actual)
    • remap

      public static <T, V> ChannelSupplier<V> remap(ChannelSupplier<T> supplier, Function<? super T,? extends Iterator<? extends V>> fn)
      Transforms this ChannelSupplier data of type with provided fn, which returns an Iterator of a type. Then provides this value to ChannelSupplier of .
    • ofInputStream

      public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(Executor executor, io.activej.common.MemSize bufSize, InputStream is)
      See Also:
    • ofInputStream

      public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(Executor executor, InputStream is)
      Creates an asynchronous ChannelSupplier out of some InputStream.

      Uses a default buffer size of 8 kilobytes

      See Also:
    • ofInputStream

      public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(Executor executor, int bufSize, InputStream inputStream)
      Creates an asynchronous ChannelSupplier<io.activej.bytebuf.ByteBuf> out of some InputStream.

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

      A size of a ByteBuf returned by ChannelSupplier.get() will not exceed specified limit

      Passed InputStream will be closed once a resulting ChannelSupplier<io.activej.bytebuf.ByteBuf> is closed or in case an error occurs during channel supplier operations.

      This method should be called from within reactor

      Parameters:
      executor - an executor that will execute blocking I/O
      bufSize - a limit on a size of a byte buf supplied by returned ChannelSupplier<io.activej.bytebuf.ByteBuf>
      inputStream - an InputStream that is transformed into a ChannelSupplier<io.activej.bytebuf.ByteBuf>
      Returns:
      a ChannelSupplier<io.activej.bytebuf.ByteBuf> out ouf an InputStream