Class AbstractPushStreamImpl<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      PushStream<T> adjustBackPressure​(java.util.function.LongUnaryOperator adjustment)
      Changes the back-pressure propagated by this pipeline stage.
      PushStream<T> adjustBackPressure​(java.util.function.ToLongBiFunction<T,​java.lang.Long> adjustment)
      Changes the back-pressure propagated by this pipeline stage.
      private <R> void aggregateAndForward​(java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f, AbstractPushStreamImpl<R> eventStream, PushEvent<? extends T> event, java.util.Queue<T> queue, java.util.concurrent.Executor executor, long elapsed)  
      private <R> long aggregateAndForward​(Function<java.util.Collection<T>,​R> f, AbstractPushStreamImpl<R> eventStream, PushEvent<? extends T> event, java.util.Queue<T> queue)  
      Promise<java.lang.Boolean> allMatch​(Predicate<? super T> predicate)
      Closes the channel and resolve the promise with false when the predicate does not matches a pay load.
      Promise<java.lang.Boolean> anyMatch​(Predicate<? super T> predicate)
      Close the channel and resolve the promise with true when the predicate matches a payload.
      <R> PushStream<R> asyncMap​(int n, int delay, Function<? super T,​Promise<? extends R>> mapper)
      Asynchronously map the payload values.
      protected abstract boolean begin()  
      PushStream<T> buffer()
      Buffer the events in a queue using default values for the queue size and other behaviors.
      <U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>>
      PushStreamBuilder<T,​U>
      buildBuffer()
      Build a buffer to enqueue events in a queue using custom values for the queue size and other behaviors.
      (package private) void check​(java.util.concurrent.atomic.AtomicLong lastTime, long timeout)  
      void close()
      Close this PushStream by sending an event of type PushEvent.EventType.CLOSE downstream.
      protected boolean close​(PushEvent<T> event)  
      protected boolean close​(PushEvent<T> event, boolean sendDownStreamEvent)  
      <R> PushStream<R> coalesce​(int count, Function<java.util.Collection<T>,​R> f)
      Coalesces a number of events into a new type of event.
      <R> PushStream<R> coalesce​(java.util.function.IntSupplier count, Function<java.util.Collection<T>,​R> f)
      Coalesces a number of events into a new type of event.
      <R> PushStream<R> coalesce​(Function<? super T,​java.util.Optional<R>> accumulator)
      Coalesces a number of events into a new type of event.
      <R,​A>
      Promise<R>
      collect​(java.util.stream.Collector<? super T,​A,​R> collector)
      See Stream.
      Promise<java.lang.Long> count()
      See Stream.
      PushStream<T> distinct()
      Remove any duplicates.
      PushStream<T> filter​(Predicate<? super T> predicate)
      Only pass events downstream when the predicate tests true.
      Promise<java.util.Optional<T>> findAny()
      Close the channel and resolve the promise with the first element.
      Promise<java.util.Optional<T>> findFirst()
      Close the channel and resolve the promise with the first element.
      <R> PushStream<R> flatMap​(Function<? super T,​? extends PushStream<? extends R>> mapper)
      Flat map the payload value (turn one event into 0..n events of potentially another type).
      Promise<java.lang.Void> forEach​(java.util.function.Consumer<? super T> action)
      Execute the action for each event received until the channel is closed.
      Promise<java.lang.Long> forEachEvent​(PushEventConsumer<? super T> action)
      Pass on each event to another consumer until the stream is closed.
      PushStream<T> fork​(int n, int delay, java.util.concurrent.Executor ex)
      Execute the downstream events in up to n background threads.
      protected java.util.Queue<T> getQueueForInternalBuffering​(int size)  
      private <R> java.lang.Runnable getWindowTask​(AbstractPushStreamImpl<R> eventStream, java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f, java.util.function.Supplier<java.time.Duration> time, java.util.function.IntSupplier maxEvents, java.lang.Object lock, long expectedCounter, java.util.concurrent.atomic.AtomicReference<java.util.Queue<T>> queueRef, java.util.concurrent.atomic.AtomicLong timestamp, java.util.concurrent.atomic.AtomicLong counter, java.util.concurrent.atomic.AtomicLong previousWindowSize, java.util.concurrent.Executor executor)  
      protected long handleEvent​(PushEvent<? extends T> event)  
      PushStream<T> limit​(long maxSize)
      Automatically close the channel after the maxSize number of elements is received.
      PushStream<T> limit​(java.time.Duration maxTime)
      Automatically close the channel after the given amount of time has elapsed.
      <R> PushStream<R> map​(Function<? super T,​? extends R> mapper)
      Map a payload value.
      Promise<java.util.Optional<T>> max​(java.util.Comparator<? super T> comparator)
      See Stream.
      PushStream<T> merge​(PushEventSource<? extends T> source)
      Merge in the events from another source.
      PushStream<T> merge​(PushStream<? extends T> source)
      Merge in the events from another PushStream.
      Promise<java.util.Optional<T>> min​(java.util.Comparator<? super T> comparator)
      See Stream.
      Promise<java.lang.Boolean> noneMatch​(Predicate<? super T> predicate)
      Closes the channel and resolve the promise with false when the predicate matches any pay load.
      PushStream<T> onClose​(java.lang.Runnable closeHandler)
      Must be run after the channel is closed.
      PushStream<T> onError​(java.util.function.Consumer<? super java.lang.Throwable> closeHandler)
      Must be run after the channel is closed.
      Promise<java.util.Optional<T>> reduce​(java.util.function.BinaryOperator<T> accumulator)
      Standard reduce without identity, so the return is an Optional.
      Promise<T> reduce​(T identity, java.util.function.BinaryOperator<T> accumulator)
      Standard reduce, see Stream.
      <U> Promise<U> reduce​(U identity, java.util.function.BiFunction<U,​? super T,​U> accumulator, java.util.function.BinaryOperator<U> combiner)
      Standard reduce with identity, accumulator and combiner.
      PushStream<T> sequential()
      Ensure that any events are delivered sequentially.
      PushStream<T> skip​(long n)
      Skip a number of events in the channel.
      PushStream<T> sorted()
      Sorted the elements, assuming that T extends Comparable.
      PushStream<T> sorted​(java.util.Comparator<? super T> comparator)
      Sorted the elements with the given comparator.
      PushStream<T>[] split​(Predicate<? super T>... predicates)
      Split the events to different streams based on a predicate.
      PushStream<T> timeout​(java.time.Duration maxTime)
      Automatically fail the channel if no events are received for the indicated length of time.
      Promise<java.lang.Object[]> toArray()
      Collect the payloads in an Object array after the channel is closed.
      <A extends T>
      Promise<A[]>
      toArray​(java.util.function.IntFunction<A[]> generator)
      Collect the payloads in an Object array after the channel is closed.
      private void updateNext​(PushEventConsumer<T> consumer)  
      protected abstract void upstreamClose​(PushEvent<?> close)  
      <R> PushStream<R> window​(java.time.Duration time, java.util.concurrent.Executor executor, Function<java.util.Collection<T>,​R> f)
      Buffers a number of events over a fixed time interval and then forwards the events to an accumulator function.
      <R> PushStream<R> window​(java.time.Duration time, Function<java.util.Collection<T>,​R> f)
      Buffers a number of events over a fixed time interval and then forwards the events to an accumulator function.
      <R> PushStream<R> window​(java.util.function.Supplier<java.time.Duration> time, java.util.function.IntSupplier maxEvents, java.util.concurrent.Executor ex, java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f)
      Buffers a number of events over a variable time interval and then forwards the events to an accumulator function.
      <R> PushStream<R> window​(java.util.function.Supplier<java.time.Duration> time, java.util.function.IntSupplier maxEvents, java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f)
      Buffers a number of events over a variable time interval and then forwards the events to an accumulator function.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • IDENTITY

        private final Function<T,​T> IDENTITY
      • next

        protected final java.util.concurrent.atomic.AtomicReference<PushEventConsumer<T>> next
      • onCloseCallback

        protected final java.util.concurrent.atomic.AtomicReference<java.lang.Runnable> onCloseCallback
      • onErrorCallback

        protected final java.util.concurrent.atomic.AtomicReference<java.util.function.Consumer<? super java.lang.Throwable>> onErrorCallback
    • Method Detail

      • begin

        protected abstract boolean begin()
      • upstreamClose

        protected abstract void upstreamClose​(PushEvent<?> close)
      • handleEvent

        protected long handleEvent​(PushEvent<? extends T> event)
      • close

        public void close()
        Description copied from interface: PushStream
        Close this PushStream by sending an event of type PushEvent.EventType.CLOSE downstream. Closing a PushStream is a safe operation that will not throw an Exception.

        Calling close() on a closed PushStream has no effect.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface PushStream<T>
      • close

        protected boolean close​(PushEvent<T> event)
      • close

        protected boolean close​(PushEvent<T> event,
                                boolean sendDownStreamEvent)
      • onClose

        public PushStream<T> onClose​(java.lang.Runnable closeHandler)
        Description copied from interface: PushStream
        Must be run after the channel is closed. This handler will run after the downstream methods have processed the close event and before the upstream methods have closed.
        Specified by:
        onClose in interface PushStream<T>
        Parameters:
        closeHandler - Will be called on close
        Returns:
        This stream
      • onError

        public PushStream<T> onError​(java.util.function.Consumer<? super java.lang.Throwable> closeHandler)
        Description copied from interface: PushStream
        Must be run after the channel is closed. This handler will run after the downstream methods have processed the close event and before the upstream methods have closed.
        Specified by:
        onError in interface PushStream<T>
        Parameters:
        closeHandler - Will be called on close
        Returns:
        This stream
      • filter

        public PushStream<T> filter​(Predicate<? super T> predicate)
        Description copied from interface: PushStream
        Only pass events downstream when the predicate tests true.
        Specified by:
        filter in interface PushStream<T>
        Parameters:
        predicate - The predicate that is tested (not null)
        Returns:
        Builder style (can be a new or the same object)
      • map

        public <R> PushStream<R> map​(Function<? super T,​? extends R> mapper)
        Description copied from interface: PushStream
        Map a payload value.
        Specified by:
        map in interface PushStream<T>
        Parameters:
        mapper - The map function
        Returns:
        Builder style (can be a new or the same object)
      • asyncMap

        public <R> PushStream<R> asyncMap​(int n,
                                          int delay,
                                          Function<? super T,​Promise<? extends R>> mapper)
        Description copied from interface: PushStream
        Asynchronously map the payload values. The mapping function returns a Promise representing the asynchronous mapping operation.

        The PushStream limits the number of concurrently running mapping operations, and returns back pressure based on the number of existing queued operations.

        Specified by:
        asyncMap in interface PushStream<T>
        Parameters:
        n - number of simultaneous promises to use
        delay - Nr of ms/promise that is queued back pressure
        mapper - The mapping function
        Returns:
        Builder style (can be a new or the same object)
      • flatMap

        public <R> PushStream<R> flatMap​(Function<? super T,​? extends PushStream<? extends R>> mapper)
        Description copied from interface: PushStream
        Flat map the payload value (turn one event into 0..n events of potentially another type).
        Specified by:
        flatMap in interface PushStream<T>
        Parameters:
        mapper - The flat map function
        Returns:
        Builder style (can be a new or the same object)
      • distinct

        public PushStream<T> distinct()
        Description copied from interface: PushStream
        Remove any duplicates. Notice that this can be expensive in a large stream since it must track previous payloads.
        Specified by:
        distinct in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • sorted

        public PushStream<T> sorted()
        Description copied from interface: PushStream
        Sorted the elements, assuming that T extends Comparable. This is of course expensive for large or infinite streams since it requires buffering the stream until close.
        Specified by:
        sorted in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • sorted

        public PushStream<T> sorted​(java.util.Comparator<? super T> comparator)
        Description copied from interface: PushStream
        Sorted the elements with the given comparator. This is of course expensive for large or infinite streams since it requires buffering the stream until close.
        Specified by:
        sorted in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • limit

        public PushStream<T> limit​(long maxSize)
        Description copied from interface: PushStream
        Automatically close the channel after the maxSize number of elements is received.
        Specified by:
        limit in interface PushStream<T>
        Parameters:
        maxSize - Maximum number of elements has been received
        Returns:
        Builder style (can be a new or the same object)
      • limit

        public PushStream<T> limit​(java.time.Duration maxTime)
        Description copied from interface: PushStream
        Automatically close the channel after the given amount of time has elapsed.
        Specified by:
        limit in interface PushStream<T>
        Parameters:
        maxTime - The maximum time that the stream should remain open
        Returns:
        Builder style (can be a new or the same object)
      • timeout

        public PushStream<T> timeout​(java.time.Duration maxTime)
        Description copied from interface: PushStream
        Automatically fail the channel if no events are received for the indicated length of time. If the timeout is reached then a failure event containing a TimeoutException will be sent.
        Specified by:
        timeout in interface PushStream<T>
        Parameters:
        maxTime - The length of time that the stream should remain open when no events are being received.
        Returns:
        Builder style (can be a new or the same object)
      • check

        void check​(java.util.concurrent.atomic.AtomicLong lastTime,
                   long timeout)
      • skip

        public PushStream<T> skip​(long n)
        Description copied from interface: PushStream
        Skip a number of events in the channel.
        Specified by:
        skip in interface PushStream<T>
        Parameters:
        n - number of elements to skip
        Returns:
        Builder style (can be a new or the same object)
      • fork

        public PushStream<T> fork​(int n,
                                  int delay,
                                  java.util.concurrent.Executor ex)
        Description copied from interface: PushStream
        Execute the downstream events in up to n background threads. If more requests are outstanding apply delay * nr of delayed threads back pressure. A downstream channel that is closed or throws an exception will cause all execution to cease and the stream to close
        Specified by:
        fork in interface PushStream<T>
        Parameters:
        n - number of simultaneous background threads to use
        delay - Nr of ms/thread that is queued back pressure
        ex - an executor to use for the background threads.
        Returns:
        Builder style (can be a new or the same object)
      • buffer

        public PushStream<T> buffer()
        Description copied from interface: PushStream
        Buffer the events in a queue using default values for the queue size and other behaviors. Buffered work will be processed asynchronously in the rest of the chain. Buffering also blocks the transmission of back pressure to previous elements in the chain, although back pressure is honored by the buffer.

        Buffers are useful for "bursty" event sources which produce a number of events close together, then none for some time. These bursts can sometimes overwhelm downstream event consumers. Buffering will not, however, protect downstream components from a source which produces events faster than they can be consumed. For fast sources PushStream.filter(Predicate) and PushStream.coalesce(int, Function) PushStream.fork(int, int, Executor) are better choices.

        Specified by:
        buffer in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • buildBuffer

        public <U extends java.util.concurrent.BlockingQueue<PushEvent<? extends T>>> PushStreamBuilder<T,​U> buildBuffer()
        Description copied from interface: PushStream
        Build a buffer to enqueue events in a queue using custom values for the queue size and other behaviors. Buffered work will be processed asynchronously in the rest of the chain. Buffering also blocks the transmission of back pressure to previous elements in the chain, although back pressure is honored by the buffer.

        Buffers are useful for "bursty" event sources which produce a number of events close together, then none for some time. These bursts can sometimes overwhelm downstream event consumers. Buffering will not, however, protect downstream components from a source which produces events faster than they can be consumed. For fast sources PushStream.filter(Predicate) and PushStream.coalesce(int, Function) PushStream.fork(int, int, Executor) are better choices.

        Buffers are also useful as "circuit breakers" in the pipeline. If a QueuePolicyOption.FAIL is used then a full buffer will trigger the stream to close, preventing an event storm from reaching the client.

        Specified by:
        buildBuffer in interface PushStream<T>
        Returns:
        A builder which can be used to configure the buffer for this pipeline stage.
      • merge

        public PushStream<T> merge​(PushEventSource<? extends T> source)
        Description copied from interface: PushStream
        Merge in the events from another source. The resulting channel is not closed until this channel and the channel from the source are closed.
        Specified by:
        merge in interface PushStream<T>
        Parameters:
        source - The source to merge in.
        Returns:
        Builder style (can be a new or the same object)
      • merge

        public PushStream<T> merge​(PushStream<? extends T> source)
        Description copied from interface: PushStream
        Merge in the events from another PushStream. The resulting channel is not closed until this channel and the channel from the source are closed.
        Specified by:
        merge in interface PushStream<T>
        Parameters:
        source - The source to merge in.
        Returns:
        Builder style (can be a new or the same object)
      • split

        public PushStream<T>[] split​(Predicate<? super T>... predicates)
        Description copied from interface: PushStream
        Split the events to different streams based on a predicate. If the predicate is true, the event is dispatched to that channel on the same position. All predicates are tested for every event.

        This method differs from other methods of PushStream in three significant ways:

        • The return value contains multiple streams.
        • This stream will only close when all of these child streams have closed.
        • Event delivery is made to all open children that accept the event.
        Specified by:
        split in interface PushStream<T>
        Parameters:
        predicates - the predicates to test
        Returns:
        streams that map to the predicates
      • sequential

        public PushStream<T> sequential()
        Description copied from interface: PushStream
        Ensure that any events are delivered sequentially. That is, no overlapping calls downstream. This can be used to turn a forked stream (where for example a heavy conversion is done in multiple threads) back into a sequential stream so a reduce is simple to do.
        Specified by:
        sequential in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • coalesce

        public <R> PushStream<R> coalesce​(Function<? super T,​java.util.Optional<R>> accumulator)
        Description copied from interface: PushStream
        Coalesces a number of events into a new type of event. The input events are forwarded to a accumulator function. This function returns an Optional. If the optional is present, it's value is send downstream, otherwise it is ignored.
        Specified by:
        coalesce in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • coalesce

        public <R> PushStream<R> coalesce​(int count,
                                          Function<java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Coalesces a number of events into a new type of event. A fixed number of input events are forwarded to a accumulator function. This function returns new event data to be forwarded on.
        Specified by:
        coalesce in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • coalesce

        public <R> PushStream<R> coalesce​(java.util.function.IntSupplier count,
                                          Function<java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Coalesces a number of events into a new type of event. A variable number of input events are forwarded to a accumulator function. The number of events to be forwarded is determined by calling the count function. The accumulator function then returns new event data to be forwarded on.
        Specified by:
        coalesce in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • aggregateAndForward

        private <R> long aggregateAndForward​(Function<java.util.Collection<T>,​R> f,
                                             AbstractPushStreamImpl<R> eventStream,
                                             PushEvent<? extends T> event,
                                             java.util.Queue<T> queue)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • window

        public <R> PushStream<R> window​(java.time.Duration time,
                                        Function<java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Buffers a number of events over a fixed time interval and then forwards the events to an accumulator function. This function returns new event data to be forwarded on. Note that:
        • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
        • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
        • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
        Specified by:
        window in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • window

        public <R> PushStream<R> window​(java.time.Duration time,
                                        java.util.concurrent.Executor executor,
                                        Function<java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Buffers a number of events over a fixed time interval and then forwards the events to an accumulator function. This function returns new event data to be forwarded on. Note that:
        • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
        • The accumulator function will be run and the forwarded event delivered by a task given to the supplied executor.
        • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
        Specified by:
        window in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • window

        public <R> PushStream<R> window​(java.util.function.Supplier<java.time.Duration> time,
                                        java.util.function.IntSupplier maxEvents,
                                        java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Buffers a number of events over a variable time interval and then forwards the events to an accumulator function. The length of time over which events are buffered is determined by the time function. A maximum number of events can also be requested, if this number of events is reached then the accumulator will be called early. The accumulator function returns new event data to be forwarded on. It is also given the length of time for which the buffer accumulated data. This may be less than the requested interval if the buffer reached the maximum number of requested events early. Note that:
        • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
        • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
        • Due to the buffering and asynchronous delivery required, this method prevents the propagation of back-pressure to earlier stages
        • If the window finishes by hitting the maximum number of events then the remaining time in the window will be applied as back-pressure to the previous stage, attempting to slow the producer to the expected windowing threshold.
        Specified by:
        window in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • window

        public <R> PushStream<R> window​(java.util.function.Supplier<java.time.Duration> time,
                                        java.util.function.IntSupplier maxEvents,
                                        java.util.concurrent.Executor ex,
                                        java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f)
        Description copied from interface: PushStream
        Buffers a number of events over a variable time interval and then forwards the events to an accumulator function. The length of time over which events are buffered is determined by the time function. A maximum number of events can also be requested, if this number of events is reached then the accumulator will be called early. The accumulator function returns new event data to be forwarded on. It is also given the length of time for which the buffer accumulated data. This may be less than the requested interval if the buffer reached the maximum number of requested events early. Note that:
        • The collection forwarded to the accumulator function will be empty if no events arrived during the time interval.
        • The accumulator function will be run and the forwarded event delivered as a different task, (and therefore potentially on a different thread) from the one that delivered the event to this PushStream.
        • If the window finishes by hitting the maximum number of events then the remaining time in the window will be applied as back-pressure to the previous stage, attempting to slow the producer to the expected windowing threshold.
        Specified by:
        window in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • getQueueForInternalBuffering

        protected java.util.Queue<T> getQueueForInternalBuffering​(int size)
      • getWindowTask

        private <R> java.lang.Runnable getWindowTask​(AbstractPushStreamImpl<R> eventStream,
                                                     java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f,
                                                     java.util.function.Supplier<java.time.Duration> time,
                                                     java.util.function.IntSupplier maxEvents,
                                                     java.lang.Object lock,
                                                     long expectedCounter,
                                                     java.util.concurrent.atomic.AtomicReference<java.util.Queue<T>> queueRef,
                                                     java.util.concurrent.atomic.AtomicLong timestamp,
                                                     java.util.concurrent.atomic.AtomicLong counter,
                                                     java.util.concurrent.atomic.AtomicLong previousWindowSize,
                                                     java.util.concurrent.Executor executor)
      • aggregateAndForward

        private <R> void aggregateAndForward​(java.util.function.BiFunction<java.lang.Long,​java.util.Collection<T>,​R> f,
                                             AbstractPushStreamImpl<R> eventStream,
                                             PushEvent<? extends T> event,
                                             java.util.Queue<T> queue,
                                             java.util.concurrent.Executor executor,
                                             long elapsed)
      • adjustBackPressure

        public PushStream<T> adjustBackPressure​(java.util.function.LongUnaryOperator adjustment)
        Description copied from interface: PushStream
        Changes the back-pressure propagated by this pipeline stage.

        The supplied function receives the back pressure returned by the next pipeline stage and returns the back pressure that should be returned by this stage. This function will not be called if the previous pipeline stage returns negative back pressure.

        Specified by:
        adjustBackPressure in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • adjustBackPressure

        public PushStream<T> adjustBackPressure​(java.util.function.ToLongBiFunction<T,​java.lang.Long> adjustment)
        Description copied from interface: PushStream
        Changes the back-pressure propagated by this pipeline stage.

        The supplied function receives the data object passed to the next pipeline stage and the back pressure that was returned by that stage when accepting it. The function returns the back pressure that should be returned by this stage. This function will not be called if the previous pipeline stage returns negative back pressure.

        Specified by:
        adjustBackPressure in interface PushStream<T>
        Returns:
        Builder style (can be a new or the same object)
      • forEach

        public Promise<java.lang.Void> forEach​(java.util.function.Consumer<? super T> action)
        Description copied from interface: PushStream
        Execute the action for each event received until the channel is closed. This is a terminating method, the returned promise is resolved when the channel closes.

        This is a terminal operation

        Specified by:
        forEach in interface PushStream<T>
        Parameters:
        action - The action to perform
        Returns:
        A promise that is resolved when the channel closes.
      • toArray

        public Promise<java.lang.Object[]> toArray()
        Description copied from interface: PushStream
        Collect the payloads in an Object array after the channel is closed. This is a terminating method, the returned promise is resolved when the channel is closed.

        This is a terminal operation

        Specified by:
        toArray in interface PushStream<T>
        Returns:
        A promise that is resolved with all the payloads received over the channel
      • toArray

        public <A extends TPromise<A[]> toArray​(java.util.function.IntFunction<A[]> generator)
        Description copied from interface: PushStream
        Collect the payloads in an Object array after the channel is closed. This is a terminating method, the returned promise is resolved when the channel is closed. The type of the array is handled by the caller using a generator function that gets the length of the desired array.

        This is a terminal operation

        Specified by:
        toArray in interface PushStream<T>
        Returns:
        A promise that is resolved with all the payloads received over the channel
      • reduce

        public Promise<T> reduce​(T identity,
                                 java.util.function.BinaryOperator<T> accumulator)
        Description copied from interface: PushStream
        Standard reduce, see Stream. The returned promise will be resolved when the channel closes.

        This is a terminal operation

        Specified by:
        reduce in interface PushStream<T>
        Parameters:
        identity - The identity/begin value
        accumulator - The accumulator
        Returns:
        A
      • reduce

        public Promise<java.util.Optional<T>> reduce​(java.util.function.BinaryOperator<T> accumulator)
        Description copied from interface: PushStream
        Standard reduce without identity, so the return is an Optional. The returned promise will be resolved when the channel closes.

        This is a terminal operation

        Specified by:
        reduce in interface PushStream<T>
        Parameters:
        accumulator - The accumulator
        Returns:
        an Optional
      • reduce

        public <U> Promise<U> reduce​(U identity,
                                     java.util.function.BiFunction<U,​? super T,​U> accumulator,
                                     java.util.function.BinaryOperator<U> combiner)
        Description copied from interface: PushStream
        Standard reduce with identity, accumulator and combiner. The returned promise will be resolved when the channel closes.

        This is a terminal operation

        Specified by:
        reduce in interface PushStream<T>
        combiner - combines two U's into one U (for example, combine two lists)
        Returns:
        The promise
      • collect

        public <R,​A> Promise<R> collect​(java.util.stream.Collector<? super T,​A,​R> collector)
        Description copied from interface: PushStream
        See Stream. Will resolve once the channel closes.

        This is a terminal operation

        Specified by:
        collect in interface PushStream<T>
        Returns:
        A Promise representing the collected results
      • min

        public Promise<java.util.Optional<T>> min​(java.util.Comparator<? super T> comparator)
        Description copied from interface: PushStream
        See Stream. Will resolve onces the channel closes.

        This is a terminal operation

        Specified by:
        min in interface PushStream<T>
        Returns:
        A Promise representing the minimum value, or null if no values are seen before the end of the stream
      • max

        public Promise<java.util.Optional<T>> max​(java.util.Comparator<? super T> comparator)
        Description copied from interface: PushStream
        See Stream. Will resolve onces the channel closes.

        This is a terminal operation

        Specified by:
        max in interface PushStream<T>
        Returns:
        A Promise representing the maximum value, or null if no values are seen before the end of the stream
      • count

        public Promise<java.lang.Long> count()
        Description copied from interface: PushStream
        See Stream. Will resolve onces the channel closes.

        This is a terminal operation

        Specified by:
        count in interface PushStream<T>
        Returns:
        A Promise representing the number of values in the stream
      • anyMatch

        public Promise<java.lang.Boolean> anyMatch​(Predicate<? super T> predicate)
        Description copied from interface: PushStream
        Close the channel and resolve the promise with true when the predicate matches a payload. If the channel is closed before the predicate matches, the promise is resolved with false.

        This is a short circuiting terminal operation

        Specified by:
        anyMatch in interface PushStream<T>
        Returns:
        A Promise that will resolve when an event matches the predicate, or the end of the stream is reached
      • allMatch

        public Promise<java.lang.Boolean> allMatch​(Predicate<? super T> predicate)
        Description copied from interface: PushStream
        Closes the channel and resolve the promise with false when the predicate does not matches a pay load. If the channel is closed before, the promise is resolved with true.

        This is a short circuiting terminal operation

        Specified by:
        allMatch in interface PushStream<T>
        Returns:
        A Promise that will resolve when an event fails to match the predicate, or the end of the stream is reached
      • noneMatch

        public Promise<java.lang.Boolean> noneMatch​(Predicate<? super T> predicate)
        Description copied from interface: PushStream
        Closes the channel and resolve the promise with false when the predicate matches any pay load. If the channel is closed before, the promise is resolved with true.

        This is a short circuiting terminal operation

        Specified by:
        noneMatch in interface PushStream<T>
        Returns:
        A Promise that will resolve when an event matches the predicate, or the end of the stream is reached
      • findFirst

        public Promise<java.util.Optional<T>> findFirst()
        Description copied from interface: PushStream
        Close the channel and resolve the promise with the first element. If the channel is closed before, the Optional will have no value.
        Specified by:
        findFirst in interface PushStream<T>
        Returns:
        a promise
      • findAny

        public Promise<java.util.Optional<T>> findAny()
        Description copied from interface: PushStream
        Close the channel and resolve the promise with the first element. If the channel is closed before, the Optional will have no value.

        This is a terminal operation

        Specified by:
        findAny in interface PushStream<T>
        Returns:
        a promise
      • forEachEvent

        public Promise<java.lang.Long> forEachEvent​(PushEventConsumer<? super T> action)
        Description copied from interface: PushStream
        Pass on each event to another consumer until the stream is closed.

        This is a terminal operation

        Specified by:
        forEachEvent in interface PushStream<T>
        Returns:
        a promise