Java Code Examples for com.alibaba.dubbo.rpc.support.RpcUtils#isAsync()

The following examples show how to use com.alibaba.dubbo.rpc.support.RpcUtils#isAsync() . 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: FutureFilter.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
    public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
        final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);

        fireInvokeCallback(invoker, invocation);
        // need to configure if there's return value before the invocation in order to help invoker to judge if it's
        // necessary to return future. 需要在调用之前配置是否有返回值,以便帮助调用程序判断是否需要返回future。
//        com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.com.alibaba.dubbo.rpc.Invoker.invoke()
        Result result = invoker.invoke(invocation);
        if (isAsync) {
            asyncCallback(invoker, invocation);
        } else {
            syncCallback(invoker, invocation, result);
        }
        return result;
    }
 
Example 2
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example 3
Source File: FutureFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example 4
Source File: FutureFilter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example 5
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example 6
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example 7
Source File: DubboSofaTracerFilter.java    From sofa-tracer with Apache License 2.0 4 votes vote down vote up
/**
 * rpc client handler
 * @param rpcContext
 * @param invoker
 * @param invocation
 * @return
 */
private Result doClientFilter(RpcContext rpcContext, Invoker<?> invoker, Invocation invocation) {
    // to build tracer instance
    if (dubboConsumerSofaTracer == null) {
        this.dubboConsumerSofaTracer = DubboConsumerSofaTracer
            .getDubboConsumerSofaTracerSingleton();
    }
    // get methodName
    String methodName = rpcContext.getMethodName();
    // get service interface
    String service = invoker.getInterface().getSimpleName();
    // build a dubbo rpc span
    SofaTracerSpan sofaTracerSpan = dubboConsumerSofaTracer.clientSend(service + "#"
                                                                       + methodName);
    // set tags to span
    appendRpcClientSpanTags(invoker, sofaTracerSpan);
    // do serialized and then transparent transmission to the rpc server
    String serializedSpanContext = sofaTracerSpan.getSofaTracerSpanContext()
        .serializeSpanContext();
    //put into attachments
    invocation.getAttachments().put(CommonSpanTags.RPC_TRACE_NAME, serializedSpanContext);

    boolean isOneWay = false, deferFinish = false;

    // check invoke type
    boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);

    // set invoke type tag
    if (isAsync) {
        sofaTracerSpan.setTag(CommonSpanTags.INVOKE_TYPE, "future");
    } else {
        isOneWay = RpcUtils.isOneway(invoker.getUrl(), invocation);
        if (isOneWay) {
            sofaTracerSpan.setTag(CommonSpanTags.INVOKE_TYPE, "oneway");
        } else {
            sofaTracerSpan.setTag(CommonSpanTags.INVOKE_TYPE, "sync");
        }
    }

    Result result;
    Throwable exception = null;
    String resultCode = SofaTracerConstant.RESULT_CODE_SUCCESS;
    try {
        // do invoke
        result = invoker.invoke(invocation);
        if (result.hasException()) {
            exception = result.getException();
        }
        // the case on async client invocation
        Future<Object> future = rpcContext.getFuture();
        if (future instanceof FutureAdapter) {
            deferFinish = ensureSpanFinishes(future, invocation, invoker);
        }
        return result;
    } catch (RpcException e) {
        exception = e;
        throw e;
    } catch (Throwable t) {
        exception = t;
        throw new RpcException(t);
    } finally {
        if (exception != null) {
            // finish span on exception, delay to clear tl in handleError
            handleError(exception, null);
        } else {
            // sync invoke
            if (isOneWay || !deferFinish) {
                dubboConsumerSofaTracer.clientReceive(resultCode);
            } else {
                // to clean SofaTraceContext
                SofaTraceContext sofaTraceContext = SofaTraceContextHolder
                    .getSofaTraceContext();
                SofaTracerSpan clientSpan = sofaTraceContext.pop();
                if (clientSpan != null) {
                    // Record client send event
                    sofaTracerSpan.log(LogData.CLIENT_SEND_EVENT_VALUE);
                }
                // cache the current span
                TracerSpanMap.put(getTracerSpanMapKey(invoker), sofaTracerSpan);
                if (clientSpan != null && clientSpan.getParentSofaTracerSpan() != null) {
                    //restore parent
                    sofaTraceContext.push(clientSpan.getParentSofaTracerSpan());
                }
            }
        }
    }
}