Java Code Examples for reactor.core.CoreSubscriber#onError()
The following examples show how to use
reactor.core.CoreSubscriber#onError() .
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: MonoSubscribeOn.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super T> actual) { Scheduler.Worker worker = scheduler.createWorker(); SubscribeOnSubscriber<T> parent = new SubscribeOnSubscriber<>(source, actual, worker); actual.onSubscribe(parent); try { worker.schedule(parent); } catch (RejectedExecutionException ree) { if (parent.s != Operators.cancelledSubscription()) { actual.onError(Operators.onRejectedExecution(ree, parent, null, null, actual.currentContext())); } } return null; }
Example 2
Source File: DirectProcessor.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { Objects.requireNonNull(actual, "subscribe"); DirectInner<T> p = new DirectInner<>(actual, this); actual.onSubscribe(p); if (add(p)) { if (p.cancelled) { remove(p); } } else { Throwable e = error; if (e != null) { actual.onError(e); } else { actual.onComplete(); } } }
Example 3
Source File: HooksTest.java From reactor-core with Apache License 2.0 | 6 votes |
private static CoreSubscriber<Object> liftSubscriber(Scannable scannable, CoreSubscriber<? super Object> sub, AtomicInteger liftCounter) { liftCounter.incrementAndGet(); return new CoreSubscriber<Object>() { @Override public void onSubscribe(Subscription s) { sub.onSubscribe(s); } @Override public void onNext(Object o) { System.out.println("Lifting " + o + " out of " + scannable.stepName()); sub.onNext((Integer) o + 100); } @Override public void onError(Throwable t) { sub.onError(t); } @Override public void onComplete() { sub.onComplete(); } }; }
Example 4
Source File: FlowableIfNonEmptyComposeTest.java From akarnokd-misc with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { TransformSubscription<T> sub = new TransformSubscription<>(actual, this); actual.onSubscribe(sub); if (transformProducer.compareAndSet(null, sub)) { if (sub.cancelled) { transformProducer.compareAndSet(sub, null); return; } drain(); } else { if (transformProducer.get() == TERMINATED) { Throwable ex = error; if (ex == null) { actual.onComplete(); } else { actual.onError(ex); } } else { actual.onError(new IllegalStateException("Only one Subscriber allowed at once")); } } }
Example 5
Source File: MonoDelay.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super Long> actual) { MonoDelayRunnable r = new MonoDelayRunnable(actual); actual.onSubscribe(r); try { r.setCancel(timedScheduler.schedule(r, delay, unit)); } catch (RejectedExecutionException ree) { if(r.cancel != OperatorDisposables.DISPOSED) { actual.onError(Operators.onRejectedExecution(ree, r, null, null, actual.currentContext())); } } }
Example 6
Source File: MonoSubscribeOnValue.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { T v = value; if (v == null) { ScheduledEmpty parent = new ScheduledEmpty(actual); actual.onSubscribe(parent); try { parent.setFuture(scheduler.schedule(parent)); } catch (RejectedExecutionException ree) { if (parent.future != OperatorDisposables.DISPOSED) { actual.onError(Operators.onRejectedExecution(ree, actual.currentContext())); } } } else { actual.onSubscribe(new ScheduledScalar<>(actual, v, scheduler)); } }
Example 7
Source File: FluxSubscribeOnValue.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { T v = value; if (v == null) { ScheduledEmpty parent = new ScheduledEmpty(actual); actual.onSubscribe(parent); try { parent.setFuture(scheduler.schedule(parent)); } catch (RejectedExecutionException ree) { if (parent.future != OperatorDisposables.DISPOSED) { actual.onError(Operators.onRejectedExecution(ree, actual.currentContext())); } } } else { actual.onSubscribe(new ScheduledScalar<>(actual, v, scheduler)); } }
Example 8
Source File: UnicastProcessor.java From reactor-core with Apache License 2.0 | 6 votes |
boolean checkTerminated(boolean d, boolean empty, CoreSubscriber<? super T> a, Queue<T> q, @Nullable T t) { if (cancelled) { Operators.onDiscard(t, a.currentContext()); Operators.onDiscardQueueWithClear(q, a.currentContext(), null); hasDownstream = false; return true; } if (d && empty) { Throwable e = error; hasDownstream = false; if (e != null) { a.onError(e); } else { a.onComplete(); } return true; } return false; }
Example 9
Source File: FluxPublishMulticast.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { PublishMulticastInner<T> pcs = new PublishMulticastInner<>(this, actual); actual.onSubscribe(pcs); if (add(pcs)) { if (pcs.requested == Long.MIN_VALUE) { remove(pcs); return; } drain(); } else { Throwable ex = error; if (ex != null) { actual.onError(ex); } else { actual.onComplete(); } } }
Example 10
Source File: MonoPublishMulticast.java From reactor-core with Apache License 2.0 | 6 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { PublishMulticastInner<T> pcs = new PublishMulticastInner<>(this, actual); actual.onSubscribe(pcs); if (add(pcs)) { if (pcs.cancelled == 1) { remove(pcs); return; } drain(); } else { Throwable ex = error; if (ex != null) { actual.onError(ex); } else { actual.onComplete(); } } }
Example 11
Source File: FluxRepeatWhen.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super T> actual) { RepeatWhenOtherSubscriber other = new RepeatWhenOtherSubscriber(); Subscriber<Long> signaller = Operators.serialize(other.completionSignal); signaller.onSubscribe(Operators.emptySubscription()); CoreSubscriber<T> serial = Operators.serialize(actual); RepeatWhenMainSubscriber<T> main = new RepeatWhenMainSubscriber<>(serial, signaller, source); other.main = main; serial.onSubscribe(main); Publisher<?> p; try { p = Objects.requireNonNull(whenSourceFactory.apply(other), "The whenSourceFactory returned a null Publisher"); } catch (Throwable e) { actual.onError(Operators.onOperatorError(e, actual.currentContext())); return null; } p.subscribe(other); if (!main.cancelled) { return main; } else { return null; } }
Example 12
Source File: MonoRunnable.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { MonoRunnableEagerSubscription s = new MonoRunnableEagerSubscription(); actual.onSubscribe(s); if (s.isCancelled()) { return; } try { run.run(); actual.onComplete(); } catch (Throwable ex) { actual.onError(Operators.onOperatorError(ex, actual.currentContext())); } }
Example 13
Source File: UnicastProcessor.java From reactor-core with Apache License 2.0 | 5 votes |
void drainFused(CoreSubscriber<? super T> a) { int missed = 1; final Queue<T> q = queue; for (;;) { if (cancelled) { // We are the holder of the queue, but we still have to perform discarding under the guarded block // to prevent any racing done by downstream this.clear(); hasDownstream = false; return; } boolean d = done; a.onNext(null); if (d) { hasDownstream = false; Throwable ex = error; if (ex != null) { a.onError(ex); } else { a.onComplete(); } return; } missed = WIP.addAndGet(this, -missed); if (missed == 0) { break; } } }
Example 14
Source File: FluxRetryWhen.java From reactor-core with Apache License 2.0 | 5 votes |
static <T> void subscribe(CoreSubscriber<? super T> s, Retry whenSourceFactory, CorePublisher<? extends T> source) { RetryWhenOtherSubscriber other = new RetryWhenOtherSubscriber(); Subscriber<Retry.RetrySignal> signaller = Operators.serialize(other.completionSignal); signaller.onSubscribe(Operators.emptySubscription()); CoreSubscriber<T> serial = Operators.serialize(s); RetryWhenMainSubscriber<T> main = new RetryWhenMainSubscriber<>(serial, signaller, source); other.main = main; serial.onSubscribe(main); Publisher<?> p; try { p = Objects.requireNonNull(whenSourceFactory.generateCompanion(other), "The whenSourceFactory returned a null Publisher"); } catch (Throwable e) { s.onError(Operators.onOperatorError(e, s.currentContext())); return; } p.subscribe(other); if (!main.cancelled) { source.subscribe(main); } }
Example 15
Source File: FluxCombineLatest.java From reactor-core with Apache License 2.0 | 5 votes |
void drainOutput() { final CoreSubscriber<? super R> a = actual; final Queue<SourceAndArray> q = queue; int missed = 1; for (; ; ) { if (cancelled) { discardQueue(q); return; } Throwable ex = error; if (ex != null) { discardQueue(q); a.onError(ex); return; } boolean d = done; boolean empty = q.isEmpty(); if (!empty) { a.onNext(null); } if (d && empty) { a.onComplete(); return; } missed = WIP.addAndGet(this, -missed); if (missed == 0) { break; } } }
Example 16
Source File: FluxFirstEmitting.java From reactor-core with Apache License 2.0 | 5 votes |
void subscribe(Publisher<? extends T>[] sources, int n, CoreSubscriber<? super T> actual) { FirstEmittingSubscriber<T>[] a = subscribers; for (int i = 0; i < n; i++) { a[i] = new FirstEmittingSubscriber<>(actual, this, i); } actual.onSubscribe(this); for (int i = 0; i < n; i++) { if (cancelled || wip != Integer.MIN_VALUE) { return; } Publisher<? extends T> p = sources[i]; if (p == null) { if (WIP.compareAndSet(this, Integer.MIN_VALUE, -1)) { actual.onError(new NullPointerException("The " + i + " th Publisher source is null")); } return; } p.subscribe(a[i]); } }
Example 17
Source File: FluxFirstNonEmptyEmitting.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
void subscribe(Publisher<? extends T>[] sources, int n, CoreSubscriber<? super T> actual) { FirstNonEmptyEmittingSubscriber<T>[] a = subscribers; for (int i = 0; i < n; i++) { a[i] = new FirstNonEmptyEmittingSubscriber<>(actual, this, i); } actual.onSubscribe(this); for (int i = 0; i < n; i++) { if (cancelled || wip != Integer.MIN_VALUE) { return; } Publisher<? extends T> p = sources[i]; if (p == null) { if (WIP.compareAndSet(this, Integer.MIN_VALUE, -1)) { actual.onError(new NullPointerException( "The " + i + " th Publisher source is null")); } return; } p.subscribe(a[i]); } }
Example 18
Source File: SubscribeOnlyOnceLifter.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public CoreSubscriber<? super T> apply(Scannable scannable, CoreSubscriber<? super T> coreSubscriber) { return new CoreSubscriber<T>() { @Override public void onSubscribe(Subscription subscription) { if (!compareAndSet(false, true)) { throw new NullPointerException("You cannot directly subscribe to a gRPC service multiple times " + "concurrently. Use Flux.share() instead."); } else { coreSubscriber.onSubscribe(subscription); } } @Override public void onNext(T t) { coreSubscriber.onNext(t); } @Override public void onError(Throwable throwable) { coreSubscriber.onError(throwable); } @Override public void onComplete() { coreSubscriber.onComplete(); } }; }
Example 19
Source File: HttpClientOperations.java From reactor-netty with Apache License 2.0 | 4 votes |
@SuppressWarnings("FutureReturnValueIgnored") void _subscribe(CoreSubscriber<? super Void> s) { HttpDataFactory df = DEFAULT_FACTORY; try { HttpClientFormEncoder encoder = new HttpClientFormEncoder(df, parent.nettyRequest, false, HttpConstants.DEFAULT_CHARSET, HttpPostRequestEncoder.EncoderMode.RFC1738); formCallback.accept(parent, encoder); encoder = encoder.applyChanges(parent.nettyRequest); df = encoder.newFactory; if (!encoder.isMultipart()) { parent.requestHeaders.remove(HttpHeaderNames.TRANSFER_ENCODING); } // Returned value is deliberately ignored parent.addHandlerFirst(NettyPipeline.ChunkedWriter, new ChunkedWriteHandler()); boolean chunked = HttpUtil.isTransferEncodingChunked(parent.nettyRequest); HttpRequest r = encoder.finalizeRequest(); if (!chunked) { HttpUtil.setTransferEncodingChunked(r, false); HttpUtil.setContentLength(r, encoder.length()); } ChannelFuture f = parent.channel() .writeAndFlush(r); Flux<Long> tail = encoder.progressFlux.onBackpressureLatest(); if (encoder.cleanOnTerminate) { tail = tail.doOnCancel(encoder) .doAfterTerminate(encoder); } if (encoder.isChunked()) { if (progressCallback != null) { progressCallback.accept(tail); } //"FutureReturnValueIgnored" this is deliberate parent.channel() .writeAndFlush(encoder); } else { if (progressCallback != null) { progressCallback.accept(FutureMono.from(f) .cast(Long.class) .switchIfEmpty(Mono.just(encoder.length())) .flux()); } } s.onComplete(); } catch (Throwable e) { Exceptions.throwIfJvmFatal(e); df.cleanRequestHttpData(parent.nettyRequest); s.onError(Exceptions.unwrap(e)); } }
Example 20
Source File: SerializedSubscriber.java From reactor-core with Apache License 2.0 | 4 votes |
void serDrainLoop(CoreSubscriber<? super T> actual) { for (; ; ) { if (cancelled) { synchronized (this) { discardMultiple(this.head); } return; } boolean d; Throwable e; LinkedArrayNode<T> n; synchronized (this) { if (cancelled) { discardMultiple(this.head); return; } if (!concurrentlyAddedContent) { drainLoopInProgress = false; return; } concurrentlyAddedContent = false; d = done; e = error; 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) { synchronized (this) { discardMultiple(n); } return; } actual.onNext(arr[i]); } n = n.next; } if (cancelled) { synchronized (this) { discardMultiple(this.head); } return; } if (e != null) { actual.onError(e); return; } else if (d) { actual.onComplete(); return; } } }