Last active
January 3, 2021 04:36
-
-
Save skaveesh/e6590f5eec985837c231fb741d62032c to your computer and use it in GitHub Desktop.
How I Decoupled Circuit Breaker from the Code with AOP in Spring Boot for Better Code Maintenance
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
//code is omitted for brevity | |
public final class SupplierUtil { | |
@FunctionalInterface | |
public interface SupplierWithException<T, E extends Exception> { | |
T get() throws Throwable; | |
} | |
public static <T, E extends Exception> Supplier<T> rethrowSupplier(SupplierWithException<T, E> supplier) { | |
return () -> { | |
try { | |
return supplier.get(); | |
} catch (Throwable exception) { | |
throwAsUnchecked(exception); | |
return null; | |
} | |
}; | |
} | |
@SuppressWarnings("unchecked") | |
private static <E extends Throwable> void throwAsUnchecked(Throwable exception) throws E { | |
throw (E) exception; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment