Java Code Examples for com.alibaba.dubbo.rpc.Result#getAttachment()
The following examples show how to use
com.alibaba.dubbo.rpc.Result#getAttachment() .
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: DubboSofaTracerFilter.java From sofa-tracer with Apache License 2.0 | 5 votes |
/** * append tag * @param invocation * @param sofaTracerSpan * @param result * @param isClient */ private static void appendElapsedTimeTags(Invocation invocation, SofaTracerSpan sofaTracerSpan, Result result, boolean isClient) { if (sofaTracerSpan == null) { return; } String reqSize; String respSize; String elapsed; String deElapsed; if (isClient) { reqSize = invocation.getAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE); elapsed = invocation.getAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME); respSize = result.getAttachment(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE); deElapsed = result.getAttachment(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME); sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME, parseAttachment(elapsed, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME, parseAttachment(deElapsed, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE, parseAttachment(reqSize, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE, parseAttachment(respSize, 0)); } else { reqSize = invocation.getAttachment(AttachmentKeyConstants.SERVER_DESERIALIZE_SIZE); deElapsed = invocation.getAttachment(AttachmentKeyConstants.SERVER_DESERIALIZE_TIME); respSize = result.getAttachment(AttachmentKeyConstants.SERVER_SERIALIZE_SIZE); elapsed = result.getAttachment(AttachmentKeyConstants.SERVER_SERIALIZE_TIME); sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_DESERIALIZE_SIZE, parseAttachment(reqSize, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_DESERIALIZE_TIME, parseAttachment(deElapsed, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_SERIALIZE_SIZE, parseAttachment(respSize, 0)); sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_SERIALIZE_TIME, parseAttachment(elapsed, 0)); } }
Example 2
Source File: MonitorFilter.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
private void collect(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) { try { // ---- service statistics ---- long elapsed = System.currentTimeMillis() - start; // invocation cost int concurrent = getConcurrent(invoker, invocation).get(); // current concurrent count String application = invoker.getUrl().getParameter(Constants.APPLICATION_KEY); String service = invoker.getInterface().getName(); // service name String method = RpcUtils.getMethodName(invocation); // method name String group = invoker.getUrl().getParameter(Constants.GROUP_KEY); String version = invoker.getUrl().getParameter(Constants.VERSION_KEY); URL url = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY); Monitor monitor = monitorFactory.getMonitor(url); if (monitor == null) { return; } int localPort; String remoteKey; String remoteValue; if (Constants.CONSUMER_SIDE.equals(invoker.getUrl().getParameter(Constants.SIDE_KEY))) { // ---- for service consumer ---- localPort = 0; remoteKey = MonitorService.PROVIDER; remoteValue = invoker.getUrl().getAddress(); } else { // ---- for service provider ---- localPort = invoker.getUrl().getPort(); remoteKey = MonitorService.CONSUMER; remoteValue = remoteHost; } 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, Constants.GROUP_KEY, group, Constants.VERSION_KEY, version)); } catch (Throwable t) { logger.error("Failed to monitor count service " + invoker.getUrl() + ", cause: " + t.getMessage(), t); } }
Example 3
Source File: MonitorFilter.java From dubbox with Apache License 2.0 | 4 votes |
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); } }
Example 4
Source File: MonitorFilter.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
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); } }
Example 5
Source File: MonitorFilter.java From dubbox with Apache License 2.0 | 4 votes |
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); } }
Example 6
Source File: MonitorFilter.java From dubbox with Apache License 2.0 | 4 votes |
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); } }