Skip to content

Instantly share code, notes, and snippets.

@mwiede
Created August 2, 2019 10:55
Show Gist options
  • Save mwiede/9c4c9ba370f5481af4b09661039369e2 to your computer and use it in GitHub Desktop.
Save mwiede/9c4c9ba370f5481af4b09661039369e2 to your computer and use it in GitHub Desktop.
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import io.github.resilience4j.retry.Retry;
public final class WebserviceFactory{
static <T> T decorateWithRetryer(final T service, Retry retry) {
InvocationHandler invocationHandler = (proxy, method, args) -> retry.executeCheckedSupplier(() -> method.invoke(service, args));
return (T) Proxy.newProxyInstance(service.getClass().getClassLoader(),
service.getClass().getInterfaces(), invocationHandler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment