forked from opensearch-project/flow-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rebase - add global-context index handler
Signed-off-by: Jackie Han <[email protected]>
- Loading branch information
1 parent
2fb6509
commit bae2dd7
Showing
13 changed files
with
355 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/opensearch/flowframework/function/ThrowingSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.function; | ||
|
||
/** | ||
* A supplier that can throw checked exception | ||
* | ||
* @param <T> method parameter type | ||
* @param <E> Exception type | ||
*/ | ||
@FunctionalInterface | ||
public interface ThrowingSupplier<T, E extends Exception> { | ||
T get() throws E; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/opensearch/flowframework/function/ThrowingSupplierWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.function; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ThrowingSupplierWrapper { | ||
/* | ||
* Private constructor to avoid Jacoco complaining about public constructor | ||
* not covered: https://tinyurl.com/yetc7tra | ||
*/ | ||
private ThrowingSupplierWrapper() {} | ||
|
||
/** | ||
* Utility method to use a method throwing checked exception inside a place | ||
* that does not allow throwing the corresponding checked exception (e.g., | ||
* enum initialization). | ||
* Convert the checked exception thrown by by throwingConsumer to a RuntimeException | ||
* so that the compiler won't complain. | ||
* @param <T> the method's return type | ||
* @param throwingSupplier the method reference that can throw checked exception | ||
* @return converted method reference | ||
*/ | ||
public static <T> Supplier<T> throwingSupplierWrapper(ThrowingSupplier<T, Exception> throwingSupplier) { | ||
|
||
return () -> { | ||
try { | ||
return throwingSupplier.get(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.