本文整理汇总了Java中com.alibaba.dubbo.rpc.Invocation.getAttachment方法的典型用法代码示例。如果您正苦于以下问题:Java Invocation.getAttachment方法的具体用法?Java Invocation.getAttachment怎么用?Java Invocation.getAttachment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.rpc.Invocation
的用法示例。
在下文中一共展示了Invocation.getAttachment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeInvoke
import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
/**
* provider before
* @Title: ApplicationParamsExchange.beforeInvoke
* @param invocation
* @return void
*/
protected static void beforeInvoke(Invocation invocation) {
String invokerExchange=invocation.getAttachment(CLIENT_KEY, "");
logger.info("["+invocation.getMethodName()+"]provider invoke=>"+CLIENT_KEY+":"+ invokerExchange);
ExchangeObject invokerInfo=null;
ExchangeObject nowInvoker=_EO_INVOKER.get();
if(!StringUtils.isBlank(invokerExchange)){
try{
invokerInfo=JSON.parse(invokerExchange,ExchangeObject.class);
}catch(Exception e){}
}
if(null==nowInvoker){
_EO_INVOKER.set(invokerInfo);
nowInvoker=invokerInfo;
}
if(null==_EO_THIS.get())_EO_THIS.set(ExchangeObject.createExchangeObject(nowInvoker));
//被调用前监听
for(AbstractProvidedBeforeListener l:providedBeforeListeners){
l.listen(invokerInfo,_EO_THIS.get());
}
}
示例2: getInvocationId
import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
public static Long getInvocationId(Invocation inv) {
String id = inv.getAttachment(Constants.ID_KEY);
return id == null ? null : new Long(id);
}
示例3: collect
import com.alibaba.dubbo.rpc.Invocation; //导入方法依赖的package包/类
private void collect(Invoker<?> invoker, Invocation invocation, Result result, RpcContext context, long start, boolean error) {
try {
// ---- 服务信息获取 ----
long elapsed = System.currentTimeMillis() - start; // 计算调用耗时
int concurrent = getConcurrent(invoker, invocation).get(); // 当前并发数
String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY);
String service = invoker.getInterface().getName(); // 获取服务名称
String method = RpcUtils.getMethodName(invocation); // 获取方法名
URL url = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY);
Monitor monitor = monitorFactory.getMonitor(url);
int localPort;
String remoteKey;
String remoteValue;
if (Constants.CONSUMER_SIDE.equals(invoker.getUrl().getParameter(Constants.SIDE_KEY))) {
// ---- 服务消费方监控 ----
context = RpcContext.getContext(); // 消费方必须在invoke()之后获取context信息
localPort = 0;
remoteKey = MonitorService.PROVIDER;
remoteValue = invoker.getUrl().getAddress();
} else {
// ---- 服务提供方监控 ----
localPort = invoker.getUrl().getPort();
remoteKey = MonitorService.CONSUMER;
remoteValue = context.getRemoteHost();
}
String input = "", output = "";
if (invocation.getAttachment(Constants.INPUT_KEY) != null) {
input = invocation.getAttachment(Constants.INPUT_KEY);
}
if (result != null && result.getAttachment(Constants.OUTPUT_KEY) != null) {
output = result.getAttachment(Constants.OUTPUT_KEY);
}
monitor.collect(new URL(Constants.COUNT_PROTOCOL,
NetUtils.getLocalHost(), localPort,
service + "/" + method,
MonitorService.APPLICATION, application,
MonitorService.INTERFACE, service,
MonitorService.METHOD, method,
remoteKey, remoteValue,
error ? MonitorService.FAILURE : MonitorService.SUCCESS, "1",
MonitorService.ELAPSED, String.valueOf(elapsed),
MonitorService.CONCURRENT, String.valueOf(concurrent),
Constants.INPUT_KEY, input,
Constants.OUTPUT_KEY, output));
} catch (Throwable t) {
logger.error("Failed to monitor count service " + invoker.getUrl() + ", cause: " + t.getMessage(), t);
}
}