default Topic<T> broadcast(){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build() .withTimeout(1); Topic<T> topic = new Topic<T>(queue,QueueFactories.<T>unboundedNonBlockingQueue()); AtomicBoolean wip = new AtomicBoolean(false); Spliterator<T> split = this.spliterator(); Continuation ref[] = {null}; Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)){ try { //use the first consuming thread to tell this Stream onto the Queue if(!split.tryAdvance(topic::offer)){ topic.close(); return Continuation.empty(); } }finally { wip.set(false); } } return ref[0]; }); ref[0]=cont; queue.addContinuation(cont); return topic; }
default <R> R foldParallel(Function<? super Stream<T>,? extends R> fn){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue().build().withTimeout(1); AtomicReference<Continuation> ref = new AtomicReference<>(null); Continuation cont = new Continuation(()->{ if(ref.get()==null && ref.compareAndSet(null,Continuation.empty())){ try { //use the first consuming thread to tell this Stream onto the Queue this.spliterator().forEachRemaining(queue::offer); }finally { queue.close(); } } return Continuation.empty(); }); ; queue.addContinuation(cont); return fn.apply(queue.jdkStream().parallel()); } default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
@Override public Stream<T> unwrapStream() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> { queue.close(); }, () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream(); } return StreamSupport.stream(new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).spliterator(), false); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }
@Override public ReactiveSeq<T> changes() { if (async == Type.NO_BACKPRESSURE) { Queue<T> discrete = QueueFactories.<T>unboundedNonBlockingQueue() .build() .withTimeout(1); Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Signal<T> signal = new Signal<T>(null, queue);
@Override public Iterator<T> iterator() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Subscription[] sub = {null}; Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> queue.close(), () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream().iterator(); } return new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).iterator(); }
default <R> ReactiveSeq<R> parallel(Function<? super Stream<T>,? extends Stream<? extends R>> fn){ Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue() .build();
default <R> ReactiveSeq<R> parallel(ForkJoinPool fj,Function<? super Stream<T>,? extends Stream<? extends R>> fn){ Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue() .build();
/** * This is the default setting, internal queues are backed by a ConcurrentLinkedQueue * This operator will return the next stage to using this Queue type if it has been changed * * @return FutureStream backed by a ConcurrentLinkedQueue */ default FutureStream<U> unboundedWaitFree() { return this.withQueueFactory(QueueFactories.unboundedNonBlockingQueue()); }
<T> Queue<T> createQueue() { Queue q; if (!backPressureOn) q = QueueFactories.unboundedNonBlockingQueue() .build(); else q = QueueFactories.boundedQueue(backPressureAfter) .build(); return q; }
public FutureStreamImpl(final LazyReact lazyReact, final Stream<U> stream) { this.simpleReact = lazyReact; this.lastActive = new LazyStreamWrapper<>(()-> stream, lazyReact); this.error = new ConsumerHolder( a -> { }); this.errorHandler = Optional.of((e) -> { error.forward.accept(e); }); this.lazyCollector = () -> new BatchingCollector<U>( getMaxActive(), this); this.queueFactory = QueueFactories.unboundedNonBlockingQueue(); this.subscription = new Subscription(); this.maxActive = lazyReact.getMaxActive(); }
public FutureStreamImpl(final LazyReact lazyReact, final Supplier<Stream<U>> stream) { this.simpleReact = lazyReact; this.lastActive = new LazyStreamWrapper<>((Supplier)stream, lazyReact); this.error = new ConsumerHolder( a -> { }); this.errorHandler = Optional.of((e) -> { error.forward.accept(e); }); this.lazyCollector = () -> new BatchingCollector<U>( getMaxActive(), this); this.queueFactory = QueueFactories.unboundedNonBlockingQueue(); this.subscription = new Subscription(); this.maxActive = lazyReact.getMaxActive(); }
default <R> R foldParallel(Function<? super Stream<T>,? extends R> fn){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue().build().withTimeout(1); AtomicReference<Continuation> ref = new AtomicReference<>(null); Continuation cont = new Continuation(()->{ if(ref.get()==null && ref.compareAndSet(null,Continuation.empty())){ try { //use the first consuming thread to tell this Stream onto the Queue this.spliterator().forEachRemaining(queue::offer); }finally { queue.close(); } } return Continuation.empty(); }); ; queue.addContinuation(cont); return fn.apply(queue.jdkStream().parallel()); } default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
default Topic<T> broadcast(){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build() .withTimeout(1); Topic<T> topic = new Topic<T>(queue,QueueFactories.<T>unboundedNonBlockingQueue()); AtomicBoolean wip = new AtomicBoolean(false); Spliterator<T> split = this.spliterator(); Continuation ref[] = {null}; Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)){ try { //use the first consuming thread to tell this Stream onto the Queue if(!split.tryAdvance(topic::offer)){ topic.close(); return Continuation.empty(); } }finally { wip.set(false); } } return ref[0]; }); ref[0]=cont; queue.addContinuation(cont); return topic; }
@Override public Stream<T> unwrapStream() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> { queue.close(); }, () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream(); } return StreamSupport.stream(new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).spliterator(), false); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }
@Override public ReactiveSeq<T> changes() { if (async == Type.NO_BACKPRESSURE) { Queue<T> discrete = QueueFactories.<T>unboundedNonBlockingQueue() .build() .withTimeout(1); Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Signal<T> signal = new Signal<T>(null, queue);
@Override public Iterator<T> iterator() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Subscription[] sub = {null}; Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> queue.close(), () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream().iterator(); } return new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).iterator(); }
default <R> ReactiveSeq<R> parallel(ForkJoinPool fj,Function<? super Stream<T>,? extends Stream<? extends R>> fn){ Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue() .build();
default <R> ReactiveSeq<R> parallel(Function<? super Stream<T>,? extends Stream<? extends R>> fn){ Queue<R> queue = QueueFactories.<R>unboundedNonBlockingQueue() .build();