Java Code Examples for org.reactivestreams.Subscriber#onComplete()
The following examples show how to use
org.reactivestreams.Subscriber#onComplete() .
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: AbstractStreamObserverAndPublisher.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
private boolean checkTerminated(boolean d, boolean empty, Subscriber<? super T> subscriber, Queue<T> q) { if (cancelled) { q.clear(); downstream = null; return true; } if (d && empty) { Throwable e = error; downstream = null; if (e != null) { subscriber.onError(e); } else { subscriber.onComplete(); } return true; } return false; }
Example 2
Source File: ConnectableProcessor.java From smallrye-mutiny with Apache License 2.0 | 6 votes |
private void manageSubscribeInTheHasSubscriptionState(Subscriber<? super T> subscriber) { // We already have a subscription, use it. // However, we could complete of failed in the meantime. subscriber.onSubscribe( new WrappedSubscription(subscription.get(), () -> this.subscriber.set(new Subscriptions.CancelledSubscriber<>()))); if (!state.compareAndSet(State.HAS_SUBSCRIPTION, State.PROCESSING)) { if (state.get() == State.FAILED) { subscriber.onError(failure.get()); } else if (state.get() == State.COMPLETE) { subscriber.onComplete(); } else { throw new IllegalStateException("Illegal transition - subscribe called in the " + state.get().name() + " state"); } } }
Example 3
Source File: SerializedProcessor.java From smallrye-mutiny with Apache License 2.0 | 6 votes |
/** * Dispatches the events contained in the queue to the given subscriber. * * @param queue the queue of event * @param subscriber the subscriber to emit the events to */ @SuppressWarnings("unchecked") public void dispatch(List<Object> queue, Subscriber<I> subscriber) { for (Object event : queue) { if (event != null) { if (event instanceof SerializedProcessor.SubscriptionEvent) { subscriber.onSubscribe(((SubscriptionEvent) event).subscription); } if (event instanceof SerializedProcessor.FailureEvent) { subscriber.onError(((FailureEvent) event).failure); return; } if (event instanceof SerializedProcessor.CompletionEvent) { subscriber.onComplete(); return; } if (event instanceof SerializedProcessor.ItemEvent) { subscriber.onNext(((ItemEvent<I>) event).item); } } } }
Example 4
Source File: FlowableFromArray.java From RxJava3-preview with Apache License 2.0 | 6 votes |
@Override void fastPath() { T[] arr = array; int f = arr.length; Subscriber<? super T> a = actual; for (int i = index; i != f; i++) { if (cancelled) { return; } T t = arr[i]; if (t == null) { a.onError(new NullPointerException("array element is null")); return; } else { a.onNext(t); } } if (cancelled) { return; } a.onComplete(); }
Example 5
Source File: HalfSerializer.java From smallrye-mutiny with Apache License 2.0 | 5 votes |
/** * Propagates the completion event or failure events (if a failure is stored in the container). * If the event cannot be dispatched, a concurrent {@code onNext} will. * * @param subscriber the downstream subscriber * @param wip the serialization work-in-progress counter * @param container the failure container */ public static void onComplete(Subscriber<?> subscriber, AtomicInteger wip, AtomicReference<Throwable> container) { if (wip.getAndIncrement() == 0) { Throwable ex = Subscriptions.terminate(container); if (ex != null) { subscriber.onError(ex); } else { subscriber.onComplete(); } } }
Example 6
Source File: FibonacciPublisher.java From Hands-On-Reactive-Programming-with-Reactor with MIT License | 5 votes |
@Override public void subscribe(Subscriber<? super Integer> subscriber) { int count = 0, a = 0, b = 1; while (count < 50) { int sum = a + b; subscriber.onNext(b); a = b; b = sum; count++; } subscriber.onComplete(); }
Example 7
Source File: ResponseHandler.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public void subscribe(Subscriber<? super ByteBuffer> subscriber) { if (this.subscriber != null) { subscriber.onComplete(); return; } this.subscriber = subscriber; channelContext.channel().attr(ChannelAttributeKey.SUBSCRIBER_KEY) .set(subscriber); subscriber.onSubscribe(new Subscription() { @Override public void request(long l) { if (running) { running = false; if (l <= 0) { subscriber.onError(new IllegalArgumentException("Demand must be positive!")); } else { subscriber.onNext(fullContent); subscriber.onComplete(); executeFuture.complete(null); } } } @Override public void cancel() { running = false; } }); }
Example 8
Source File: AbstractListenerReadPublisher.java From spring-analysis-note with MIT License | 5 votes |
<T> void onAllDataRead(AbstractListenerReadPublisher<T> publisher) { if (publisher.changeState(this, COMPLETED)) { Subscriber<? super T> s = publisher.subscriber; if (s != null) { s.onComplete(); } } else { publisher.state.get().onAllDataRead(publisher); } }
Example 9
Source File: FlowableRange.java From RxJava3-preview with Apache License 2.0 | 5 votes |
@Override void slowPath(long r) { long e = 0; int f = end; int i = index; Subscriber<? super Integer> a = actual; for (;;) { while (e != r && i != f) { if (cancelled) { return; } a.onNext(i); e++; i++; } if (i == f) { if (!cancelled) { a.onComplete(); } return; } r = get(); if (e == r) { index = i; r = addAndGet(-e); if (r == 0L) { return; } e = 0L; } } }
Example 10
Source File: AbstractListenerReadPublisher.java From java-technology-stack with MIT License | 5 votes |
<T> void onAllDataRead(AbstractListenerReadPublisher<T> publisher) { if (publisher.changeState(this, COMPLETED)) { Subscriber<? super T> s = publisher.subscriber; if (s != null) { s.onComplete(); } } else { publisher.state.get().onAllDataRead(publisher); } }
Example 11
Source File: SubscribeOnlyOnceFlowableOperator.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Subscriber<? super T> apply(final Subscriber<? super T> observer) { return new Subscriber<T>() { @Override public void onSubscribe(Subscription subscription) { if (subscribedOnce.getAndSet(true)) { throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " + "concurrently. Use Flowable.share() instead."); } else { observer.onSubscribe(subscription); } } @Override public void onNext(T t) { observer.onNext(t); } @Override public void onError(Throwable throwable) { observer.onError(throwable); } @Override public void onComplete() { observer.onComplete(); } }; }
Example 12
Source File: AmqpCreditBasedSender.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Override public void onComplete() { Subscription sub = upstream.getAndSet(Subscriptions.CANCELLED); Subscriber<? super Message<?>> subscriber = this.downstream.get(); if (sub != null && sub != Subscriptions.CANCELLED && subscriber != null) { subscriber.onComplete(); } }
Example 13
Source File: ParallelInvalid.java From RxJava3-preview with Apache License 2.0 | 5 votes |
@Override public void subscribe(Subscriber<? super Object>[] subscribers) { TestException ex = new TestException(); for (Subscriber<? super Object> s : subscribers) { EmptySubscription.error(ex, s); s.onError(ex); s.onNext(0); s.onComplete(); s.onComplete(); } }
Example 14
Source File: KafkaSink.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Override public void onComplete() { Subscriber<? super Message<?>> subscriber = downstream.getAndSet(null); if (subscriber != null) { subscriber.onComplete(); } }
Example 15
Source File: AbstractStreamObserverAndPublisher.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void drainFused(final Subscriber<? super T> subscriber) { int missed = 1; for (;;) { if (cancelled) { queue.clear(); downstream = null; return; } boolean d = done; subscriber.onNext(null); if (d) { downstream = null; Throwable ex = error; if (ex != null) { subscriber.onError(ex); } else { subscriber.onComplete(); } return; } missed = WIP.addAndGet(this, -missed); if (missed == 0) { break; } } }
Example 16
Source File: DrainUtils.java From smallrye-mutiny with Apache License 2.0 | 4 votes |
/** * Drains the queue either in a pre- or post-complete state. * * @param n the requested amount * @param downstream the downstream consumer * @param queue the queue holding available values * @param requested the atomic long keeping track of requests * @param isCancelled callback to detect cancellation * @return true if the queue was completely drained or the drain process was cancelled */ private static <T> boolean postCompleteDrain(long n, Subscriber<? super T> downstream, Queue<T> queue, AtomicLong requested, BooleanSupplier isCancelled) { long e = n & COMPLETED_MASK; for (;;) { while (e != n) { if (isCancelled.getAsBoolean()) { return true; } T t = queue.poll(); if (t == null) { downstream.onComplete(); return true; } downstream.onNext(t); e++; } if (isCancelled.getAsBoolean()) { return true; } if (queue.isEmpty()) { downstream.onComplete(); return true; } n = requested.get(); if (n == e) { n = requested.addAndGet(-(e & REQUESTED_MASK)); if ((n & REQUESTED_MASK) == 0L) { return false; } e = n & COMPLETED_MASK; } } }
Example 17
Source File: SerializedSubscriber.java From smallrye-mutiny with Apache License 2.0 | 4 votes |
void serDrainLoop(Subscriber<? super T> actual) { for (;;) { if (cancelled) { return; } boolean d; Throwable e; LinkedArrayNode<T> n; synchronized (this) { if (cancelled) { return; } if (!missed) { emitting = false; return; } missed = false; d = done; e = failure; n = head; head = null; tail = null; } while (n != null) { T[] arr = n.array; int c = n.count; for (int i = 0; i < c; i++) { if (cancelled) { return; } actual.onNext(arr[i]); } n = n.next; } if (cancelled) { return; } if (e != null) { actual.onError(e); return; } else if (d) { actual.onComplete(); return; } } }
Example 18
Source File: ConnectableProcessor.java From smallrye-reactive-streams-operators with Apache License 2.0 | 4 votes |
private void manageSubscribeInCompleteState(Subscriber<? super T> subscriber) { subscriber.onSubscribe(new EmptySubscription()); subscriber.onComplete(); }
Example 19
Source File: EmptyPublisher.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public void subscribe(Subscriber<? super T> subscriber) { subscriber.onSubscribe(SUBSCRIPTION); subscriber.onComplete(); }
Example 20
Source File: Subscriptions.java From smallrye-mutiny with Apache License 2.0 | 2 votes |
/** * Invokes {@code onSubscribe} on the given {@link Subscriber} with the <em>cancelled</em> subscription instance * followed immediately by a call to {@code onComplete}. * * @param subscriber the subscriber, must not be {@code null} */ public static void complete(Subscriber<?> subscriber) { ParameterValidation.nonNull(subscriber, "subscriber"); subscriber.onSubscribe(empty()); subscriber.onComplete(); }