Class ChannelSuppliers
ChannelSuppliers.
Includes helper classes: ChannelSupplierOfException, ChannelSupplierOfIterator,
ChannelSupplierOfValue, ChannelSupplierEmpty.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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 <T> ChannelSupplier<T>empty()Creates aChannelSupplierwhich is empty (always returns a promise ofnull)static <T> ChannelSupplier<T>ofAnotherReactor(io.activej.reactor.Reactor anotherReactor, ChannelSupplier<T> anotherReactorSupplier) static <T> ChannelSupplier<T>ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier) static <T> ChannelSupplier<T>ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier, @Nullable io.activej.async.process.AsyncCloseable closeable) WrapsAsyncSupplierin ChannelSupplier, whenget()is called,AsyncSupplier'sget()will be executed.static <T> ChannelSupplier<T>ofConsumer(Consumer<ChannelConsumer<T>> consumer, ChannelQueue<T> queue) Creates a ChannelSupplier received fromChannelQueue.static <T> ChannelSupplier<T>Creates aChannelSupplierwhich always returns a promise of exception.static ChannelSupplier<io.activej.bytebuf.ByteBuf>ofInputStream(Executor executor, int bufSize, InputStream inputStream) Creates an asynchronousChannelSupplier<io.activej.bytebuf.ByteBuf>out of someInputStream.static ChannelSupplier<io.activej.bytebuf.ByteBuf>ofInputStream(Executor executor, io.activej.common.MemSize bufSize, InputStream is) static ChannelSupplier<io.activej.bytebuf.ByteBuf>ofInputStream(Executor executor, InputStream is) Creates an asynchronousChannelSupplierout of someInputStream.static <T> ChannelSupplier<T>ofIterator(Iterator<? extends T> iterator) Creates 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 <T> ChannelSupplier<T>ofLazyProvider(Supplier<? extends ChannelSupplier<T>> provider) static <T> ChannelSupplier<T>static <T> ChannelSupplier<T>ofPromise(io.activej.promise.Promise<? extends ChannelSupplier<T>> promise) Wrapspromiseof ChannelSupplier in ChannelSupplier or returns the ChannelSupplier frompromiseitself.static ChannelSupplier<io.activej.bytebuf.ByteBuf>ofSocket(ITcpSocket socket) WrapsITcpSocket.read()operation intoChannelSupplierstatic <T> ChannelSupplier<T>static <T> ChannelSupplier<T>ofSupplier(io.activej.common.function.SupplierEx<T> supplier) Wraps provided defaultSupplierto ChannelSupplier.static <T> ChannelSupplier<T>ofSupplier(io.activej.common.function.SupplierEx<T> supplier, @Nullable io.activej.async.process.AsyncCloseable closeable) Wraps provided defaultSupplierto ChannelSupplier.static <T> ChannelSupplier<T>ofValue(T value) Creates aChannelSupplierof one value.static <T> ChannelSupplier<T>ofValues()static <T> ChannelSupplier<T>ofValues(T value) static <T> ChannelSupplier<T>ofValues(T... values) 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.
-
Constructor Details
-
ChannelSuppliers
public ChannelSuppliers()
-
-
Method Details
-
ofAsyncSupplier
public static <T> ChannelSupplier<T> ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier) -
ofAsyncSupplier
public static <T> ChannelSupplier<T> ofAsyncSupplier(io.activej.async.function.AsyncSupplier<T> supplier, @Nullable @Nullable io.activej.async.process.AsyncCloseable closeable) WrapsAsyncSupplierin ChannelSupplier, whenget()is called,AsyncSupplier'sget()will be executed.- Type Parameters:
T- data type wrapped inAsyncSupplierand ChannelSupplier- Parameters:
supplier- anAsyncSupplierto be wrapped in ChannelSuppliercloseable- aCancellablewhich will be set for the ChannelSupplier wrapper- Returns:
- ChannelSupplier which wraps
AsyncSupplier
-
ofSupplier
Wraps provided defaultSupplierto 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 defaultSupplierto ChannelSupplier. -
ofConsumer
public static <T> ChannelSupplier<T> ofConsumer(Consumer<ChannelConsumer<T>> consumer, ChannelQueue<T> queue) Creates a ChannelSupplier received fromChannelQueue. -
empty
Creates aChannelSupplierwhich is empty (always returns a promise ofnull) -
ofValue
Creates aChannelSupplierof one value. Returns a promise of the value whengetis called for the first time, all subsequent calls will returnnull.- Parameters:
value- a value to be wrapped in ChannelSupplier- Returns:
- a
ChannelSupplierwhich wraps thevalue
-
ofValues
- See Also:
-
ofValues
- See Also:
-
#ofValue(T)
-
ofValues
- See Also:
-
ofException
Creates aChannelSupplierwhich always returns a promise of exception. -
ofList
- See Also:
-
ofStream
- See Also:
-
ofIterator
Creates 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.- Parameters:
iterator- an iterator to be wrapped in ChannelSupplier- Returns:
- a ChannelSupplier which wraps elements of
type
-
ofSocket
WrapsITcpSocket.read()operation intoChannelSupplier- Returns:
ChannelSupplierof ByteBufs that are read from network
-
ofPromise
public static <T> ChannelSupplier<T> ofPromise(io.activej.promise.Promise<? extends ChannelSupplier<T>> promise) Wrapspromiseof ChannelSupplier in ChannelSupplier or returns the ChannelSupplier frompromiseitself.If
promiseis completed, it will be materialized and its result (a ChannelSupplier) will be returned.Otherwise, when
get()is called, it will wait untilpromisecompletes andpromiseresult's (a ChannelSupplier)get()operation will be executed. If thepromisecompletes exceptionally, apromiseof exception will be returned.- Parameters:
promise- wraps aChannelSupplier- Returns:
- a ChannelSupplier of
promiseor 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) - Parameters:
provider- a provider ofChannelSupplier- Returns:
- a
ChannelSupplierthat was wrapped in theprovider
-
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>
-
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 . -
ofInputStream
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(Executor executor, io.activej.common.MemSize bufSize, InputStream is) -
ofInputStream
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(Executor executor, InputStream is) Creates an asynchronousChannelSupplierout of someInputStream.Uses a default buffer size of 8 kilobytes
-
ofInputStream
public static ChannelSupplier<io.activej.bytebuf.ByteBuf> ofInputStream(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 reactor.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 reactor
- 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
-