com.alibaba.dubbo.remoting.exchange.ResponseFuture Java Examples

The following examples show how to use com.alibaba.dubbo.remoting.exchange.ResponseFuture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception {
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
    MockResult result = (MockResult) client.request(new RpcMessage(DemoService.class.getName(), "plus", new Class<?>[]{int.class, int.class}, new Object[]{55, 25})).get();
    System.out.println("55+25=" + result.getResult());

    for (int i = 0; i < 100; i++)
        client.request(new RpcMessage(DemoService.class.getName(), "sayHello", new Class<?>[]{String.class}, new Object[]{"qianlei" + i}));

    for (int i = 0; i < 100; i++)
        client.request(new Main.Data());

    System.out.println("=====test invoke=====");
    for (int i = 0; i < 100; i++) {
        ResponseFuture future = client.request(new Main.Data());
        System.out.println("invoke and get");
        System.out.println("invoke result:" + future.get());
    }
    System.out.println("=====the end=====");
}
 
Example #2
Source File: Main.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
Example #3
Source File: Main.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
Example #4
Source File: MockedClient.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public ResponseFuture request(Object msg, int timeout) throws RemotingException {
    this.invoked = msg;
    return new ResponseFuture() {
        public Object get() throws RemotingException {
            return received;
        }
        public Object get(int timeoutInMillis) throws RemotingException {
            return received;
        }
        public boolean isDone() {
            return true;
        }
        public void setCallback(ResponseCallback callback) {
        }
    };
}
 
Example #5
Source File: MockedClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public ResponseFuture request(Object msg, int timeout) throws RemotingException {
    this.invoked = msg;
    return new ResponseFuture() {
        public Object get() throws RemotingException {
            return received;
        }
        public Object get(int timeoutInMillis) throws RemotingException {
            return received;
        }
        public boolean isDone() {
            return true;
        }
        public void setCallback(ResponseCallback callback) {
        }
    };
}
 
Example #6
Source File: MockedClient.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
public ResponseFuture request(Object msg, int timeout) throws RemotingException {
    this.invoked = msg;
    return new ResponseFuture() {
        public Object get() throws RemotingException {
            return received;
        }

        public Object get(int timeoutInMillis) throws RemotingException {
            return received;
        }

        public boolean isDone() {
            return true;
        }

        public void setCallback(ResponseCallback callback) {
        }
    };
}
 
Example #7
Source File: Main.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
Example #8
Source File: MockedClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public ResponseFuture request(Object msg, int timeout) throws RemotingException {
    this.invoked = msg;
    return new ResponseFuture() {
        public Object get() throws RemotingException {
            return received;
        }
        public Object get(int timeoutInMillis) throws RemotingException {
            return received;
        }
        public boolean isDone() {
            return true;
        }
        public void setCallback(ResponseCallback callback) {
        }
    };
}
 
Example #9
Source File: MockedClient.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public ResponseFuture request(Object msg, int timeout) throws RemotingException {
    this.invoked = msg;
    return new ResponseFuture() {
        public Object get() throws RemotingException {
            return received;
        }
        public Object get(int timeoutInMillis) throws RemotingException {
            return received;
        }
        public boolean isDone() {
            return true;
        }
        public void setCallback(ResponseCallback callback) {
        }
    };
}
 
Example #10
Source File: Main.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
Example #11
Source File: Main.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
Example #12
Source File: FinishSpanResponseFuture.java    From brave with Apache License 2.0 5 votes vote down vote up
FinishSpanResponseFuture(
  ResponseFuture delegate, TracingFilter filter, DubboRequest request, Result result, Span span,
  @Nullable TraceContext callbackContext) {
  this.delegate = delegate;
  this.finishSpan = FinishSpan.create(filter, request, result, span);
  this.currentTraceContext = filter.currentTraceContext;
  this.callbackContext = callbackContext;
  // Ensures even if no callback added later, for example when a consumer, we finish the span
  setCallback(null);
}
 
