@Override public void close() { runAndLogError(log, "Unable to close channel pools", pools::close); runAndLogError(log, "Unable to shutdown event loop", sdkEventLoopGroup.eventLoopGroup()::shutdownGracefully); }
/** * Returns the deserialized object from the given json string and target * class; or null if the given json string is null. */ public static <T> T fromJsonString(String json, Class<T> clazz) { if (json == null) { return null; } return invokeSafely(() -> OBJECT_MAPPER.readValue(json, clazz)); }
@Override public CompletableFuture<OutputT> execute(CompletableFuture<InputT> inputFuture, RequestExecutionContext context) throws Exception { return inputFuture.thenApply(safeFunction(input -> delegate.execute(input, context))); } }
/** * A wrapper around a Runnable that throws a checked exception. * * @param unsafeRunnable Something that acts like a Runnable but throws an exception * @return A Runnable that is wrapped in a try-catch converting the checked exception into a runtime exception */ public static Runnable safeRunnable(UnsafeRunnable unsafeRunnable) { return () -> { try { unsafeRunnable.run(); } catch (Exception e) { throw asRuntimeException(e); } }; }
/** * A wrapper around a Consumer that throws a checked exception. * * @param unsafeConsumer - something that acts like a consumer but throws an exception * @return a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception */ public static <I> Consumer<I> safeConsumer(UnsafeConsumer<I> unsafeConsumer) { return (input) -> { try { unsafeConsumer.accept(input); } catch (Exception e) { throw asRuntimeException(e); } }; }
/** * Encode a string according to RFC 1630: encoding for form data. */ public static String formDataEncode(String value) { return value == null ? null : invokeSafely(() -> URLEncoder.encode(value, DEFAULT_ENCODING)); }
@Override public void close() { runAndLogError(log, "Unable to close channel pools", pools::close); runAndLogError(log, "Unable to shutdown event loop", sdkEventLoopGroup.eventLoopGroup()::shutdownGracefully); }
@Override protected List<GeneratorTask> createTasks() throws Exception { return model.getPaginators().entrySet().stream() .filter(entry -> entry.getValue().isValid()) .flatMap(safeFunction(this::createSyncAndAsyncTasks)) .collect(Collectors.toList()); }
/** * A wrapper around a BiConsumer that throws a checked exception. * * @param unsafeSupplier - something that acts like a BiConsumer but throws an exception * @return a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception */ public static <T> Supplier<T> safeSupplier(UnsafeSupplier<T> unsafeSupplier) { return () -> { try { return unsafeSupplier.get(); } catch (Exception e) { throw asRuntimeException(e); } }; }
/** * Encode a string according to RFC 1630: encoding for form data. */ public static String formDataEncode(String value) { return value == null ? null : invokeSafely(() -> URLEncoder.encode(value, DEFAULT_ENCODING)); }
/** * Called when all events have been delivered to the downstream subscriber. */ private void onEventComplete() { synchronized (this) { // No op if it's already done if (isDone) { return; } isDone = true; runAndLogError(log, "Error thrown from Subscriber#onComplete, ignoring.", () -> subscriberRef.get().onComplete()); eventStreamResponseHandler.complete(); future.complete(null); } }
@Override protected List<GeneratorTask> createTasks() throws Exception { return model.getPaginators().entrySet().stream() .filter(entry -> entry.getValue().isValid()) .flatMap(safeFunction(this::createSyncAndAsyncTasks)) .collect(Collectors.toList()); }
/** * A wrapper around a BiConsumer that throws a checked exception. * * @param unsafeSupplier - something that acts like a BiConsumer but throws an exception * @return a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception */ public static <T> Supplier<T> safeSupplier(UnsafeSupplier<T> unsafeSupplier) { return () -> { try { return unsafeSupplier.get(); } catch (Exception e) { throw asRuntimeException(e); } }; }
@Override public void exceptionOccurred(Throwable throwable) { try { invokeSafely(fileChannel::close); } finally { invokeSafely(() -> Files.deleteIfExists(path)); } cf.completeExceptionally(throwable); }
@Override public void exceptionOccurred(Throwable throwable) { synchronized (this) { if (!isDone) { isDone = true; // If we have a Subscriber at this point notify it as well if (subscriberRef.get() != null && shouldSurfaceErrorToEventSubscriber(throwable)) { runAndLogError(log, "Error thrown from Subscriber#onError, ignoring.", () -> subscriberRef.get().onError(throwable)); } eventStreamResponseHandler.exceptionOccurred(throwable); transformFuture.completeExceptionally(throwable); } } }
@Override protected List<GeneratorTask> createTasks() { info("Emitting marshaller classes"); return model.getShapes().entrySet().stream() .filter(e -> shouldGenerate(e.getValue())) .flatMap(safeFunction(e -> createTask(e.getKey(), e.getValue()))) .collect(Collectors.toList()); }
/** * A wrapper around a Runnable that throws a checked exception. * * @param unsafeRunnable Something that acts like a Runnable but throws an exception * @return A Runnable that is wrapped in a try-catch converting the checked exception into a runtime exception */ public static Runnable safeRunnable(UnsafeRunnable unsafeRunnable) { return () -> { try { unsafeRunnable.run(); } catch (Exception e) { throw asRuntimeException(e); } }; }
/** * Returns the deserialized object from the given json string and target * class; or null if the given json string is null. */ public static <T> T fromJsonString(String json, Class<T> clazz) { if (json == null) { return null; } return invokeSafely(() -> OBJECT_MAPPER.readValue(json, clazz)); }
.withInput(getObjectTorrentRequest), asyncResponseTransformer); } catch (Throwable t) { runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", () -> asyncResponseTransformer.exceptionOccurred(t)); return CompletableFutureUtils.failedFuture(t);
@Override protected List<GeneratorTask> createTasks() { info("Emitting marshaller classes"); return model.getShapes().entrySet().stream() .filter(e -> shouldGenerate(e.getValue())) .flatMap(safeFunction(e -> createTask(e.getKey(), e.getValue()))) .collect(Collectors.toList()); }