Java 类io.reactivex.internal.subscriptions.SubscriptionHelper 实例源码

项目:rxjava2-extras    文件:FlowableRepeat.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        if (BackpressureHelper.add(this, n) == 0) {
            long requested = n;
            long emitted = 0;
            do {
                emitted = requested;
                while (requested-- > 0 && !cancelled && (count == -1 || counter-- > 0)) {
                    child.onNext(value);
                }
            } while ((requested = this.addAndGet(-emitted)) > 0);
            if (count >= 0 && !cancelled) {
                child.onComplete();
            }
        }
    }
}
项目:rxjava2-extras    文件:FlowableRepeatingTransform.java   
@Override
protected void subscribeActual(Subscriber<? super T> child) {

    Flowable<T> f;
    try {
        f = transform.apply(source);
    } catch (Exception e) {
        Exceptions.throwIfFatal(e);
        child.onSubscribe(SubscriptionHelper.CANCELLED);
        child.onError(e);
        return;
    }
    AtomicReference<Chain<T>> chainRef = new AtomicReference<Chain<T>>();
    DestinationSerializedSubject<T> destination = new DestinationSerializedSubject<T>(child,
            chainRef);
    Chain<T> chain = new Chain<T>(transform, destination, maxIterations, maxChained, tester);
    chainRef.set(chain);
    // destination is not initially subscribed to the chain but will be when
    // tester function result completes
    destination.subscribe(child);
    ChainedReplaySubject<T> sub = ChainedReplaySubject.create(destination, chain, tester);
    chain.initialize(sub);
    f.onTerminateDetach() //
            .subscribe(sub);
}
项目:RxJava2Extensions    文件:FlowableFlatMapSync.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.setOnce(this, s)) {
        if (s instanceof QueueSubscription) {
            @SuppressWarnings("unchecked")
            QueueSubscription<R> qs = (QueueSubscription<R>) s;

            int m = qs.requestFusion(QueueSubscription.ANY | QueueSubscription.BOUNDARY);

            if (m == QueueSubscription.SYNC) {
                fusionMode = m;
                queue = qs;
                done = true;
                parent.drain();
                return;
            }
            if (m == QueueSubscription.ASYNC) {
                fusionMode = m;
                queue = qs;
                s.request(bufferSize);
                return;
            }
        }
        s.request(bufferSize);
    }
}
项目:RxJava2Extensions    文件:FuturePerhapsSubscriber.java   
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
    for (;;) {
        Subscription a = s.get();
        if (a == this || a == SubscriptionHelper.CANCELLED) {
            return false;
        }

        if (s.compareAndSet(a, SubscriptionHelper.CANCELLED)) {
            if (a != null) {
                a.cancel();
            }
            countDown();
            return true;
        }
    }
}
项目:RxJava2Extensions    文件:SoloSubscribeOn.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        Subscription s = get();
        if (s != null) {
            scheduleRequest();
        } else {
            requested.set(true);
            s = get();
            if (s != null) {
                if (requested.getAndSet(false)) {
                    scheduleRequest();
                }
            }
        }
    }
}
项目:RxShell    文件:Harvester.java   
@Override
public void onSubscribe(Subscription subscription) {
    if (SubscriptionHelper.validate(this.subscription, subscription)) {
        this.subscription = subscription;
        customer.onSubscribe(this);
    }
}
项目:Java-EX    文件:RandomOperator.java   
@Override
public void onSubscribe(Subscription s) {
  if (SubscriptionHelper.validate(this.s, s)) {
    this.s = s;
    actual.onSubscribe(this);
  }
}
项目:RxJava2Extensions    文件:FlowableSplit.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:FlowableSplit.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);

        s.request(bufferSize);
    }
}
项目:RxJava2Extensions    文件:FlowableProcessorWrap.java   
@Override
public void cancel() {
    if (compareAndSet(false, true)) {
        s.cancel();
        s = SubscriptionHelper.CANCELLED;
    }
}
项目:RxJava2Extensions    文件:DisposableAutoReleaseSubscriber.java   
@Override
public void onNext(T t) {
    if (get() != SubscriptionHelper.CANCELLED) {
        try {
            onNext.accept(t);
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            get().cancel();
            onError(e);
        }
    }
}
项目:RxJava2Extensions    文件:NonoTimeout.java   
void otherError(Throwable t) {
    SubscriptionHelper.cancel(this);
    if (once.compareAndSet(false, true)) {
        actual.onError(t);
    } else {
        RxJavaPlugins.onError(t);
    }
}
项目:RxJava2Extensions    文件:FlowableOnBackpressureTimeout.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:FlowableOnBackpressureTimeout.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);

        s.request(Long.MAX_VALUE);
    }
}
项目:RxJava2Extensions    文件:FlowableFilterAsync.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:FlowableFilterAsync.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(upstream, s)) {
        upstream = s;

        actual.onSubscribe(this);

        s.request(bufferSize);
    }
}
项目:RxJava2Extensions    文件:FlowableSwitchFlatMap.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);

        s.request(Long.MAX_VALUE);
    }
}
项目:rxjava2-extras    文件:FlowableStateMachine.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:FlowableZipLatest.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:FlowableZipLatest.java   
@Override
public void onError(Throwable t) {
    ZipLatestCoordinator<T, ?> p = parent;
    if (p.errors.addThrowable(t)) {
        lazySet(SubscriptionHelper.CANCELLED);
        done = true;
        p.drain();
    } else {
        RxJavaPlugins.onError(t);
    }
}
项目:rxjava2-extras    文件:FlowableStateMachine.java   
@Override
public void onSubscribe(Subscription parent) {
    if (SubscriptionHelper.validate(this.parent, parent)) {
        this.parent = parent;
        child.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:FlowableRefCountTimeout.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(upstream, s)) {
        this.upstream = s;

        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:FlowableMapAsync.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(upstream, s)) {
        upstream = s;

        actual.onSubscribe(this);

        s.request(bufferSize);
    }
}
项目:rxjava2-extras    文件:FlowableMapLast.java   
@Override
public void onSubscribe(Subscription subscription) {
    if (SubscriptionHelper.validate(this.parent, subscription)) {
        this.parent = subscription;
        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:FlowableEvery.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:NonoTakeUntil.java   
@Override
public void onError(Throwable t) {
    if (once.compareAndSet(false, true)) {
        SubscriptionHelper.cancel(inner);
        actual.onError(t);
    } else {
        RxJavaPlugins.onError(t);
    }
}
项目:rxjava2-extras    文件:FlowableWindowMinMax.java   
@Override
public void onSubscribe(Subscription parent) {
    if (SubscriptionHelper.validate(this.parent, parent)) {
        this.parent = parent;
        child.onSubscribe(this);
        parent.request(windowSize - 1);
    }
}
项目:RxJava2Extensions    文件:FlowableSwitchIfEmptyManyArray.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        Subscription a = s.get();
        if (a != null) {
            a.request(n);
        }
    }
}
项目:RxJava2Extensions    文件:FlowableSwitchIfEmptyManyArray.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.replace(this.s, s)) {
        long n = requested.get();
        if (n != 0L) {
            s.request(n);
        }
    }
}
项目:rxjava2-extras    文件:FlowableOnBackpressureBufferToFile.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        scheduleDrain();
    }
}
项目:RxJava2Extensions    文件:FlowableFlatMapSync.java   
@Override
public final void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.upstream, s)) {
        this.upstream = s;

        actual.onSubscribe(this);

        s.request(maxConcurrency);
    }
}
项目:RxJava2Extensions    文件:NonoRetryWhile.java   
@Override
public void onError(Throwable t) {
    boolean b;

    try {
        b = predicate.test(t);
    } catch (Throwable ex) {
        Exceptions.throwIfFatal(ex);
        actual.onError(new CompositeException(t, ex));
        return;
    }

    if (!b) {
        actual.onError(t);
    } else {
        active = false;
        if (getAndIncrement() == 0) {
            do {
                if (SubscriptionHelper.isCancelled(s.get())) {
                    return;
                }

                if (!active) {
                    active = true;
                    source.subscribe(this);
                }
            } while (decrementAndGet() != 0);
        }
    }
}
项目:RxJava2Extensions    文件:BasicMergeSubscription.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:NonoRetryWhile.java   
@Override
public void onSubscribe(Subscription s) {
    SubscriptionHelper.replace(this.s, s);
    if (!once) {
        once = true;
        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:NonoTakeUntil.java   
void innerError(Throwable t) {
    if (once.compareAndSet(false, true)) {
        SubscriptionHelper.cancel(this);
        actual.onError(t);
    } else {
        RxJavaPlugins.onError(t);
    }
}
项目:RxJava2Extensions    文件:FlowableSpanout.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:FlowableCoalesce.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(upstream, s)) {
        upstream = s;
        actual.onSubscribe(this);

        s.request(Long.MAX_VALUE);
    }
}
项目:RxJava2Extensions    文件:FlowableCoalesce.java   
@Override
public void request(long n) {
    if (SubscriptionHelper.validate(n)) {
        BackpressureHelper.add(requested, n);
        drain();
    }
}
项目:RxJava2Extensions    文件:BasicNonoSubscriber.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);
    }
}
项目:RxJava2Extensions    文件:NonoDoFinally.java   
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;

        actual.onSubscribe(this);
    }
}