Java Code Examples for reactor.core.publisher.Operators#cancelledSubscription()

The following examples show how to use reactor.core.publisher.Operators#cancelledSubscription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReconnectMono.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onComplete() {
  final Subscription s = this.s;
  final T value = this.value;

  if (s == Operators.cancelledSubscription() || !S.compareAndSet(this, s, null)) {
    this.doFinally();
    return;
  }

  final ResolvingInner<T> p = this.parent;
  if (value == null) {
    p.terminate(new IllegalStateException("Source completed empty"));
  } else {
    p.complete(value);
  }
}
 
Example 2
Source File: ReconnectMono.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
final void doFinally() {
  if (WIP.getAndIncrement(this) != 0) {
    return;
  }

  int m = 1;
  T value;

  for (; ; ) {
    value = this.value;
    if (value != null && this.s == Operators.cancelledSubscription()) {
      this.value = null;
      this.parent.doOnValueExpired(value);
      return;
    }

    m = WIP.addAndGet(this, -m);
    if (m == 0) {
      return;
    }
  }
}
 
Example 3
Source File: AssertSubscriber.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the Subscription once but does not request anything.
 *
 * @param s the Subscription to set
 * @return true if successful, false if the current subscription is not null
 */
protected final boolean setWithoutRequesting(Subscription s) {
  Objects.requireNonNull(s, "s");
  for (; ; ) {
    Subscription a = this.s;
    if (a == Operators.cancelledSubscription()) {
      s.cancel();
      return false;
    }
    if (a != null) {
      s.cancel();
      Operators.reportSubscriptionSet();
      return false;
    }

    if (S.compareAndSet(this, null, s)) {
      return true;
    }
  }
}
 
Example 4
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the Subscription once but does not request anything.
 * @param s the Subscription to push
 * @return true if successful, false if the current subscription is not null
 */
protected final boolean setWithoutRequesting(Subscription s) {
    Objects.requireNonNull(s, "s");
    for (;;) {
        Subscription a = this.s;
        if (a == Operators.cancelledSubscription()) {
            s.cancel();
            return false;
        }
        if (a != null) {
            s.cancel();
            Operators.reportSubscriptionSet();
            return false;
        }

        if (S.compareAndSet(this, null, s)) {
            return true;
        }
    }
}
 
Example 5
Source File: AssertSubscriber.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the Subscription once but does not request anything.
 * @param s the Subscription to set
 * @return true if successful, false if the current subscription is not null
 */
protected final boolean setWithoutRequesting(Subscription s) {
	Objects.requireNonNull(s, "s");
	for (;;) {
		Subscription a = this.s;
		if (a == Operators.cancelledSubscription()) {
			s.cancel();
			return false;
		}
		if (a != null) {
			s.cancel();
			Operators.reportSubscriptionSet();
			return false;
		}

		if (S.compareAndSet(this, null, s)) {
			return true;
		}
	}
}
 
Example 6
Source File: AssertSubscriber.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
/**
 * Atomically sets the single subscription and requests the missed amount from it.
 *
 * @param s
 * @return false if this arbiter is cancelled or there was a subscription already set
 */
protected final boolean set(Subscription s) {
	Objects.requireNonNull(s, "s");
	Subscription a = this.s;
	if (a == Operators.cancelledSubscription()) {
		s.cancel();
		return false;
	}
	if (a != null) {
		s.cancel();
		Operators.reportSubscriptionSet();
		return false;
	}

	if (S.compareAndSet(this, null, s)) {

		long r = REQUESTED.getAndSet(this, 0L);

		if (r != 0L) {
			s.request(r);
		}

		return true;
	}

	a = this.s;

	if (a != Operators.cancelledSubscription()) {
		s.cancel();
		return false;
	}

	Operators.reportSubscriptionSet();
	return false;
}
 
Example 7
Source File: AssertSubscriber.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void cancel() {
	Subscription a = s;
	if (a != Operators.cancelledSubscription()) {
		a = S.getAndSet(this, Operators.cancelledSubscription());
		if (a != null && a != Operators.cancelledSubscription()) {
			a.cancel();
		}
	}
}
 
Example 8
Source File: AssertSubscriber.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Override
public void cancel() {
  Subscription a = s;
  if (a != Operators.cancelledSubscription()) {
    a = S.getAndSet(this, Operators.cancelledSubscription());
    if (a != null && a != Operators.cancelledSubscription()) {
      a.cancel();
    }
  }
}
 
