Java Code Examples for reactor.core.Exceptions#propagate()
The following examples show how to use
reactor.core.Exceptions#propagate() .
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: Operators.java From reactor-core with Apache License 2.0 | 6 votes |
/** * Return a wrapped {@link RejectedExecutionException} which can be thrown by the * operator. This exception denotes that an execution was rejected by a * {@link reactor.core.scheduler.Scheduler}, notably when it was already disposed. * <p> * Wrapping is done by calling both {@link Exceptions#failWithRejected(Throwable)} and * {@link #onOperatorError(Subscription, Throwable, Object, Context)} (with the passed * {@link Subscription}). * * @param original the original execution error * @param subscription the subscription to pass to onOperatorError. * @param suppressed a Throwable to be suppressed by the {@link RejectedExecutionException} (or null if not relevant) * @param dataSignal a value to be passed to {@link #onOperatorError(Subscription, Throwable, Object, Context)} (or null if not relevant) * @param context a context that might hold a local error consumer */ public static RuntimeException onRejectedExecution(Throwable original, @Nullable Subscription subscription, @Nullable Throwable suppressed, @Nullable Object dataSignal, Context context) { //we "cheat" to apply the special key for onRejectedExecution in onOperatorError if (context.hasKey(Hooks.KEY_ON_REJECTED_EXECUTION)) { context = context.put(Hooks.KEY_ON_OPERATOR_ERROR, context.get(Hooks.KEY_ON_REJECTED_EXECUTION)); } //don't create REE if original is a reactor-produced REE (not including singletons) RejectedExecutionException ree = Exceptions.failWithRejected(original); if (suppressed != null) { ree.addSuppressed(suppressed); } if (dataSignal != null) { return Exceptions.propagate(Operators.onOperatorError(subscription, ree, dataSignal, context)); } return Exceptions.propagate(Operators.onOperatorError(subscription, ree, context)); }
Example 2
Source File: HttpClientFormEncoder.java From reactor-netty with Apache License 2.0 | 6 votes |
final HttpClientFormEncoder applyChanges(HttpRequest request) { if (!needNewEncoder) { return this; } try { HttpClientFormEncoder encoder = new HttpClientFormEncoder(newFactory, request, newMultipart, newCharset, newMode); encoder.setBodyHttpDatas(getBodyListAttributes()); return encoder; } catch(ErrorDataEncoderException ee){ throw Exceptions.propagate(ee); } }
Example 3
Source File: MonoProcessor.java From reactor-core with Apache License 2.0 | 6 votes |
/** * Returns the value that completed this {@link MonoProcessor}. Returns {@code null} if the {@link MonoProcessor} has not been completed. If the * {@link MonoProcessor} is completed with an error a RuntimeException that wraps the error is thrown. * * @return the value that completed the {@link MonoProcessor}, or {@code null} if it has not been completed * * @throws RuntimeException if the {@link MonoProcessor} was completed with an error */ @Nullable public O peek() { if (!isTerminated()) { return null; } if (value != null) { return value; } if (error != null) { RuntimeException re = Exceptions.propagate(error); re = Exceptions.addSuppressed(re, new Exception("Mono#peek terminated with an error")); throw re; } return null; }
Example 4
Source File: SslProvider.java From reactor-netty with Apache License 2.0 | 6 votes |
SslProvider(SslProvider from, DefaultConfigurationType type) { this.sslContextBuilder = from.sslContextBuilder; this.type = type; if (this.sslContextBuilder != null) { updateDefaultConfiguration(); try { this.sslContext = sslContextBuilder.build(); } catch (SSLException e) { throw Exceptions.propagate(e); } } else { this.sslContext = from.sslContext; } this.handlerConfigurator = from.handlerConfigurator; this.handshakeTimeoutMillis = from.handshakeTimeoutMillis; this.closeNotifyFlushTimeoutMillis = from.closeNotifyFlushTimeoutMillis; this.closeNotifyReadTimeoutMillis = from.closeNotifyReadTimeoutMillis; this.builderHashCode = from.builderHashCode; }
Example 5
Source File: ExtraBotSupport.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Mono<Void> onMessageCreate(MessageCreateEvent event) { Message message = event.getMessage(); if (message.getContent().startsWith("!react")) { String rawCount = message.getContent().substring("!react".length()); int count = 1; if (!rawCount.isEmpty()) { try { count = Math.max(1, Math.min(20, Integer.parseInt(rawCount.trim()))); } catch (NumberFormatException e) { throw Exceptions.propagate(e); } } return Flux.fromIterable(fetch(count)) .flatMap(emoji -> message.addReaction(ReactionEmoji.unicode(emoji))) .then(); } return Mono.empty(); }
Example 6
Source File: BlockingIterable.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public boolean hasNext() { if (Schedulers.isInNonBlockingThread()) { throw new IllegalStateException("Iterating over a toIterable() / toStream() is blocking, which is not supported in thread " + Thread.currentThread().getName()); } for (; ; ) { boolean d = done; boolean empty = queue.isEmpty(); if (d) { Throwable e = error; if (e != null) { throw Exceptions.propagate(e); } else if (empty) { return false; } } if (empty) { lock.lock(); try { while (!done && queue.isEmpty()) { condition.await(); } } catch (InterruptedException ex) { run(); throw Exceptions.propagate(ex); } finally { lock.unlock(); } } else { return true; } } }
Example 7
Source File: AppCacheManifestTransformer.java From java-technology-stack with MIT License | 5 votes |
private static void writeToByteArrayOutputStream(ByteArrayOutputStream out, String toWrite) { try { byte[] bytes = toWrite.getBytes(DEFAULT_CHARSET); out.write(bytes); } catch (IOException ex) { throw Exceptions.propagate(ex); } }
Example 8
Source File: MonoError.java From reactor-core with Apache License 2.0 | 5 votes |
@Override public Object call() throws Exception { if(error instanceof Exception){ throw ((Exception)error); } throw Exceptions.propagate(error); }
Example 9
Source File: HttpClientFormEncoder.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public HttpClientForm textFile(String name, File file, @Nullable String contentType) { try { addBodyFileUpload(name, file, contentType, true); } catch (ErrorDataEncoderException e) { throw Exceptions.propagate(e); } return this; }
Example 10
Source File: ReactivePreAuthorizeAspect.java From light-security with Apache License 2.0 | 5 votes |
@SuppressWarnings("ALL") private <T extends Publisher<?>> T proceed(ProceedingJoinPoint point) { try { return (T) point.proceed(); } catch (Throwable throwable) { throw Exceptions.propagate(throwable); } }
Example 11
Source File: Cbor.java From rsocket-rpc-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public static <T> Marshaller<T> marshaller(Class<T> clazz) { return t -> { ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(); OutputStream bos = new ByteBufOutputStream(byteBuf); try { Cbor.getInstance().mapper.writeValue(bos, t); } catch (IOException e) { throw Exceptions.propagate(e); } return byteBuf; }; }
Example 12
Source File: AbstractCloudFoundryDeployer.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
/** * Return a Docker image identifier if the application Resource is for a Docker image, or {@literal null} otherwise. * * @see #getApplication(AppDeploymentRequest) */ String getDockerImage(AppDeploymentRequest request) { try { String uri = request.getResource().getURI().toString(); if (uri.startsWith("docker:")) { return uri.substring("docker:".length()); } else { return null; } } catch (IOException e) { throw Exceptions.propagate(e); } }
Example 13
Source File: GraphQLIntegrationTest.java From rsocket-rpc-java with Apache License 2.0 | 5 votes |
private static Unmarshaller<GraphQLDataFetchers.Book> unmarshaller() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new AfterburnerModule()); return byteBuf -> { try { InputStream byteBufInputStream = new ByteBufInputStream(byteBuf); Map map = mapper.readValue(byteBufInputStream, Map.class); Object bookById = map.get("bookById"); return mapper.convertValue(bookById, GraphQLDataFetchers.Book.class); } catch (Exception e) { throw Exceptions.propagate(e); } }; }
Example 14
Source File: MonoCallableOnAssembly.java From reactor-core with Apache License 2.0 | 5 votes |
@Override @Nullable @SuppressWarnings("unchecked") public T block(Duration timeout) { try { return ((Callable<T>) source).call(); } catch (Throwable e) { throw Exceptions.propagate(e); } }
Example 15
Source File: BlockingIterable.java From rsocket-rpc-java with Apache License 2.0 | 5 votes |
SubscriberIterator<T> createIterator() { Queue<T> q; try { q = Objects.requireNonNull(queueSupplier.get(), "The queueSupplier returned a null queue"); } catch (Throwable e) { throw Exceptions.propagate(e); } return new SubscriberIterator<>(q, batchSize); }
Example 16
Source File: BlockingIterable.java From rsocket-rpc-java with Apache License 2.0 | 5 votes |
@Override public boolean hasNext() { for (; ; ) { boolean d = done; boolean empty = queue.isEmpty(); if (d) { Throwable e = error; if (e != null) { throw Exceptions.propagate(e); } else if (empty) { return false; } } if (empty) { lock.lock(); try { while (!done && queue.isEmpty()) { condition.await(); } } catch (InterruptedException ex) { run(); throw Exceptions.propagate(ex); } finally { lock.unlock(); } } else { return true; } } }
Example 17
Source File: SslProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
SslProvider(SslProvider.Build builder) { this.sslContextBuilder = builder.sslCtxBuilder; this.type = builder.type; if (builder.sslContext == null) { if (sslContextBuilder != null) { if (type != null) { updateDefaultConfiguration(); } try { this.sslContext = sslContextBuilder.build(); } catch (SSLException e) { throw Exceptions.propagate(e); } } else { throw new IllegalArgumentException("Neither SslContextBuilder nor SslContext is specified"); } } else { this.sslContext = builder.sslContext; } this.handlerConfigurator = builder.handlerConfigurator; this.handshakeTimeoutMillis = builder.handshakeTimeoutMillis; this.closeNotifyFlushTimeoutMillis = builder.closeNotifyFlushTimeoutMillis; this.closeNotifyReadTimeoutMillis = builder.closeNotifyReadTimeoutMillis; this.builderHashCode = builder.hashCode(); }
Example 18
Source File: MonoError.java From reactor-core with Apache License 2.0 | 4 votes |
@Override public T block(Duration m) { throw Exceptions.propagate(error); }
Example 19
Source File: MonoError.java From reactor-core with Apache License 2.0 | 4 votes |
@Override public T block() { throw Exceptions.propagate(error); }
Example 20
Source File: RSocketResponder.java From rsocket-java with Apache License 2.0 | 4 votes |
private void handleFrame(ByteBuf frame) { try { int streamId = FrameHeaderCodec.streamId(frame); Subscriber<Payload> receiver; FrameType frameType = FrameHeaderCodec.frameType(frame); switch (frameType) { case REQUEST_FNF: handleFireAndForget(streamId, fireAndForget(payloadDecoder.apply(frame))); break; case REQUEST_RESPONSE: handleRequestResponse(streamId, requestResponse(payloadDecoder.apply(frame))); break; case CANCEL: handleCancelFrame(streamId); break; case REQUEST_N: handleRequestN(streamId, frame); break; case REQUEST_STREAM: long streamInitialRequestN = RequestStreamFrameCodec.initialRequestN(frame); Payload streamPayload = payloadDecoder.apply(frame); handleStream(streamId, requestStream(streamPayload), streamInitialRequestN, null); break; case REQUEST_CHANNEL: long channelInitialRequestN = RequestChannelFrameCodec.initialRequestN(frame); Payload channelPayload = payloadDecoder.apply(frame); handleChannel(streamId, channelPayload, channelInitialRequestN); break; case METADATA_PUSH: handleMetadataPush(metadataPush(payloadDecoder.apply(frame))); break; case PAYLOAD: // TODO: Hook in receiving socket. break; case NEXT: receiver = channelProcessors.get(streamId); if (receiver != null) { receiver.onNext(payloadDecoder.apply(frame)); } break; case COMPLETE: receiver = channelProcessors.get(streamId); if (receiver != null) { receiver.onComplete(); } break; case ERROR: receiver = channelProcessors.get(streamId); if (receiver != null) { // FIXME: when https://github.com/reactor/reactor-core/issues/2176 is resolved // This is workaround to handle specific Reactor related case when // onError call may not return normally try { receiver.onError(io.rsocket.exceptions.Exceptions.from(streamId, frame)); } catch (RuntimeException e) { if (reactor.core.Exceptions.isBubbling(e) || reactor.core.Exceptions.isErrorCallbackNotImplemented(e)) { if (LOGGER.isDebugEnabled()) { Throwable unwrapped = reactor.core.Exceptions.unwrap(e); LOGGER.debug("Unhandled dropped exception", unwrapped); } } } } break; case NEXT_COMPLETE: receiver = channelProcessors.get(streamId); if (receiver != null) { receiver.onNext(payloadDecoder.apply(frame)); receiver.onComplete(); } break; case SETUP: handleError(streamId, new IllegalStateException("Setup frame received post setup.")); break; case LEASE: default: handleError( streamId, new IllegalStateException("ServerRSocket: Unexpected frame type: " + frameType)); break; } ReferenceCountUtil.safeRelease(frame); } catch (Throwable t) { ReferenceCountUtil.safeRelease(frame); throw Exceptions.propagate(t); } }