@Override public StreamSubscription subscribe(Consumer<? super IN> onNext, Consumer<? super Throwable> onError, Runnable onComplete) { LazyConcat[] ref = {null}; StreamSubscription sub = new StreamSubscription() { @Override public void request(long n) { if (n <= 0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } super.request(n); ref[0].request(n); } @Override public void cancel() { ref[0].cancel(); super.cancel(); } }; LazyConcat c = new LazyConcat(sub,operators,onNext,onError,onComplete); ref[0]=c; return sub; }
public void emitted(long n) { if (processAll) { return; } if (wip.compareAndSet(0, 1)) { requested.accumulateAndGet(n,(a,b)->a-b); if (decrementAndCheckActive()) { addMissingRequests(); } }else { produced.accumulateAndGet(n, (a, b) -> a + b); if (incrementAndCheckInactive()) { addMissingRequests(); } } }
@Override public void cancel() { ref[0].cancel(); super.cancel(); } };
void handleMainPublisher() { if (mainActive.getAndIncrement()==0) { do { if (!sub.isOpen) { return; } if (!running) { Object next = ops.poll(); if (complete && next==null) { onComplete.run(); break; }else if(next!=null) { operatorsSub.request(1l); Operator<IN> pub = (Operator<IN>) nilsafeOut(next); running = true; nextSub(pub); } } } while (mainActive.decrementAndGet()!=0) ; } }
@Override public void onComplete() { complete =true; handleMainPublisher(); } });
public void onError(Throwable t){ emitted(1); onError.accept(t); }
public LazyConcat(StreamSubscription sub, Seq<Operator<IN>> operators, Consumer<? super IN> onNext, Consumer<? super Throwable> onError, Runnable onComplete) { this.sub = sub; this.operators = operators; this.onNext = onNext; this.onError = onError; this.onComplete = onComplete; operatorsSubscription(); operatorsSub.request(1); }
void handleMainPublisher() { if (mainActive.getAndIncrement()==0) { do { if (!sub.isOpen) { return; } if (!running) { Object next = ops.poll(); if (complete && next==null) { onComplete.run(); break; }else if(next!=null) { operatorsSub.request(1l); Operator<IN> pub = (Operator<IN>) nilsafeOut(next); running = true; nextSub(pub); } } } while (mainActive.decrementAndGet()!=0) ; } }
public void onComplete(){ running =false; handleMainPublisher(); }
public void onNext(IN e){ emitted(1); if(!sub.isOpen){ return; } try { onNext.accept(e); } catch (Throwable t) { onError.accept(t); } }
public LazyConcat(StreamSubscription sub, Seq<Operator<IN>> operators, Consumer<? super IN> onNext, Consumer<? super Throwable> onError, Runnable onComplete) { this.sub = sub; this.operators = operators; this.onNext = onNext; this.onError = onError; this.onComplete = onComplete; operatorsSubscription(); operatorsSub.request(1); }
public void nextSub(Operator<IN> op){ Subscription local = op.subscribe(this::onNext ,this::onError,this::onComplete); if(processAll){ local.request(Long.MAX_VALUE); active.set(local); return; } if (wip.compareAndSet(0, 1)) { active.set(local); long r = requested.get(); if (decrementAndCheckActive()) { this.addMissingRequests(); } if(r>0) { local.request(r); } return; } next.set(local); if(incrementAndCheckInactive()){ this.addMissingRequests(); return; } return; }
@Override public void onNext(Operator<IN> inOperator) { ops.add((Operator<IN>)nilsafeIn(inOperator)); handleMainPublisher(); }
public void onError(Throwable t){ emitted(1); onError.accept(t); }
@Override public void cancel() { ref[0].cancel(); super.cancel(); } };
@Override public StreamSubscription subscribe(Consumer<? super IN> onNext, Consumer<? super Throwable> onError, Runnable onComplete) { LazyConcat[] ref = {null}; StreamSubscription sub = new StreamSubscription() { @Override public void request(long n) { if (n <= 0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } super.request(n); ref[0].request(n); } @Override public void cancel() { ref[0].cancel(); super.cancel(); } }; LazyConcat c = new LazyConcat(sub,operators,onNext,onError,onComplete); ref[0]=c; return sub; }
if (decrementAndCheckActive()) { addMissingRequests(); if(incrementAndCheckInactive()){ addMissingRequests();
@Override public void onComplete() { complete =true; handleMainPublisher(); } });
public void onNext(IN e){ emitted(1); if(!sub.isOpen){ return; } try { onNext.accept(e); } catch (Throwable t) { onError.accept(t); } }
public void emitted(long n) { if (processAll) { return; } if (wip.compareAndSet(0, 1)) { requested.accumulateAndGet(n,(a,b)->a-b); if (decrementAndCheckActive()) { addMissingRequests(); } }else { produced.accumulateAndGet(n, (a, b) -> a + b); if (incrementAndCheckInactive()) { addMissingRequests(); } } }