Java Code Examples for org.reactivestreams.Subscription#request()

The following examples show how to use org.reactivestreams.Subscription#request() . 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: FluxGroupBy.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;
		actual.onSubscribe(this);
		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 3
Source File: FlowableToListSingle.java    From RxJava3-preview with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.validate(this.s, s)) {
        this.s = s;
        actual.onSubscribe(this);
        s.request(Long.MAX_VALUE);
    }
}
 
Example 4
Source File: MonoDelayElement.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;

		actual.onSubscribe(this);
		s.request(Long.MAX_VALUE);
	}
}
 
Example 5
Source File: MonoWhen.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		s.request(Long.MAX_VALUE);
	}
	else {
		s.cancel();
	}
}
 
Example 6
Source File: ConnectionPublisher.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Override
public synchronized void onSubscribe(Subscription s) {
    this.s = s;
    if (!cancelled) {
        s.request(1);
    } else {
        s.cancel();
    }
}
 
Example 7
Source File: FluxPublishOn.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;

		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked") QueueSubscription<T> f =
					(QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);

			if (m == Fuseable.SYNC) {
				sourceMode = Fuseable.SYNC;
				queue = f;
				done = true;

				actual.onSubscribe(this);
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = Fuseable.ASYNC;
				queue = f;

				actual.onSubscribe(this);

				s.request(Operators.unboundedOrPrefetch(prefetch));

				return;
			}
		}

		queue = queueSupplier.get();

		actual.onSubscribe(this);

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 8
Source File: FluxPublishOn.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.validate(this.s, s)) {
		this.s = s;

		if (s instanceof QueueSubscription) {
			@SuppressWarnings("unchecked") QueueSubscription<T> f =
					(QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);

			if (m == Fuseable.SYNC) {
				sourceMode = Fuseable.SYNC;
				queue = f;
				done = true;

				actual.onSubscribe(this);
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = Fuseable.ASYNC;
				queue = f;

				actual.onSubscribe(this);

				s.request(Operators.unboundedOrPrefetch(prefetch));

				return;
			}
		}

		queue = queueSupplier.get();

		actual.onSubscribe(this);

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 9
Source File: RingBufferSubscriberUtils.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
void doRequest(int n) {
  Subscription s = subscription;
  if (s != null) {
    pendingRequest.addAndGet(n);
    index = ringBuffer.next(n);
    s.request(n);
  }
}
 
Example 10
Source File: FluxPublish.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		if (s instanceof Fuseable.QueueSubscription) {
			@SuppressWarnings("unchecked") Fuseable.QueueSubscription<T> f =
					(Fuseable.QueueSubscription<T>) s;

			int m = f.requestFusion(Fuseable.ANY | Fuseable.THREAD_BARRIER);
			if (m == Fuseable.SYNC) {
				sourceMode = m;
				queue = f;
				drain();
				return;
			}
			if (m == Fuseable.ASYNC) {
				sourceMode = m;
				queue = f;
				s.request(Operators.unboundedOrPrefetch(prefetch));
				return;
			}
		}

		queue = parent.queueSupplier.get();

		s.request(Operators.unboundedOrPrefetch(prefetch));
	}
}
 
Example 11
Source File: PublisherSkipUntil.java    From reactive-streams-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    main.setOther(s);

    s.request(Long.MAX_VALUE);
}
 
Example 12
Source File: UndertowHttpHandlerAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void onSubscribe(Subscription subscription) {
	subscription.request(Long.MAX_VALUE);
}
 
Example 13
Source File: PublisherWindowBoundary.java    From reactive-streams-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.setOnce(S, this, s)) {
        s.request(Long.MAX_VALUE);
    }
}
 
Example 14
Source File: ChannelOperations.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Override
public final void onSubscribe(Subscription s) {
	if (Operators.setOnce(OUTBOUND_CLOSE, this, s)) {
		s.request(Long.MAX_VALUE);
	}
}
 
Example 15
Source File: RecordingSubscriber.java    From retrofit2-reactor-adapter with Apache License 2.0 4 votes vote down vote up
@Override public void onSubscribe(Subscription s) {
  this.s = s;
  s.request(initialRequest);
}
 
Example 16
Source File: RingBufferProcessor.java    From camunda-bpm-reactor with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void request(long n) {
  if (n <= 0l) {
    subscriber.onError(SpecificationExceptions.spec_3_09_exception(n));
    return;
  }

  if (!eventProcessor.isRunning()) {
    return;
  }

  if (pendingRequest.addAndGet(n) < 0) {
    pendingRequest.set(Long.MAX_VALUE);
  }
  //buffered data in producer unpublished
  final long currentSequence = eventProcessor.nextSequence;
  final long cursor = ringBuffer.getCursor();

  //if the current subscriber sequence behind ringBuffer cursor, count the distance from the next slot to the end
  final long buffered = currentSequence < cursor
    ? cursor - (currentSequence == Sequencer.INITIAL_CURSOR_VALUE
    ? currentSequence + 1l
    : currentSequence)
    : 0l;

  final long toRequest;
  if (buffered > 0l) {
    toRequest = (n - buffered) < 0l ? 0 : n - buffered;
  } else {
    toRequest = n;
  }

  if (toRequest > 0l) {
    Subscription parent = upstreamSubscription;
    if (parent != null) {
      parent.request(toRequest);
    }
  }

}
 
Example 17
Source File: PublisherWindowBoundaryAndSize.java    From reactive-streams-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.setOnce(S, this, s)) {
        s.request(Long.MAX_VALUE);
    }
}
 
Example 18
Source File: LatchedSubscriber.java    From RHub with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
    s.request(Long.MAX_VALUE);
}
 
Example 19
Source File: FluxSampleFirst.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public void onSubscribe(Subscription s) {
	if (Operators.setOnce(S, this, s)) {
		s.request(Long.MAX_VALUE);
	}
}
 
Example 20
Source File: ForEachSequenceMTest.java    From cyclops with Apache License 2.0 3 votes vote down vote up
@Test
public void forEachXWithErrorExample(){
    
   
    Subscription s = Spouts.of(10,20,30)
                                   .map(this::process)
                                   .forEach( 2,System.out::println, System.err::println);
       
       System.out.println("Completed 2");
       s.request(1);
       System.out.println("Finished all!");
       
}