Example #13
Source File: FutureFilter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
    Future<?> f = RpcContext.getContext().getFuture();
    if (f instanceof FutureAdapter) {
        ResponseFuture future = ((FutureAdapter<?>)f).getFuture();
        future.setCallback(new ResponseCallback() {
            public void done(Object rpcResult) {
                if (rpcResult == null){
                    logger.error(new IllegalStateException("invalid result value : null, expected "+Result.class.getName()));
                    return;
                }
                ///must be rpcResult
                if (! (rpcResult instanceof Result)){
                    logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected "+Result.class.getName()));
                    return;
                }
                Result result = (Result) rpcResult;
                if (result.hasException()) {
                    fireThrowCallback(invoker, invocation, result.getException());
                } else {
                    fireReturnCallback(invoker, invocation, result.getValue());
                }
            }
            public void caught(Throwable exception) {
                fireThrowCallback(invoker, invocation, exception);
            }
        });
    }
}
 
Example #14
Source File: FutureFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
    Future<?> f = RpcContext.getContext().getFuture();
    if (f instanceof FutureAdapter) {
        ResponseFuture future = ((FutureAdapter<?>)f).getFuture();
        future.setCallback(new ResponseCallback() {
            public void done(Object rpcResult) {
                if (rpcResult == null){
                    logger.error(new IllegalStateException("invalid result value : null, expected "+Result.class.getName()));
                    return;
                }
                ///must be rpcResult
                if (! (rpcResult instanceof Result)){
                    logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected "+Result.class.getName()));
                    return;
                }
                Result result = (Result) rpcResult;
                if (result.hasException()) {
                    fireThrowCallback(invoker, invocation, result.getException());
                } else {
                    fireReturnCallback(invoker, invocation, result.getValue());
                }
            }
            public void caught(Throwable exception) {
                fireThrowCallback(invoker, invocation, exception);
            }
        });
    }
}
 
Example #15
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
    Future<?> f = RpcContext.getContext().getFuture();
    if (f instanceof FutureAdapter) {
        ResponseFuture future = ((FutureAdapter<?>)f).getFuture();
        future.setCallback(new ResponseCallback() {
            public void done(Object rpcResult) {
                if (rpcResult == null){
                    logger.error(new IllegalStateException("invalid result value : null, expected "+Result.class.getName()));
                    return;
                }
                ///must be rpcResult
                if (! (rpcResult instanceof Result)){
                    logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected "+Result.class.getName()));
                    return;
                }
                Result result = (Result) rpcResult;
                if (result.hasException()) {
                    fireThrowCallback(invoker, invocation, result.getException());
                } else {
                    fireReturnCallback(invoker, invocation, result.getValue());
                }
            }
            public void caught(Throwable exception) {
                fireThrowCallback(invoker, invocation, exception);
            }
        });
    }
}
 
Example #16
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
    Future<?> f = RpcContext.getContext().getFuture();
    if (f instanceof FutureAdapter) {
        ResponseFuture future = ((FutureAdapter<?>)f).getFuture();
        future.setCallback(new ResponseCallback() {
            public void done(Object rpcResult) {
                if (rpcResult == null){
                    logger.error(new IllegalStateException("invalid result value : null, expected "+Result.class.getName()));
                    return;
                }
                ///must be rpcResult
                if (! (rpcResult instanceof Result)){
                    logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected "+Result.class.getName()));
                    return;
                }
                Result result = (Result) rpcResult;
                if (result.hasException()) {
                    fireThrowCallback(invoker, invocation, result.getException());
                } else {
                    fireReturnCallback(invoker, invocation, result.getValue());
                }
            }
            public void caught(Throwable exception) {
                fireThrowCallback(invoker, invocation, exception);
            }
        });
    }
}
 
Example #17
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
    Future<?> f = RpcContext.getContext().getFuture();
    if (f instanceof FutureAdapter) {
        ResponseFuture future = ((FutureAdapter<?>)f).getFuture();
        future.setCallback(new ResponseCallback() {
            public void done(Object rpcResult) {
                if (rpcResult == null){
                    logger.error(new IllegalStateException("invalid result value : null, expected "+Result.class.getName()));
                    return;
                }
                ///must be rpcResult
                if (! (rpcResult instanceof Result)){
                    logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected "+Result.class.getName()));
                    return;
                }
                Result result = (Result) rpcResult;
                if (result.hasException()) {
                    fireThrowCallback(invoker, invocation, result.getException());
                } else {
                    fireReturnCallback(invoker, invocation, result.getValue());
                }
            }
            public void caught(Throwable exception) {
                fireThrowCallback(invoker, invocation, exception);
            }
        });
    }
}
 
