com.alibaba.dubbo.remoting.exchange.ResponseCallback Java Examples
The following examples show how to use
com.alibaba.dubbo.remoting.exchange.ResponseCallback.
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: DefaultFuture.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try { if (!isDone()) { this.callback = callback; } else { isdone = true; } } finally { lock.unlock(); } if (isdone) { invokeCallback(callback); } } }
Example #2
Source File: TracingResponseCallbackTest.java From brave with Apache License 2.0 | 6 votes |
@Test public void done_should_have_span_in_scope_caught() { ResponseCallback delegate = new ResponseCallback() { @Override public void done(Object response) { throw new AssertionError(); } @Override public void caught(Throwable exception) { assertThat(currentTraceContext.get()).isSameAs(invocationContext); } }; ResponseCallback callback = TracingResponseCallback.create(delegate, finishSpan, currentTraceContext, invocationContext); Throwable error = new Exception("Test exception"); callback.caught(error); verify(finishSpan).accept(null, error); }
Example #3
Source File: TracingResponseCallbackTest.java From brave with Apache License 2.0 | 6 votes |
@Test public void done_should_have_span_in_scope() { ResponseCallback delegate = new ResponseCallback() { @Override public void done(Object response) { assertThat(currentTraceContext.get()).isSameAs(invocationContext); } @Override public void caught(Throwable exception) { throw new AssertionError(); } }; ResponseCallback callback = TracingResponseCallback.create(delegate, finishSpan, currentTraceContext, invocationContext); Object result = new Object(); callback.done(result); verify(finishSpan).accept(result, null); }
Example #4
Source File: MockedClient.java From dubbox with Apache License 2.0 | 6 votes |
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: DefaultFuture.java From dubbox with Apache License 2.0 | 6 votes |
public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try{ if (!isDone()) { this.callback = callback; } else { isdone = true; } }finally { lock.unlock(); } if (isdone){ invokeCallback(callback); } } }
Example #6
Source File: MockedClient.java From dubbox with Apache License 2.0 | 6 votes |
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: DefaultFuture.java From dubbox with Apache License 2.0 | 6 votes |
public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try{ if (!isDone()) { this.callback = callback; } else { isdone = true; } }finally { lock.unlock(); } if (isdone){ invokeCallback(callback); } } }
Example #8
Source File: DefaultFuture.java From dubbo3 with Apache License 2.0 | 6 votes |
public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try{ if (!isDone()) { this.callback = callback; } else { isdone = true; } }finally { lock.unlock(); } if (isdone){ invokeCallback(callback); } } }
Example #9
Source File: MockedClient.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
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: DefaultFuture.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try{ if (!isDone()) { this.callback = callback; } else { isdone = true; } }finally { lock.unlock(); } if (isdone){ invokeCallback(callback); } } }
Example #11
Source File: MockedClient.java From dubbox with Apache License 2.0 | 6 votes |
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 #12
Source File: DefaultFuture.java From dubbox with Apache License 2.0 | 6 votes |
public void setCallback(ResponseCallback callback) { if (isDone()) { invokeCallback(callback); } else { boolean isdone = false; lock.lock(); try{ if (!isDone()) { this.callback = callback; } else { isdone = true; } }finally { lock.unlock(); } if (isdone){ invokeCallback(callback); } } }
Example #13
Source File: MockedClient.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
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 #14
Source File: FutureFilter.java From dubbox with Apache License 2.0 | 5 votes |
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 dubbo-2.6.5 with Apache License 2.0 | 5 votes |
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 #16
Source File: TracingResponseCallbackTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void done_should_forward_then_finish_span() { ResponseCallback delegate = mock(ResponseCallback.class); ResponseCallback callback = TracingResponseCallback.create(delegate, finishSpan, currentTraceContext, invocationContext); Object result = new Object(); callback.done(result); verify(delegate).done(result); verify(finishSpan).accept(result, null); }
Example #17
Source File: TracingResponseCallbackTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void done_should_finish_span_caught() { ResponseCallback callback = TracingResponseCallback.create(null, finishSpan, currentTraceContext, invocationContext); Throwable error = new Exception("Test exception"); callback.caught(error); verify(finishSpan).accept(null, error); }
Example #18
Source File: TracingResponseCallbackTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void done_should_finish_span() { ResponseCallback callback = TracingResponseCallback.create(null, finishSpan, currentTraceContext, invocationContext); callback.done(null); verify(finishSpan).accept(null, null); }
Example #19
Source File: TracingResponseCallback.java From brave with Apache License 2.0 | 5 votes |
DelegateAndFinishSpan(FinishSpan finishSpan, ResponseCallback delegate, CurrentTraceContext currentTraceContext, @Nullable TraceContext context) { super(finishSpan); this.delegate = delegate; this.current = currentTraceContext; this.context = context; }
Example #20
Source File: FutureFilter.java From dubbox with Apache License 2.0 | 5 votes |
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 #21
Source File: AlibabaResponseFutureInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onEnter(@Advice.Argument(value = 0, readOnly = false) ResponseCallback callback) { if (tracer == null) { return; } AbstractSpan<?> active = tracer.getActive(); if (active == null) { return; } callbackSpanMap.put(callback, active); ElasticApmAgent.ensureInstrumented(callback.getClass(), RESPONSE_CALLBACK_INSTRUMENTATIONS); }
Example #22
Source File: AlibabaResponseCallbackInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onEnter(@Advice.This ResponseCallback thiz, @Advice.Local("span") AbstractSpan<?> span) { span = AlibabaResponseFutureInstrumentation.callbackSpanMap.remove(thiz); if (span != null) { span.activate(); } }
Example #23
Source File: FutureFilter.java From dubbox with Apache License 2.0 | 5 votes |
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 #24
Source File: AlibabaResponseCallbackInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onEnter(@Advice.This ResponseCallback thiz, @Advice.Local("span") AbstractSpan<?> span) { span = AlibabaResponseFutureInstrumentation.callbackSpanMap.remove(thiz); if (span != null) { span.activate(); } }
Example #25
Source File: FutureFilter.java From dubbo3 with Apache License 2.0 | 5 votes |
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 #26
Source File: DubboSofaTracerFilter.java From sofa-tracer with Apache License 2.0 | 5 votes |
static ResponseCallback create(ResponseCallback delegate, Invocation invocation, Invoker<?> invoker) { if (delegate == null) { return new FinishSpan(invocation, invoker); } return new DelegateAndFinishSpan(delegate, invocation, invoker); }
Example #27
Source File: FutureFilter.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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 #28
Source File: SimpleFuture.java From dubbox with Apache License 2.0 | 4 votes |
public void setCallback(ResponseCallback callback) { callback.done(value); }
Example #29
Source File: SimpleFuture.java From dubbox with Apache License 2.0 | 4 votes |
public void setCallback(ResponseCallback callback) { callback.done(value); }
Example #30
Source File: DubboSofaTracerFilter.java From sofa-tracer with Apache License 2.0 | 4 votes |
@Override public void setCallback(ResponseCallback callback) { ResponseCallback delegate = TracingResponseCallback.create(callback, invocation, invoker); responseFuture.setCallback(delegate); }