protected Object invokeMethod(Method method, Object[] args) throws Throwable { try { if (!method.isAccessible()) { method.setAccessible(true); } final Object r = method.invoke(proxyDescriptor.getProxy(), args); hasSuccessfulCall = true; return r; } catch (InvocationTargetException e) { throw e.getCause(); } }
private void log(final Method method, final boolean isFailover, final int failovers, final long delay, final Exception ex) { // log info if this has made some successful calls or // this is not the first failover final boolean info = hasSuccessfulCall || failovers != 0 || asyncCallHandler.hasSuccessfulCall(); if (!info && !LOG.isDebugEnabled()) { return; } final StringBuilder b = new StringBuilder() .append(ex + ", while invoking ") .append(proxyDescriptor.getProxyInfo().getString(method.getName())); if (failovers > 0) { b.append(" after ").append(failovers).append(" failover attempts"); } b.append(isFailover? ". Trying to failover ": ". Retrying "); b.append(delay > 0? "after sleeping for " + delay + "ms.": "immediately."); if (info) { LOG.info(b.toString()); } else { LOG.debug(b.toString(), ex); } }
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; }
private void log(final Method method, final boolean isFailover, final int failovers, final long delay, final Exception ex) { // log info if this has made some successful calls or // this is not the first failover final boolean info = hasSuccessfulCall || failovers != 0 || asyncCallHandler.hasSuccessfulCall(); if (!info && !LOG.isDebugEnabled()) { return; } final StringBuilder b = new StringBuilder() .append("Exception while invoking ") .append(proxyDescriptor.getProxyInfo().getString(method.getName())); if (failovers > 0) { b.append(" after ").append(failovers).append(" failover attempts"); } b.append(isFailover? ". Trying to failover ": ". Retrying "); b.append(delay > 0? "after sleeping for " + delay + "ms.": "immediately."); if (info) { LOG.info(b.toString(), ex); } else { LOG.debug(b.toString(), ex); } }
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; }
@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 void close() throws IOException { proxyDescriptor.close(); }
private long getFailoverCount() { return proxyDescriptor.getFailoverCount(); }
synchronized void processRetryInfo() { counters.retries++; if (retryInfo.isFailover()) { retryInvocationHandler.proxyDescriptor.failover( retryInfo.expectedFailoverCount, method, callId); counters.failovers++; } retryInfo = null; }
protected Object invokeMethod(Method method, Object[] args) throws Throwable { try { if (!method.isAccessible()) { method.setAccessible(true); } final Object r = method.invoke(proxyDescriptor.getProxy(), args); hasSuccessfulCall = true; return r; } catch (InvocationTargetException e) { throw e.getCause(); } }
protected RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider, RetryPolicy defaultPolicy, Map<String, RetryPolicy> methodNameToPolicyMap) { this.proxyDescriptor = new ProxyDescriptor<>(proxyProvider); this.defaultPolicy = defaultPolicy; this.methodNameToPolicyMap = methodNameToPolicyMap; }
@Override //RpcInvocationHandler public ConnectionId getConnectionId() { return RPC.getConnectionIdForProxy(proxyDescriptor.getProxy()); } }
@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(); } } }
private long getFailoverCount() { return proxyDescriptor.getFailoverCount(); }
protected RetryInvocationHandler(FailoverProxyProvider<T> proxyProvider, RetryPolicy defaultPolicy, Map<String, RetryPolicy> methodNameToPolicyMap) { this.proxyDescriptor = new ProxyDescriptor<>(proxyProvider); this.defaultPolicy = defaultPolicy; this.methodNameToPolicyMap = methodNameToPolicyMap; }
@Override public void close() throws IOException { proxyDescriptor.close(); }
synchronized void processRetryInfo() { counters.retries++; if (retryInfo.isFailover()) { retryInvocationHandler.proxyDescriptor.failover( retryInfo.expectedFailoverCount, method, callId); counters.failovers++; } retryInfo = null; }
@Override //RpcInvocationHandler public ConnectionId getConnectionId() { return RPC.getConnectionIdForProxy(proxyDescriptor.getProxy()); } }