You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sk0x50 (via GitHub)" <gi...@apache.org> on 2023/06/21 11:28:34 UTC

[GitHub] [ignite-3] sk0x50 commented on a diff in pull request #2225: IGNITE-19539 Added exception mapper utility

sk0x50 commented on code in PR #2225:
URL: https://github.com/apache/ignite-3/pull/2225#discussion_r1236832620


##########
modules/api/src/main/java/org/apache/ignite/lang/IgniteExceptionMapperFuture.java:
##########
@@ -0,0 +1,436 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.lang;
+
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+import static org.apache.ignite.lang.IgniteExceptionMapperUtil.mapToPublicException;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * This class represents a {@link CompletableFuture}, the main purpose of this future is to automatically map
+ * internal exceptions to public ones on completion.
+ *
+ * @param <T> The result type.
+ */
+public class IgniteExceptionMapperFuture<T> extends CompletableFuture<T> {
+    /** Internal future, whose result will be used to map to a public exception if this delegate completed exceptionally. */
+    private final CompletableFuture<T> delegate;
+
+    /**
+     * Creates a new instance {@link IgniteExceptionMapperFuture} with the given {@code delegate}
+     * as an underlying future that serves all requests.
+     *
+     * @param delegate Future to be wrapped.
+     * @param <U> The result Type.
+     * @return New instance {@link IgniteExceptionMapperFuture}.
+     */
+    public static <U> IgniteExceptionMapperFuture<U> of(CompletableFuture<U> delegate) {

Review Comment:
   This makes sense to me. I will provide a utility method instead of this future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org