CallReturn invoke() throws Throwable { return new CallReturn(invokeMethod()); }
@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 get(long timeout, TimeUnit unit) throws Throwable { final CallReturn c = asyncCallReturn.waitAsyncValue(timeout, unit); final Object r = c.getReturnValue(); hasSuccessfulCall = true; return r; }
/** @return true if the call is done; otherwise, return false. */ boolean isDone() { final CallReturn r = invokeOnce(); LOG.debug("#{}: {}", getCallId(), r.getState()); switch (r.getState()) { case RETURNED: case EXCEPTION: asyncCallReturn.set(r); // the async call is done return true; case RETRY: invokeOnce(); break; case WAIT_RETRY: case ASYNC_CALL_IN_PROGRESS: case ASYNC_INVOKED: // nothing to do break; default: Preconditions.checkState(false); } return false; }
@Override public Object get(long timeout, TimeUnit unit) throws Throwable { final CallReturn c = asyncCallReturn.waitAsyncValue(timeout, unit); final Object r = c.getReturnValue(); hasSuccessfulCall = true; return r; }
/** @return true if the call is done; otherwise, return false. */ boolean isDone() { final CallReturn r = invokeOnce(); LOG.debug("#{}: {}", getCallId(), r.getState()); switch (r.getState()) { case RETURNED: case EXCEPTION: asyncCallReturn.set(r); // the async call is done return true; case RETRY: invokeOnce(); break; case WAIT_RETRY: case ASYNC_CALL_IN_PROGRESS: case ASYNC_INVOKED: // nothing to do break; default: Preconditions.checkState(false); } return false; }
@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(); } } }
/** Invoke the call once without retrying. */ synchronized CallReturn invokeOnce() { try { if (retryInfo != null) { return processWaitTimeAndRetryInfo(); } // The number of times this invocation handler has ever been failed over // before this method invocation attempt. Used to prevent concurrent // failed method invocations from triggering multiple failover attempts. final long failoverCount = retryInvocationHandler.getFailoverCount(); try { return invoke(); } catch (Exception e) { if (LOG.isTraceEnabled()) { LOG.trace(toString(), e); } if (Thread.currentThread().isInterrupted()) { // If interrupted, do not retry. throw e; } retryInfo = retryInvocationHandler.handleException( method, callId, retryPolicy, counters, failoverCount, e); return processWaitTimeAndRetryInfo(); } } catch(Throwable t) { return new CallReturn(t); } }
return new CallReturn(lowerLayerAsyncGet.get(0, TimeUnit.SECONDS)); } finally { lowerLayerAsyncGet = null;
CallReturn invoke() throws Throwable { return new CallReturn(invokeMethod()); }
/** Invoke the call once without retrying. */ synchronized CallReturn invokeOnce() { try { if (retryInfo != null) { return processWaitTimeAndRetryInfo(); } // The number of times this invocation handler has ever been failed over // before this method invocation attempt. Used to prevent concurrent // failed method invocations from triggering multiple failover attempts. final long failoverCount = retryInvocationHandler.getFailoverCount(); try { return invoke(); } catch (Exception e) { if (LOG.isTraceEnabled()) { LOG.trace(toString(), e); } if (Thread.currentThread().isInterrupted()) { // If interrupted, do not retry. throw e; } retryInfo = retryInvocationHandler.handleException( method, callId, retryPolicy, counters, failoverCount, e); return processWaitTimeAndRetryInfo(); } } catch(Throwable t) { return new CallReturn(t); } }
return new CallReturn(lowerLayerAsyncGet.get(0, TimeUnit.SECONDS)); } finally { lowerLayerAsyncGet = null;