Example #18
Source File: DubboSofaTracerFilter.java    From sofa-tracer with Apache License 2.0 5 votes vote down vote up
boolean ensureSpanFinishes(Future<Object> future, Invocation invocation, Invoker<?> invoker) {
    boolean deferFinish = false;
    if (future instanceof FutureAdapter) {
        deferFinish = true;
        ResponseFuture original = ((FutureAdapter<Object>) future).getFuture();
        ResponseFuture wrapped = new AsyncResponseFutureDelegate(invocation, invoker, original);
        // Ensures even if no callback added later, for example when a consumer, we finish the span
        wrapped.setCallback(null);
        RpcContext.getContext().setFuture(new FutureAdapter<>(wrapped));
    }
    return deferFinish;
}
 
Example #19
Source File: FutureFilter.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void asyncCallback(final Invoker<?> invoker, final Invocation invocation) {
//        从rpc上下文中取出异步执行结果的future
        Future<?> f = RpcContext.getContext().getFuture();
        if (f instanceof FutureAdapter) {
            ResponseFuture future = ((FutureAdapter<?>) f).getFuture();
            future.setCallback(new ResponseCallback() {
                @Override
                public void done(Object rpcResult) {
                    if (rpcResult == null) {
                        logger.error(new IllegalStateException("invalid result value : null, expected " + Result.class.getName()));
                        return;
                    }
                    ///must be rpcResult
                    if (!(rpcResult instanceof Result)) {
                        logger.error(new IllegalStateException("invalid result type :" + rpcResult.getClass() + ", expected " + Result.class.getName()));
                        return;
                    }
                    Result result = (Result) rpcResult;
                    if (result.hasException()) {
//                        触发异常回调=》
                        fireThrowCallback(invoker, invocation, result.getException());
                    } else {
//                        触发返回值回调=》
                        fireReturnCallback(invoker, invocation, result.getValue());
                    }
                }

                @Override
                public void caught(Throwable exception) {
//                    异常方法回调=》
                    fireThrowCallback(invoker, invocation, exception);
                }
            });
        }
    }
 
Example #20
Source File: FutureAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ResponseFuture getFuture() {
    return future;
}
 
Example #21
Source File: MockedClient.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public ResponseFuture request(Object msg) throws RemotingException {
    return request(msg, 0);
}
 
Example #22
Source File: ClientToServerTest.java    From dubbo-remoting-netty4 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFuture() throws Exception {
    ResponseFuture future = client.request(new World("world"));
    Hello result = (Hello)future.get();
    Assert.assertEquals("hello,world", result.getName());
}
 
Example #23
Source File: ClientToServerTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void testFuture() throws Exception {
    ResponseFuture future = client.request(new World("world"));
    Hello result = (Hello)future.get();
    Assert.assertEquals("hello,world", result.getName());
}
 
Example #24
Source File: ClientToServerTest.java    From dubbo-remoting-netty4 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFuture() throws Exception {
    ResponseFuture future = client.request(new World("world"));
    Hello result = (Hello)future.get();
    Assert.assertEquals("hello,world", result.getName());
}
 
Example #25
Source File: MockChannel.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ResponseFuture send(Object request, int timeout) throws RemotingException {
    return null;
}
 
Example #26
Source File: ClientToServerTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void testFuture() throws Exception {
    ResponseFuture future = client.request(new World("world"));
    Hello result = (Hello)future.get();
    Assert.assertEquals("hello,world", result.getName());
}
 
Example #27
Source File: FutureAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public FutureAdapter(ResponseFuture future){
    this.future = future;
}
 
Example #28
Source File: ClientToServerTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void testFuture() throws Exception {
    ResponseFuture future = client.request(new World("world"));
    Hello result = (Hello)future.get();
    Assert.assertEquals("hello,world", result.getName());
}
 
Example #29
Source File: MockedClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ResponseFuture request(Object msg) throws RemotingException {
    return request(msg, 0);
}
 
Example #30
Source File: MockedClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ResponseFuture request(Object msg) throws RemotingException {
    return request(msg, 0);
}