本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}