use of com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter in project cyclops by aol.
the class ReactiveSeq method enqueuedAll.
static <T> ReactiveSeq<T> enqueuedAll(Consumer<? super Subscriber<T>>... subs) {
final Counter c = new Counter();
c.active.set(subs.length);
QueueBasedSubscriber<T> s = QueueBasedSubscriber.subscriber(c, subs.length);
for (Consumer<? super Subscriber<T>> next : subs) next.accept(s);
s.close();
return s.reactiveSeq();
}
use of com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter in project cyclops by aol.
the class ReactiveSeq method enqueued.
static <T> ReactiveSeq<T> enqueued(Queue<T> q, Consumer<? super Subscriber<T>> sub) {
final Counter c = new Counter();
c.active.set(1);
QueueBasedSubscriber<T> s = QueueBasedSubscriber.subscriber(q, c, 1);
sub.accept(s);
return s.reactiveSeq();
}
use of com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter in project cyclops by aol.
the class ReactiveSeq method merge.
default ReactiveSeq<T> merge(Adapter<T>... adapters) {
return defer(() -> {
Publisher<T>[] publishers = ReactiveSeq.of(adapters).map(a -> a.stream()).toArray(n -> new Publisher[n]);
final Counter c = new Counter();
c.active.set(publishers.length + 1);
final QueueBasedSubscriber<T> init = QueueBasedSubscriber.subscriber(QueueFactories.boundedQueue(5_000), c, publishers.length);
final Supplier<Continuation> sp = () -> {
backpressureAware().subscribe(init);
for (final Publisher next : publishers) {
next.subscribe(QueueBasedSubscriber.subscriber(init.getQueue(), c, publishers.length));
}
init.close();
return Continuation.empty();
};
final Continuation continuation = new Continuation(sp);
init.addContinuation(continuation);
return ReactiveSeq.fromStream(init.jdkStream());
});
}
use of com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter in project cyclops by aol.
the class ReactiveSeq method mergeP.
/**
* A potentially asynchronous merge operation where data from each publisher may arrive out of order (if publishers
* are configured to publish asynchronously.
* The QueueFactory parameter can be used by pull based Streams to control the maximum queued elements @see {@link QueueFactories}
* Push based reactive-streams signal demand via their subscription.
*/
// name will be refactored to merge in the future
@Deprecated
default ReactiveSeq<T> mergeP(final QueueFactory<T> factory, final Publisher<T>... publishers) {
return defer(() -> {
final Counter c = new Counter();
c.active.set(publishers.length + 1);
final QueueBasedSubscriber<T> init = QueueBasedSubscriber.subscriber(factory, c, publishers.length);
final Supplier<Continuation> sp = () -> {
subscribe(init);
for (final Publisher next : publishers) {
next.subscribe(QueueBasedSubscriber.subscriber(init.getQueue(), c, publishers.length));
}
init.close();
return Continuation.empty();
};
final Continuation continuation = new Continuation(sp);
init.addContinuation(continuation);
return ReactiveSeq.fromStream(init.jdkStream());
});
}
use of com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter in project cyclops by aol.
the class ReactiveSeq method enqueued.
/**
* Create a Stream that accepts data via the Subsriber passed into the supplied Consumer.
* reactive-streams susbscription can be used to determine demand (or ignored and data passed
* via onNext, onError) excess supply over demand is enqueued
*
* <pre>
* {@code
* ReactiveSeq<Integer> input = ReactiveSeq.enqueued(subscriber->{
* listener.onEvent(subscriber::onNext);
* listener.onError(susbscriber::onError);
* closeListener.onEvent(subscriber::onClose);
* });
* }
* </pre>
*
* @param sub
* @param <T>
* @return
*/
static <T> ReactiveSeq<T> enqueued(Consumer<? super Subscriber<T>> sub) {
final Counter c = new Counter();
c.active.set(1);
QueueBasedSubscriber<T> s = QueueBasedSubscriber.subscriber(c, 1);
sub.accept(s);
s.close();
return s.reactiveSeq();
}
Aggregations