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

The following examples show how to use reactor.core.publisher.Operators#addCap() . 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: AssertSubscriber.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
protected final void normalRequest(long n) {
  Subscription a = s;
  if (a != null) {
    a.request(n);
  } else {
    Operators.addCap(REQUESTED, this, n);

    a = s;

    if (a != null) {
      long r = REQUESTED.getAndSet(this, 0L);

      if (r != 0L) {
        a.request(r);
      }
    }
  }
}
 
Example 2
Source File: AssertSubscriber.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
protected final void normalRequest(long n) {
	Subscription a = s;
	if (a != null) {
		a.request(n);
	} else {
		Operators.addCap(REQUESTED, this, n);

		a = s;

		if (a != null) {
			long r = REQUESTED.getAndSet(this, 0L);

			if (r != 0L) {
				a.request(r);
			}
		}
	}
}
 
Example 3
Source File: DefaultStepVerifierBuilder.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
private void updateRequested(Event<?> event) {
	RequestEvent requestEvent = null;
	if (event instanceof RequestEvent) requestEvent = (RequestEvent) event;
	else if (event instanceof SubscriptionTaskEvent) {
		SubscriptionTaskEvent ste = (SubscriptionTaskEvent) event;
		if (ste.delegate instanceof RequestEvent) {
			requestEvent = (RequestEvent) ste.delegate;
		}
	}

	if (requestEvent == null) {
		return;
	}
	else if (requestEvent.isBounded()) {
		Operators.addCap(REQUESTED, this, requestEvent.getRequestAmount());

	}
	else {
		REQUESTED.set(this, Long.MAX_VALUE);
	}
}
 
Example 4
Source File: AssertSubscriber.java    From RHub with Apache License 2.0 6 votes vote down vote up
protected final void normalRequest(long n) {
    Subscription a = s;
    if (a != null) {
        a.request(n);
    } else {
        Operators.addCap(REQUESTED, this, n);

        a = s;

        if (a != null) {
            long r = REQUESTED.getAndSet(this, 0L);

            if (r != 0L) {
                a.request(r);
            }
        }
    }
}
 
Example 5
Source File: FluxReceive.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
	if (Operators.validate(n)) {
		if (eventLoop.inEventLoop()) {
			this.receiverDemand = Operators.addCap(receiverDemand, n);
			drainReceiver();
		}
		else {
			eventLoop.execute(() -> {
				this.receiverDemand = Operators.addCap(receiverDemand, n);
				drainReceiver();
			});
		}
	}
}
 
Example 6
Source File: ResolvingOperator.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
  if (Operators.validate(n)) {
    long r = this.requested; // volatile read beforehand

    if (r > STATE_SUBSCRIBED) { // works only in case onSubscribe has not happened
      long u;
      for (; ; ) { // normal CAS loop with overflow protection
        if (r == Long.MAX_VALUE) {
          // if r == Long.MAX_VALUE then we dont care and we can loose this
          // request just in case of racing
          return;
        }
        u = Operators.addCap(r, n);
        if (REQUESTED.compareAndSet(this, r, u)) {
          // Means increment happened before onSubscribe
          return;
        } else {
          // Means increment happened after onSubscribe

          // update new state to see what exactly happened (onSubscribe |cancel | requestN)
          r = this.requested;

          // check state (expect -1 | -2 to exit, otherwise repeat)
          if (r < 0) {
            break;
          }
        }
      }
    }

    if (r == STATE_CANCELLED) { // if canceled, just exit
      return;
    }

    // if onSubscribe -> subscription exists (and we sure of that because volatile read
    // after volatile write) so we can execute requestN on the subscription
    this.s.request(n);
  }
}
 
Example 7
Source File: FluxCharSequence.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
	if (Operators.validate(n)) {
		if (Operators.addCap(REQUESTED, this, n) == 0) {
			if (n == Long.MAX_VALUE) {
				fastPath();
			}
			else {
				slowPath(n);
			}
		}
	}
}
 
Example 8
Source File: DefaultStepVerifierBuilder.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public DefaultStepVerifierBuilder<T> thenRequest(long n) {
	checkStrictlyPositive(n);
	this.script.add(new RequestEvent<>(n, "thenRequest"));
	this.hangCheckRequested = Operators.addCap(hangCheckRequested, n);
	return this;
}
 
Example 9
Source File: DefaultTestPublisher.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
	if (Operators.validate(n)) {
		Operators.addCap(REQUESTED, this, n);
		parent.wasRequested = true;
	}
}
 
Example 10
Source File: ColdTestPublisher.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void request(long n) {
	if (Operators.validate(n)) {
		Operators.addCap(REQUESTED, this, n);
		parent.wasRequested = true;
	}
}
 
Example 11
Source File: TestCallStreamObserverProducer.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static long add(TestCallStreamObserverProducer o, long n) {
    for (;;) {
        long r = REQUESTED.get(o);
        if (r == Long.MAX_VALUE) {
            return Long.MAX_VALUE;
        }
        long u = Operators.addCap(r, n);
        if ((REQUESTED).compareAndSet(o, r, u)) {
            return r;
        }
    }
}
 
Example 12
Source File: AbstractListenerReadPublisher.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		// Did a concurrent read transition to NO_DEMAND just before us?
		publisher.changeToDemandState(NO_DEMAND);
	}
}
 
Example 13
Source File: AbstractListenerReadPublisher.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		// Did a concurrent read transition to NO_DEMAND just before us?
		publisher.changeToDemandState(NO_DEMAND);
	}
}
 
Example 14
Source File: AbstractListenerReadPublisher.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		publisher.changeToDemandState(this);
	}
}
 
Example 15
Source File: AbstractListenerReadPublisher.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		// Did a concurrent read transition to NO_DEMAND just before us?
		publisher.changeToDemandState(NO_DEMAND);
	}
}
 
Example 16
Source File: AbstractListenerReadPublisher.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		// Did a concurrent read transition to NO_DEMAND just before us?
		publisher.changeToDemandState(NO_DEMAND);
	}
}
 
Example 17
Source File: AbstractListenerReadPublisher.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		publisher.changeToDemandState(this);
	}
}
 
Example 18
Source File: VirtualTimeScheduler.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
final void advanceTime(long timeShiftInNanoseconds) {
	Operators.addCap(DEFERRED_NANO_TIME, this, timeShiftInNanoseconds);
	drain();
}
 
Example 19
Source File: AbstractListenerReadPublisher.java    From spring-analysis-note with MIT License 2 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		publisher.changeToDemandState(this);
	}
}
 
Example 20
Source File: AbstractListenerReadPublisher.java    From java-technology-stack with MIT License 2 votes vote down vote up
@Override
<T> void request(AbstractListenerReadPublisher<T> publisher, long n) {
	if (Operators.validate(n)) {
		Operators.addCap(DEMAND_FIELD_UPDATER, publisher, n);
		publisher.changeToDemandState(this);
	}
}