本文整理汇总了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;
}
}
}
示例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;
}
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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();
}
}
}
}
}
示例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);
}
}
}
示例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();
}
}
}
}
示例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();
}
示例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;
}
}
}
示例14: onDisposed
import org.reactivestreams.Subscription; //导入方法依赖的package包/类
@Override
protected void onDisposed(@NonNull Subscription value) {
value.cancel();
}