Example 9
Source File: MonoSendMany.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public Object scanUnsafe(Attr key) {
	if (key == Attr.PARENT) return s;
	if (key == Attr.ACTUAL) return actual;
	if (key == Attr.REQUESTED_FROM_DOWNSTREAM) return requested;
	if (key == Attr.CANCELLED) return Operators.cancelledSubscription() == s;
	if (key == Attr.TERMINATED) return terminalSignal != null;
	if (key == Attr.BUFFERED) return queue != null ? queue.size() : 0;
	if (key == Attr.ERROR) return !hasOnComplete() ? terminalSignal : null;
	if (key == Attr.PREFETCH) return MAX_SIZE;
	return null;
}
 
Example 10
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 5 votes vote down vote up
@Override
public void cancel() {
    Subscription a = s;
    if (a != Operators.cancelledSubscription()) {
        a = S.getAndSet(this, Operators.cancelledSubscription());
        if (a != null && a != Operators.cancelledSubscription()) {
            a.cancel();
        }
    }
}
 
Example 11
Source File: BlockingIterable.java    From rsocket-rpc-java with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Object scanUnsafe(Attr key) {
  if (key == Attr.TERMINATED) return done;
  if (key == Attr.PARENT) return s;
  if (key == Attr.CANCELLED) return s == Operators.cancelledSubscription();
  if (key == Attr.PREFETCH) return batchSize;
  if (key == Attr.ERROR) return error;

  return null;
}
 
Example 12
Source File: InheritableBaseSubscriber.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
    if (S.getAndSet(this, Operators.cancelledSubscription()) != Operators
        .cancelledSubscription()) {
        //we're sure it has not been concurrently cancelled
        try {
            hookOnComplete();
        } catch (Throwable throwable) {
            //onError itself will short-circuit due to the CancelledSubscription being push above
            hookOnError(Operators.onOperatorError(throwable, currentContext()));
        } finally {
            safeHookFinally(SignalType.ON_COMPLETE);
        }
    }
}
 
Example 13
Source File: ReconnectMono.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(T value) {
  if (this.s == Operators.cancelledSubscription()) {
    this.parent.doOnValueExpired(value);
    return;
  }

  this.value = value;
  // volatile write and check on racing
  this.doFinally();
}
 
Example 14
Source File: DefaultRSocketClient.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(RSocket value) {
  if (this.s == Operators.cancelledSubscription()) {
    this.doOnValueExpired(value);
    return;
  }

  this.value = value;
  // volatile write and check on racing
  this.doFinally();
}
 
Example 15
Source File: InheritableBaseSubscriber.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
    if (S.getAndSet(this, Operators.cancelledSubscription()) != Operators
        .cancelledSubscription()) {
        //we're sure it has not been concurrently cancelled
        try {
            hookOnComplete();
        } catch (Throwable throwable) {
            //onError itself will short-circuit due to the CancelledSubscription being push above
            hookOnError(Operators.onOperatorError(throwable, currentContext()));
        } finally {
            safeHookFinally(SignalType.ON_COMPLETE);
        }
    }
}
 
Example 16
Source File: InheritableBaseSubscriber.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(Throwable t) {
    Objects.requireNonNull(t, "onError");

    if (S.getAndSet(this, Operators.cancelledSubscription()) == Operators
        .cancelledSubscription()) {
        // Already cancelled concurrently

        // Workaround for Sentinel BlockException:
        // Here we add a predicate method to decide whether exception should be dropped implicitly
        // or call the {@code onErrorDropped} hook.
        if (shouldCallErrorDropHook()) {
            Operators.onErrorDropped(t, currentContext());
        }

        return;
    }

    try {
        hookOnError(t);
    } catch (Throwable e) {
        e = Exceptions.addSuppressed(e, t);
        Operators.onErrorDropped(e, currentContext());
    } finally {
        safeHookFinally(SignalType.ON_ERROR);
    }
}
 
Example 17
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 4 votes vote down vote up
final boolean isCancelled() {
    return s == Operators.cancelledSubscription();
}
 
Example 18
Source File: AssertSubscriber.java    From rsocket-java with Apache License 2.0 4 votes vote down vote up
final boolean isCancelled() {
  return s == Operators.cancelledSubscription();
}
 
Example 19
Source File: DefaultStepVerifierBuilder.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
boolean isCancelled() {
	return get() == Operators.cancelledSubscription();
}
 
Example 20
Source File: InheritableBaseSubscriber.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDisposed() {
    return subscription == Operators.cancelledSubscription();
}