Class ChannelSuppliers
ChannelSuppliers.
Includes helper classes: ChannelSupplierOfException, ChannelSupplierOfIterator,
ChannelSupplierOfValue, ChannelSupplierEmpty.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic classRepresents aChannelSupplierwhich always returns a promise ofnull.static final classRepresents aChannelSupplierwhich always returns a promise of exception.static final classRepresents aChannelSupplierwhich wraps the provided iterator and returns promises of iterator's values untilhasNext()is true, when there are no more values left, a promise ofnullis returned.static final classRepresents aChannelSupplierof one value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamchannelSupplierAsInputStream(io.activej.eventloop.Eventloop eventloop, ChannelSupplier<io.activej.bytebuf.ByteBuf> channelSupplier) Creates anInputStreamout of aChannelSupplier<io.activej.bytebuf.ByteBuf>.static <T,A, R> io.activej.promise.Promise<R> collect(ChannelSupplier<T> supplier, A initialValue, io.activej.common.function.BiConsumerEx<A, T> accumulator, io.activej.common.function.FunctionEx<A, R> finisher) Collects data provided by thesupplierasynchronously and returns a promise of accumulated result.static <T> ChannelSupplier<T>concat(ChannelSupplier<? extends T>... suppliers) static <T> ChannelSupplier<T>concat(ChannelSupplier<? extends T> supplier1, ChannelSupplier<? extends T> supplier2) static <T> ChannelSupplier<T>concat(Iterator<? extends ChannelSupplier<? extends T>> iterator) Creates a new ChannelSupplier which onget()call returns the result wrapped inpromiseof the first ChannelSuppliers'promisethat was successfully completed with a non-null result.static <T> ChannelSupplier<T>concat(List<ChannelSupplier<? extends T>> suppliers) static ChannelSupplier<io.activej.bytebuf.ByteBuf>inputStreamAsChannelSupplier(Executor executor, int bufSize, InputStream inputStream) Creates an asynchronousChannelSupplier<io.activej.bytebuf.ByteBuf>out of someInputStream.static ChannelSupplier<io.activej.bytebuf.ByteBuf>inputStreamAsChannelSupplier(Executor executor, io.activej.common.MemSize bufSize, InputStream is) static ChannelSupplier<io.activej.bytebuf.ByteBuf>inputStreamAsChannelSupplier(Executor executor, InputStream is) Creates an asynchronousChannelSupplierout of someInputStream.static <T> ChannelSupplier<T>prefetch(int count, ChannelSupplier<T> actual) static <T> ChannelSupplier<T>prefetch(ChannelSupplier<T> actual) static <T,V> ChannelSupplier<V> remap(ChannelSupplier<T> supplier, Function<? super T, ? extends Iterator<? extends V>> fn) Transforms thisChannelSupplierdata oftype with provided fn, which returns anIteratorof atype. static <T> io.activej.promise.Promise<Void>streamTo(io.activej.common.collection.Try<ChannelSupplier<T>> supplier, io.activej.common.collection.Try<ChannelConsumer<T>> consumer) static <T> io.activej.promise.Promise<Void>streamTo(ChannelSupplier<T> supplier, ChannelConsumer<T> consumer) Streams data from thesupplierto theconsumeruntilget()ofsupplierreturns a promise ofnull.static <T> io.activej.promise.Promise<Void>streamTo(io.activej.promise.Promise<ChannelSupplier<T>> supplier, io.activej.promise.Promise<ChannelConsumer<T>> consumer)
-
Constructor Details
-
ChannelSuppliers
public ChannelSuppliers()
-
-
Method Details
-
concat
public static <T> ChannelSupplier<T> concat(ChannelSupplier<? extends T> supplier1, ChannelSupplier<? extends T> supplier2) - See Also:
-
concat
- See Also:
-
concat
- See Also:
-
concat
public static <T> ChannelSupplier<T> concat(Iterator<? extends ChannelSupplier<? extends T>> iterator) Creates a new ChannelSupplier which onget()call returns the result wrapped inpromiseof the first ChannelSuppliers'promisethat was successfully completed with a non-null result. If all the ChannelSuppliers of the iterator have anullpromiseresult, apromiseofnullwill be returned.If one of the ChannelSuppliers'
promisescompletes with an exception, all subsequent elements of the iterator will be closed and apromiseof 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>
-
collect
public static <T,A, io.activej.promise.Promise<R> collectR> (ChannelSupplier<T> supplier, A initialValue, io.activej.common.function.BiConsumerEx<A, T> accumulator, io.activej.common.function.FunctionEx<A, R> finisher) Collects data provided by thesupplierasynchronously and returns a promise of accumulated result. This process will be getting values from thesupplier, until a promise ofnullis returned, which represents end of stream.If
getreturns a promise of exception or there was an exception whileaccumulatoraccepted values, a promise ofexceptionwill be returned and the process will stop.- Type Parameters:
T- a data type provided by thesupplierA- an intermediate accumulation data typeR- a data type of final result offinisher- Parameters:
supplier- aChannelSupplierwhich provides data to be collectedinitialValue- a value which will accumulate the results of accumulatoraccumulator- aBiConsumerwhich may perform some operations over provided by supplier data and accumulates the result to the initialValuefinisher- aFunctionwhich performs the final transformation of the accumulated value- Returns:
- a promise of accumulated result, transformed by the
finisher
-
streamTo
public static <T> io.activej.promise.Promise<Void> streamTo(io.activej.promise.Promise<ChannelSupplier<T>> supplier, io.activej.promise.Promise<ChannelConsumer<T>> consumer) -
streamTo
public static <T> io.activej.promise.Promise<Void> streamTo(io.activej.common.collection.Try<ChannelSupplier<T>> supplier, io.activej.common.collection.Try<ChannelConsumer<T>> consumer) -
streamTo
public static <T> io.activej.promise.Promise<Void> streamTo(ChannelSupplier<T> supplier, ChannelConsumer<T> consumer) Streams data from thesupplierto theconsumeruntilget()ofsupplierreturns a promise ofnull.If
getreturns a promise of exception or there was an exception whileconsumeraccepted values, a promise ofexceptionwill be returned and the process will stop.- Type Parameters:
T- a data type of values passed from the supplier to consumer- Parameters:
supplier- a supplier which provides some dataconsumer- a consumer which accepts the provided by supplier data- Returns:
- a promise of
nullas a marker of completion of stream, or promise of exception, if there was an exception while streaming
-
prefetch
-
prefetch
-
remap
public static <T,V> ChannelSupplier<V> remap(ChannelSupplier<T> supplier, Function<? super T, ? extends Iterator<? extends V>> fn) Transforms thisChannelSupplierdata oftype with provided fn, which returns anIteratorof atype. Then provides this value to ChannelSupplier of . -
inputStreamAsChannelSupplier
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> inputStreamAsChannelSupplier(Executor executor, io.activej.common.MemSize bufSize, InputStream is) -
inputStreamAsChannelSupplier
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> inputStreamAsChannelSupplier(Executor executor, InputStream is) Creates an asynchronousChannelSupplierout of someInputStream.Uses a default buffer size of 8 kilobytes
-
inputStreamAsChannelSupplier
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> inputStreamAsChannelSupplier(Executor executor, int bufSize, InputStream inputStream) Creates an asynchronousChannelSupplier<io.activej.bytebuf.ByteBuf>out of someInputStream.I/O operations are executed using a specified
Executor, so that the channel supplier operations does not block the eventloop thread.A size of a
ByteBufreturned byChannelSupplier.get()will not exceed specified limitPassed
InputStreamwill be closed once a resultingChannelSupplier<io.activej.bytebuf.ByteBuf>is closed or in case an error occurs during channel supplier operations.This method should be called from within eventloop thread
- Parameters:
executor- an executor that will execute blocking I/ObufSize- a limit on a size of a byte buf supplied by returnedChannelSupplier<io.activej.bytebuf.ByteBuf>inputStream- anInputStreamthat is transformed into aChannelSupplier<io.activej.bytebuf.ByteBuf>- Returns:
- a
ChannelSupplier<io.activej.bytebuf.ByteBuf>out ouf anInputStream
-
channelSupplierAsInputStream
public static InputStream channelSupplierAsInputStream(io.activej.eventloop.Eventloop eventloop, ChannelSupplier<io.activej.bytebuf.ByteBuf> channelSupplier) Creates anInputStreamout of aChannelSupplier<io.activej.bytebuf.ByteBuf>.Asynchronous operations are executed in a context of a specified
EventloopPassed
ChannelSupplier<io.activej.bytebuf.ByteBuf>will be closed once a resultingInputStreamis closed or in case an error occurs while reading data.InputStream's methods are blocking, so they should not be called from an eventloop thread- Parameters:
eventloop- an eventloop that will execute asynchronous operationschannelSupplier- aChannelSupplier<io.activej.bytebuf.ByteBuf>that is transformed to anInputStream- Returns:
- an
InputStreamout ouf aChannelSupplier<io.activej.bytebuf.ByteBuf>
-