当前位置: 首页>>代码示例>>Java>>正文


Java Invocation.getAttachments方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.rpc.Invocation.getAttachments方法的典型用法代码示例。如果您正苦于以下问题:Java Invocation.getAttachments方法的具体用法?Java Invocation.getAttachments怎么用?Java Invocation.getAttachments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.rpc.Invocation的用法示例。


在下文中一共展示了Invocation.getAttachments方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCallChainContextMap

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
/**
 * 接收dubbo传递的traceId和spanId
 * 设置CallChainContext的ThreadLocal数据
 *
 * @param invocation
 * @return
 */
private Map<String, String> setCallChainContextMap(Invocation invocation) {
    Map<String, String> attachments = invocation.getAttachments();

    if (null != attachments) {
        String traceIdValue = attachments.get(CallChainContext.TRACEID);
        String spanIdValue = attachments.get(CallChainContext.SPANID);

        Map<String, String> globalMap = CallChainContext.getContext().get();
        if (null == globalMap) {
            globalMap = new ConcurrentHashMap<String, String>();
        }

        if (null != traceIdValue) {
            globalMap.put(CallChainContext.TRACEID, traceIdValue);
        }

        if (null != spanIdValue) {
            spanIdValue += ".1";
            globalMap.put(CallChainContext.SPANID, spanIdValue);
        }

        CallChainContext.getContext().add(globalMap);
    }
    return attachments;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:33,代码来源:ContextFilter.java

示例2: invoke

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    Map<String, String> attachments = invocation.getAttachments();
    if (attachments != null) {
        attachments = new HashMap<String, String>(attachments);
        attachments.remove(Constants.PATH_KEY);
        attachments.remove(Constants.GROUP_KEY);
        attachments.remove(Constants.VERSION_KEY);
        attachments.remove(Constants.DUBBO_VERSION_KEY);
        attachments.remove(Constants.TOKEN_KEY);
        attachments.remove(Constants.TIMEOUT_KEY);
    }
    RpcContext.getContext()
            .setInvoker(invoker)
            .setInvocation(invocation)
            .setAttachments(attachments)
            .setLocalAddress(invoker.getUrl().getHost(), 
                             invoker.getUrl().getPort());
    if (invocation instanceof RpcInvocation) {
        ((RpcInvocation)invocation).setInvoker(invoker);
    }
    try {
        return invoker.invoke(invocation);
    } finally {
        RpcContext.removeContext();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:27,代码来源:ContextFilter.java

示例3: route

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
		URL url, final Invocation invocation) throws RpcException {
	if (invocation.getAttachments() == null) {
		return getNormalInvokers(invokers);
	} else {
		String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
		if (value == null) 
			return getNormalInvokers(invokers);
		else if (Boolean.TRUE.toString().equalsIgnoreCase(value)){
			return getMockedInvokers(invokers);
		} 
	}
	return invokers;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:15,代码来源:MockInvokersSelector.java

示例4: invoke

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:TokenFilter.java

示例5: invoke

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Map<String, String> attachments = invocation.getAttachments();
        if (attachments != null) {
            attachments = new HashMap<String, String>(attachments);
            attachments.remove(Constants.PATH_KEY);
            attachments.remove(Constants.GROUP_KEY);
            attachments.remove(Constants.VERSION_KEY);
            attachments.remove(Constants.DUBBO_VERSION_KEY);
            attachments.remove(Constants.TOKEN_KEY);
            attachments.remove(Constants.TIMEOUT_KEY);
        }
        RpcContext.getContext()
                .setInvoker(invoker)
                .setInvocation(invocation)
//                .setAttachments(attachments)  // modified by lishen
                .setLocalAddress(invoker.getUrl().getHost(),
                        invoker.getUrl().getPort());

        // modified by lishen
        if (attachments != null) {
            if (RpcContext.getContext().getAttachments() != null) {
                RpcContext.getContext().getAttachments().putAll(attachments);
            } else {
                RpcContext.getContext().setAttachments(attachments);
            }
        }

        if (invocation instanceof RpcInvocation) {
            ((RpcInvocation)invocation).setInvoker(invoker);
        }
        try {
            return invoker.invoke(invocation);
        } finally {
            RpcContext.removeContext();
        }
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:37,代码来源:ContextFilter.java

示例6: route

import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
                                  URL url, final Invocation invocation) throws RpcException {
    if (invocation.getAttachments() == null) {
        return getNormalInvokers(invokers);
    } else {
        String value = invocation.getAttachments().get(Constants.INVOCATION_NEED_MOCK);
        if (value == null)
            return getNormalInvokers(invokers);
        else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
            return getMockedInvokers(invokers);
        }
    }
    return invokers;
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:15,代码来源:MockInvokersSelector.java


注:本文中的com.alibaba.dubbo.rpc.Invocation.getAttachments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。