Object invokeMethod() throws Throwable { if (isRpc) { Client.setCallIdAndRetryCount(callId, counters.retries, retryInvocationHandler.asyncCallHandler); } return retryInvocationHandler.invokeMethod(method, args); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final boolean isRpc = isRpcInvocation(proxyDescriptor.getProxy()); final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID; final Call call = newCall(method, args, isRpc, callId); while (true) { final CallReturn c = call.invokeOnce(); final CallReturn.State state = c.getState(); if (state == CallReturn.State.ASYNC_INVOKED) { return null; // return null for async calls } else if (c.getState() != CallReturn.State.RETRY) { return c.getReturnValue(); } } }
final boolean isRpc = isRpcInvocation(currentProxy.proxy); final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID; int retries = 0; Object ret = invokeMethod(method, args); hasMadeASuccessfulCall = true; return ret; msg += " after " + invocationFailoverCount + " fail over attempts"; msg += ". Trying to fail over " + formatSleepMessage(action.delayMillis); LOG.info(msg, e); } else { + " of class " + currentProxy.proxy.getClass().getSimpleName() + " over " + currentProxy.proxyInfo + ". Retrying " + formatSleepMessage(action.delayMillis), e);
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RetryCount.set(0); return super.invoke(proxy, method, args); }
assertTrue(RetryInvocationHandler.isRpcInvocation(unreliable)); assertTrue(RetryInvocationHandler.isRpcInvocation(xlator)); assertFalse(RetryInvocationHandler.isRpcInvocation(new Object()));
private RetryInfo handleException(final Method method, final int callId, final RetryPolicy policy, final Counters counters, final long expectFailoverCount, final Exception e) throws Exception { final RetryInfo retryInfo = RetryInfo.newRetryInfo(policy, e, counters, proxyDescriptor.idempotentOrAtMostOnce(method), expectFailoverCount); if (retryInfo.isFail()) { // fail. if (retryInfo.action.reason != null) { if (LOG.isDebugEnabled()) { LOG.debug("Exception while invoking call #" + callId + " " + proxyDescriptor.getProxyInfo().getString(method.getName()) + ". Not retrying because " + retryInfo.action.reason, e); } } throw retryInfo.getFailException(); } log(method, retryInfo.isFailover(), counters.failovers, retryInfo.delay, e); return retryInfo; }
final boolean isRpc = isRpcInvocation(currentProxy.proxy); final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID; int retries = 0; Object ret = invokeMethod(method, args); hasMadeASuccessfulCall = true; return ret; msg += " after " + invocationFailoverCount + " fail over attempts"; msg += ". Trying to fail over " + formatSleepMessage(action.delayMillis); LOG.info(msg, e); } else { + " of class " + currentProxy.proxy.getClass().getSimpleName() + " over " + currentProxy.proxyInfo + ". Retrying " + formatSleepMessage(action.delayMillis), e);
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RetryCount.set(0); return super.invoke(proxy, method, args); }
assertTrue(RetryInvocationHandler.isRpcInvocation(unreliable)); assertTrue(RetryInvocationHandler.isRpcInvocation(xlator)); assertFalse(RetryInvocationHandler.isRpcInvocation(new Object()));
private RetryInfo handleException(final Method method, final int callId, final RetryPolicy policy, final Counters counters, final long expectFailoverCount, final Exception e) throws Exception { final RetryInfo retryInfo = RetryInfo.newRetryInfo(policy, e, counters, proxyDescriptor.idempotentOrAtMostOnce(method), expectFailoverCount); if (retryInfo.isFail()) { // fail. if (retryInfo.action.reason != null) { if (LOG.isDebugEnabled()) { LOG.debug("Exception while invoking call #" + callId + " " + proxyDescriptor.getProxyInfo().getString(method.getName()) + ". Not retrying because " + retryInfo.action.reason, e); } } throw retryInfo.getFailException(); } log(method, retryInfo.isFailover(), counters.failovers, retryInfo.delay, e); return retryInfo; }
final boolean isRpc = isRpcInvocation(currentProxy.proxy); final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID; int retries = 0; Object ret = invokeMethod(method, args); hasMadeASuccessfulCall = true; return ret; msg += " after " + invocationFailoverCount + " fail over attempts"; msg += ". Trying to fail over " + formatSleepMessage(action.delayMillis); LOG.info(msg, e); } else { + " of class " + currentProxy.proxy.getClass().getSimpleName() + " over " + currentProxy.proxyInfo + ". Retrying " + formatSleepMessage(action.delayMillis), e);
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
@Override protected Object invokeMethod(Method method, Object[] args) throws Throwable { Object result = super.invokeMethod(method, args); int retryCount = RetryCount.get(); if (retryCount < this.numToDrop) { RetryCount.set(++retryCount); if (LOG.isDebugEnabled()) { LOG.debug("Drop the response. Current retryCount == " + retryCount); } throw new RetriableException("Fake Exception"); } else { if (LOG.isDebugEnabled()) { LOG.debug("retryCount == " + retryCount + ". It's time to normally process the response"); } return result; } } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final boolean isRpc = isRpcInvocation(proxyDescriptor.getProxy()); final int callId = isRpc? Client.nextCallId(): RpcConstants.INVALID_CALL_ID; final Call call = newCall(method, args, isRpc, callId); while (true) { final CallReturn c = call.invokeOnce(); final CallReturn.State state = c.getState(); if (state == CallReturn.State.ASYNC_INVOKED) { return null; // return null for async calls } else if (c.getState() != CallReturn.State.RETRY) { return c.getReturnValue(); } } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RetryCount.set(0); return super.invoke(proxy, method, args); }
/** * <p> * Create a proxy for an interface of an implementation class * using the same retry policy for each method in the interface. * </p> * @param iface the interface that the retry will implement * @param implementation the instance whose methods should be retried * @param retryPolicy the policy for retirying method call failures * @return the retry proxy */ public static Object create(Class<?> iface, Object implementation, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( implementation.getClass().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler(implementation, retryPolicy) ); }
Object invokeMethod() throws Throwable { if (isRpc) { Client.setCallIdAndRetryCount(callId, counters.retries, retryInvocationHandler.asyncCallHandler); } return retryInvocationHandler.invokeMethod(method, args); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { RetryCount.set(0); return super.invoke(proxy, method, args); }
/** * <p> * Create a proxy for an interface of an implementation class * using the same retry policy for each method in the interface. * </p> * @param iface the interface that the retry will implement * @param implementation the instance whose methods should be retried * @param retryPolicy the policy for retirying method call failures * @return the retry proxy */ public static Object create(Class<?> iface, Object implementation, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( implementation.getClass().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler(implementation, retryPolicy) ); }