當前位置: 首頁>>代碼示例>>Java>>正文


Java Subscription.cancel方法代碼示例

本文整理匯總了Java中org.reactivestreams.Subscription.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java Subscription.cancel方法的具體用法?Java Subscription.cancel怎麽用?Java Subscription.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.reactivestreams.Subscription的用法示例。


在下文中一共展示了Subscription.cancel方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setResource

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Sets the resource at the specified index and disposes the old resource.
 * @param index the index of the resource to set
 * @param resource the new resource
 * @return true if the resource has ben set, false if the composite has been disposed
 */
public boolean setResource(int index, Subscription resource) {
    for (;;) {
        Subscription o = get(index);
        if (o == SubscriptionHelper.CANCELLED) {
            if (resource != null) {
                resource.cancel();
            }
            return false;
        }
        if (compareAndSet(index, o, resource)) {
            if (o != null) {
                o.cancel();
            }
            return true;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:24,代碼來源:ArrayCompositeSubscription.java

示例2: cancel

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@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;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:18,代碼來源:FutureSubscriber.java

示例3: blockingGet

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Block until the first value arrives and return it, otherwise
 * return null for an empty source and rethrow any exception.
 * @return the first value or null if the source is empty
 */
public final T blockingGet() {
    if (getCount() != 0) {
        try {
            BlockingHelper.verifyNonBlocking();
            await();
        } catch (InterruptedException ex) {
            Subscription s = this.s;
            this.s = SubscriptionHelper.CANCELLED;
            if (s != null) {
                s.cancel();
            }
            throw ExceptionHelper.wrapOrThrow(ex);
        }
    }

    Throwable e = error;
    if (e != null) {
        throw ExceptionHelper.wrapOrThrow(e);
    }
    return value;
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:27,代碼來源:BlockingBaseSubscriber.java

示例4: onSubscribe

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
public void onSubscribe(Subscription subscription) {
    if (this.subscription != null) {
        subscription.cancel();
    } else {
        this.subscription = Preconditions.checkNotNull(subscription);
        subscribed.countDown();
    }
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:10,代碼來源:ReactivePublisherBackpressureOnReadyHandler.java

示例5: onWebSocketClose

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
public void onWebSocketClose(int statusCode, String reason) {
    log.info("Closing web socket");
    super.onWebSocketClose(statusCode, reason);
    Subscription subscription = subscriptionRef.get();
    if (subscription != null) {
        subscription.cancel();
    }
}
 
開發者ID:graphql-java,項目名稱:graphql-java-subscription-example,代碼行數:10,代碼來源:StockTickerWebSocket.java

示例6: validate

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Ensures that the upstream Subscription is null and returns true, otherwise
 * cancels the next Subscription and if the upstream is not the shared
 * cancelled instance, reports a ProtocolViolationException due to
 * multiple subscribe attempts.
 * @param upstream the upstream current value
 * @param next the Subscription to check for nullness and cancel if necessary
 * @param subscriber the class of the consumer to have a personalized
 * error message if the upstream already contains a non-cancelled Subscription.
 * @return true if successful, false if the upstream was non null
 */
public static boolean validate(Subscription upstream, Subscription next, Class<?> subscriber) {
    ObjectHelper.requireNonNull(next, "next is null");
    if (upstream != null) {
        next.cancel();
        if (upstream != SubscriptionHelper.CANCELLED) {
            reportDoubleSubscription(subscriber);
        }
        return false;
    }
    return true;
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:23,代碼來源:EndSubscriberHelper.java

示例7: setOnce

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Atomically updates the target upstream AtomicReference from null to the non-null
 * next Subscription, otherwise cancels next and reports a ProtocolViolationException
 * if the AtomicReference doesn't contain the shared cancelled indicator.
 * @param upstream the target AtomicReference to update
 * @param next the Subscription to set on it atomically
 * @param subscriber the class of the consumer to have a personalized
 * error message if the upstream already contains a non-cancelled Subscription.
 * @return true if successful, false if the content of the AtomicReference was non null
 */
public static boolean setOnce(AtomicReference<Subscription> upstream, Subscription next, Class<?> subscriber) {
    ObjectHelper.requireNonNull(next, "next is null");
    if (!upstream.compareAndSet(null, next)) {
        next.cancel();
        if (upstream.get() != SubscriptionHelper.CANCELLED) {
            reportDoubleSubscription(subscriber);
        }
        return false;
    }
    return true;
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:22,代碼來源:EndSubscriberHelper.java

示例8: replaceResource

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Replaces the resource at the specified index and returns the old resource.
 * @param index the index of the resource to replace
 * @param resource the new resource
 * @return the old resource, can be null
 */
public Subscription replaceResource(int index, Subscription resource) {
    for (;;) {
        Subscription o = get(index);
        if (o == SubscriptionHelper.CANCELLED) {
            if (resource != null) {
                resource.cancel();
            }
            return null;
        }
        if (compareAndSet(index, o, resource)) {
            return o;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:21,代碼來源:ArrayCompositeSubscription.java

示例9: dispose

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
public void dispose() {
    if (get(0) != SubscriptionHelper.CANCELLED) {
        int s = length();
        for (int i = 0; i < s; i++) {
            Subscription o = get(i);
            if (o != SubscriptionHelper.CANCELLED) {
                o = getAndSet(i, SubscriptionHelper.CANCELLED);
                if (o != SubscriptionHelper.CANCELLED && o != null) {
                    o.cancel();
                }
            }
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:16,代碼來源:ArrayCompositeSubscription.java

示例10: onSubscribe

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.setOnce(this, s)) {
        try {
            onSubscribe.accept(this);
        } catch (Throwable ex) {
            Exceptions.throwIfFatal(ex);
            s.cancel();
            onError(ex);
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:13,代碼來源:LambdaSubscriber.java

示例11: onSubscribe

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
public final void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;
        if (!cancelled) {
            s.request(Long.MAX_VALUE);
            if (cancelled) {
                this.s = SubscriptionHelper.CANCELLED;
                s.cancel();
            }
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:14,代碼來源:BlockingBaseSubscriber.java

示例12: cancel

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
/**
 * Cancels the upstream's Subscription.
 */
protected final void cancel() {
    Subscription s = this.s;
    this.s = SubscriptionHelper.CANCELLED;
    s.cancel();
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:9,代碼來源:DefaultSubscriber.java

示例13: drainLoop

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
final void drainLoop() {
    int missed = 1;

    long requestAmount = 0L;
    Subscription requestTarget = null;

    for (; ; ) {

        Subscription ms = missedSubscription.get();

        if (ms != null) {
            ms = missedSubscription.getAndSet(null);
        }

        long mr = missedRequested.get();
        if (mr != 0L) {
            mr = missedRequested.getAndSet(0L);
        }

        long mp = missedProduced.get();
        if (mp != 0L) {
            mp = missedProduced.getAndSet(0L);
        }

        Subscription a = actual;

        if (cancelled) {
            if (a != null) {
                a.cancel();
                actual = null;
            }
            if (ms != null) {
                ms.cancel();
            }
        } else {
            long r = requested;
            if (r != Long.MAX_VALUE) {
                long u = BackpressureHelper.addCap(r, mr);

                if (u != Long.MAX_VALUE) {
                    long v = u - mp;
                    if (v < 0L) {
                        SubscriptionHelper.reportMoreProduced(v);
                        v = 0;
                    }
                    r = v;
                } else {
                    r = u;
                }
                requested = r;
            }

            if (ms != null) {
                if (a != null) {
                    a.cancel();
                }
                actual = ms;
                if (r != 0L) {
                    requestAmount = BackpressureHelper.addCap(requestAmount, r);
                    requestTarget = ms;
                }
            } else if (a != null && mr != 0L) {
                requestAmount = BackpressureHelper.addCap(requestAmount, mr);
                requestTarget = a;
            }
        }

        missed = addAndGet(-missed);
        if (missed == 0) {
            if (requestAmount != 0L) {
                requestTarget.request(requestAmount);
            }
            return;
        }
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:77,代碼來源:SubscriptionArbiter.java

示例14: onDisposed

import org.reactivestreams.Subscription; //導入方法依賴的package包/類
@Override
protected void onDisposed(@NonNull Subscription value) {
    value.cancel();
}
 
開發者ID:akarnokd,項目名稱:RxJava3-preview,代碼行數:5,代碼來源:SubscriptionDisposable.java


注:本文中的org.reactivestreams.Subscription.cancel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。