@Override public TransactionContext get(Object target, Method method, Object[] args) { String context = RpcContext.getContext().getAttachment(TransactionContextConstants.TRANSACTION_CONTEXT); if (StringUtils.isNotEmpty(context)) { return JSON.parseObject(context, TransactionContext.class); } return null; }
private long id() throws IOException { String userHome = System.getProperty("user.home"); if (StringUtils.isNotEmpty(userHome)) { File dstDirectory = new File(userHome, ".dst"); boolean dstDirectoryExists = dstDirectory.exists(); if (!dstDirectoryExists) { dstDirectoryExists = dstDirectory.mkdir(); } if (dstDirectoryExists) { File lock = new File(dstDirectory, "unique-id.lock"); boolean lockExists = dstDirectory.exists(); if (!lockExists) { lockExists = lock.createNewFile(); } if (lockExists) { RandomAccessFile randomAccessFile = new RandomAccessFile(lock, "rw"); FileChannel fileChannel = randomAccessFile.getChannel(); for (int i = 0; i < maxId; i++) { if (fileChannel.tryLock(i, 1, false) != null) { return i; } } } } } return -1; }
/** Alternative to {@link #getStatus}, but for Servlet 2.5+ */ @Override public Collection<KeyValueAnnotation> responseAnnotations() { String status = getHeader("status"); String message = getHeader("message"); if(StringUtils.isNotEmpty(status)) { if (Integer.parseInt(status) != 0) { KeyValueAnnotation keyValueAnnotation1 = KeyValueAnnotation.create(DubboKeys.HTTP_STATUS, status); KeyValueAnnotation keyValueAnnotation2 = KeyValueAnnotation.create(DubboKeys.HTTP_MESSAGE, message); return Lists.newArrayList(keyValueAnnotation1 ,keyValueAnnotation2); } } return Collections.singleton( KeyValueAnnotation.create(zipkin.TraceKeys.HTTP_STATUS_CODE, String.valueOf(httpStatus)) ); } }
@Override public void process(WatchedEvent event) throws Exception { if (listener != null) { String path = event.getPath() == null ? "" : event.getPath(); listener.childChanged(path, // if path is null, curator using watcher will throw NullPointerException. // if client connect or disconnect to server, zookeeper will queue // watched event(Watcher.Event.EventType.None, .., path = null). StringUtils.isNotEmpty(path) ? client.getChildren().usingWatcher(this).forPath(path) : Collections.<String>emptyList()); } } }
@Override public void process(WatchedEvent event) throws Exception { if (listener != null) { String path = event.getPath() == null ? "" : event.getPath(); listener.childChanged(path, // if path is null, curator using watcher will throw NullPointerException. // if client connect or disconnect to server, zookeeper will queue // watched event(Watcher.Event.EventType.None, .., path = null). StringUtils.isNotEmpty(path) ? client.getChildren().usingWatcher(this).forPath(path) : Collections.<String>emptyList()); } } }
if (StringUtils.isNotEmpty(webappPath)) { webappPath = webappPath.substring(1); if (!contextPath.startsWith(webappPath)) {
if (StringUtils.isNotEmpty(webappPath)) { webappPath = webappPath.substring(1); if (!contextPath.startsWith(webappPath)) {
if (StringUtils.isNotEmpty(webappPath)) { webappPath = webappPath.substring(1); if (!contextPath.startsWith(webappPath)) {
private String createProvideSideTraceId() { RpcContext rpcContext = RpcContext.getContext(); String isSample = rpcContext.getAttachment(DstConstants.DST_IS_SAMPLE); if(StringUtils.isNotEmpty(isSample)){ ContextHolder.setLocalSample(Boolean.valueOf(isSample)); } String traceId = rpcContext.getAttachment(DstConstants.DST_TRACE_ID); if (StringUtils.isBlank(traceId)) { ContextHolder.setTraceId(GUId.singleton().nextId()); } else { ContextHolder.setTraceId(traceId); } return ContextHolder.getTraceId(); }
@Override public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { RpcContext context = RpcContext.getContext(); context.setAttachments((Map<String, String>) getAttribute(dubboAttachmentsAttrName)); String generic = (String) getAttribute(Constants.GENERIC_KEY); if (StringUtils.isNotEmpty(generic)) { context.setAttachment(Constants.GENERIC_KEY, generic); } try { return super.invoke(targetObject); } finally { context.setAttachments(null); } } }
@Override public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { RpcContext context = RpcContext.getContext(); context.setAttachments((Map<String, String>) getAttribute(dubboAttachmentsAttrName)); String generic = (String) getAttribute(Constants.GENERIC_KEY); if (StringUtils.isNotEmpty(generic)) { context.setAttachment(Constants.GENERIC_KEY, generic); } try { return super.invoke(targetObject); } finally { context.setAttachments(null); } } }
private Span createProviderSideSpan() { RpcContext rpcContext = RpcContext.getContext(); String traceId = rpcContext.getAttachment(DstConstants.DST_TRACE_ID); String spanId = rpcContext.getAttachment(DstConstants.DST_SPAN_ID); String parentSpanId = rpcContext.getAttachment(DstConstants.DST_PARENT_SPAN_ID); if (StringUtils.isNotEmpty(traceId) && StringUtils.isNotEmpty(spanId)) {//只需要判断traceId和spanid即可 Span span = new Span(); span.setId(spanId); span.setParentId(parentSpanId); span.setTraceId(traceId); span.setServiceName(getServiceName()); span.setName(getMethodName()); ContextHolder.setSpan(span); } return ContextHolder.getSpan(); }
if (StringUtils.isNotEmpty(proxy)) { registryURL = registryURL.addParameter(Constants.PROXY_KEY, proxy);
if (StringUtils.isNotEmpty(proxy)) { registryURL = registryURL.addParameter(Constants.PROXY_KEY, proxy);