io.mongock.driver.api.lock.guard.proxy.LockGuardMethodHandler Maven / Gradle / Ivy
The newest version!
package io.mongock.driver.api.lock.guard.proxy;
import io.mongock.driver.api.lock.LockManager;
import java.lang.reflect.InvocationTargetException;
import javassist.util.proxy.MethodHandler;
import java.lang.reflect.Method;
import java.util.Set;
public class LockGuardMethodHandler implements MethodHandler {
private final LockGuardProxy lockGuardProxy;
public LockGuardMethodHandler(T implementation, LockManager lockManager, LockGuardProxyFactory proxyFactory, Set nonGuardedMethods) {
this.lockGuardProxy = new LockGuardProxy<>(implementation, lockManager, proxyFactory, nonGuardedMethods);
}
public LockGuardProxy getLockGuardProxy() {
return lockGuardProxy;
}
@Override
public Object invoke(Object proxy, Method method, Method method1, Object[] methodArgs) throws Throwable {
try {
return lockGuardProxy.invoke(proxy, method, methodArgs);
} catch (InvocationTargetException ex) {
if (ex.getTargetException() != null) {
throw ex.getTargetException();
}
throw ex;
}
}
}