com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker
1 protected Result doInvoke(final Invocation invocation) throws Throwable {
2 RpcInvocation inv = (RpcInvocation) invocation;
3 final String methodName = RpcUtils.getMethodName(invocation);
4 inv.setAttachment(Constants.PATH_KEY, getUrl().getPath());
5 inv.setAttachment(Constants.VERSION_KEY, version);
6
7 ExchangeClient currentClient;
8 if (clients.length == 1) {
9 currentClient = clients[0];
10 } else {
11 currentClient = clients[index.getAndIncrement() % clients.length];
12 }
13 try {
14 boolean isAsync = RpcUtils.isAsync(getUrl(), invocation);
15 boolean isOneway = RpcUtils.isOneway(getUrl(), invocation);
16 int timeout = getUrl().getMethodParameter(methodName, Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
17 if (isOneway) {
18 boolean isSent = getUrl().getMethodParameter(methodName, Constants.SENT_KEY, false);
19 currentClient.send(inv, isSent);
20 RpcContext.getContext().setFuture(null);
21 return new RpcResult();
22 } else if (isAsync) {
23 ResponseFuture future = currentClient.request(inv, timeout);
24 RpcContext.getContext().setFuture(new FutureAdapter<Object>(future));
25 return new RpcResult();
26 } else {
27 RpcContext.getContext().setFuture(null);
28 return (Result) currentClient.request(inv, timeout).get();
29 }
30 } catch (TimeoutException e) {
31 throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);
32 } catch (RemotingException e) {
33 throw new RpcException(RpcException.NETWORK_EXCEPTION, "Failed to invoke remote method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);
34 }
35 }
com.alibaba.dubbo.remoting.exchange.support.DefaultFuture
1 public Object get(int timeout) throws RemotingException { 2 if (timeout <= 0) { 3 timeout = Constants.DEFAULT_TIMEOUT; 4 } 5 if (!isDone()) { 6 long start = System.currentTimeMillis(); 7 lock.lock(); 8 try { 9 while (!isDone()) { 10 done.await(timeout, TimeUnit.MILLISECONDS); 11 if (isDone() || System.currentTimeMillis() - start > timeout) { 12 break; 13 } 14 } 15 } catch (InterruptedException e) { 16 throw new RuntimeException(e); 17 } finally { 18 lock.unlock(); 19 } 20 if (!isDone()) { 21 throw new TimeoutException(sent > 0, channel, getTimeoutMessage(false)); 22 } 23 } 24 return returnFromResponse(); 25 }
private void doReceived(Response res) { lock.lock(); try { response = res; if (done != null) { done.signal(); } } finally { lock.unlock(); } if (callback != null) { invokeCallback(callback); } }