You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/05/03 22:01:31 UTC

[GitHub] wu-sheng closed pull request #1152: Add RunnableWrapper

wu-sheng closed pull request #1152: Add RunnableWrapper
URL: https://github.com/apache/incubator-skywalking/pull/1152
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/RunnableWrapper.java b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/RunnableWrapper.java
new file mode 100644
index 000000000..60cd912dc
--- /dev/null
+++ b/apm-application-toolkit/apm-toolkit-trace/src/main/java/org/apache/skywalking/apm/toolkit/trace/RunnableWrapper.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.skywalking.apm.toolkit.trace;
+
+/**
+ * @author lican
+ */
+@TraceCrossThread
+public class RunnableWrapper implements Runnable {
+    final Runnable runnable;
+
+    public RunnableWrapper(Runnable runnable) {
+        this.runnable = runnable;
+    }
+
+    public static RunnableWrapper of(Runnable r) {
+        return new RunnableWrapper(r);
+    }
+
+
+    @Override
+    public void run() {
+        this.runnable.run();
+    }
+}
\ No newline at end of file
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml
deleted file mode 100644
index 91354b934..000000000
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/pom.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ Copyright 2017, OpenSkywalking Organization All rights reserved.
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~     http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License.
-  ~
-  ~ Project repository: https://github.com/OpenSkywalking/skywalking
-  -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <parent>
-        <artifactId>apm-sdk-plugin</artifactId>
-        <groupId>org.apache.skywalking</groupId>
-        <version>5.0.0-beta-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>apm-jdk-cross-thread-plugin</artifactId>
-    <name>jdk-cross-thread-plugin</name>
-
-    <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-deploy-plugin</artifactId>
-            </plugin>
-            <plugin>
-                <!-- 源码插件 -->
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-source-plugin</artifactId>
-                <!-- 发布时自动将源码同时发布的配置 -->
-                <executions>
-                    <execution>
-                        <id>attach-sources</id>
-                        <goals>
-                            <goal>jar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-</project>
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/resources/skywalking-plugin.def
deleted file mode 100644
index 9323cf3cf..000000000
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/resources/skywalking-plugin.def
+++ /dev/null
@@ -1,17 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-jdk-cross-thread=org.apache.skywalking.apm.plugin.jdk.thread.define.CallableOrRunnableInstrumentation
-
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index f31c86977..5f780d72e 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -56,7 +56,6 @@
         <module>kafka-v1-plugin</module>
         <module>servicecomb-plugin</module>
         <module>hystrix-1.x-plugin</module>
-        <module>jdk-cross-thread-plugin</module>
     </modules>
     <packaging>pom</packaging>
 
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/define/CallableOrRunnableInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableActivation.java
similarity index 83%
rename from apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/define/CallableOrRunnableInstrumentation.java
rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableActivation.java
index 4a4730e3d..e770298d3 100644
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/define/CallableOrRunnableInstrumentation.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableActivation.java
@@ -13,10 +13,9 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
-package org.apache.skywalking.apm.plugin.jdk.thread.define;
+package org.apache.skywalking.apm.toolkit.activation.trace;
 
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
@@ -25,22 +24,20 @@
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
 import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
 
-import static net.bytebuddy.matcher.ElementMatchers.any;
-import static net.bytebuddy.matcher.ElementMatchers.named;
-import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
+import static net.bytebuddy.matcher.ElementMatchers.*;
 import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch;
 
 /**
- * {@link CallableOrRunnableInstrumentation} presents that skywalking intercepts all Class with annotation
+ * {@link CallableOrRunnableActivation} presents that skywalking intercepts all Class with annotation
  * "org.skywalking.apm.toolkit.trace.TraceCrossThread" and method named "call" or "run".
  *
- * @author carlvine500
+ * @author carlvine500 lican
  */
-public class CallableOrRunnableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class CallableOrRunnableActivation extends ClassInstanceMethodsEnhancePluginDefine {
 
     public static final String ANNOTATION_NAME = "org.apache.skywalking.apm.toolkit.trace.TraceCrossThread";
-    private static final String INIT_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdk.thread.CallableOrRunnableConstructInterceptor";
-    private static final String CALL_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdk.thread.CallableOrRunnableInvokeInterceptor";
+    private static final String INIT_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.CallableOrRunnableConstructInterceptor";
+    private static final String CALL_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.toolkit.activation.trace.CallableOrRunnableInvokeInterceptor";
     private static final String CALL_METHOD_NAME = "call";
     private static final String RUN_METHOD_NAME = "run";
 
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableConstructInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableConstructInterceptor.java
similarity index 95%
rename from apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableConstructInterceptor.java
rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableConstructInterceptor.java
index 3c96f60f1..b0a18129c 100644
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableConstructInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableConstructInterceptor.java
@@ -13,9 +13,8 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-package org.apache.skywalking.apm.plugin.jdk.thread;
+package org.apache.skywalking.apm.toolkit.activation.trace;
 
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInvokeInterceptor.java
similarity index 97%
rename from apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java
rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInvokeInterceptor.java
index 8be7075c5..5fd19e497 100644
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInvokeInterceptor.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInvokeInterceptor.java
@@ -13,17 +13,17 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
-package org.apache.skywalking.apm.plugin.jdk.thread;
+package org.apache.skywalking.apm.toolkit.activation.trace;
 
-import java.lang.reflect.Method;
 import org.apache.skywalking.apm.agent.core.context.ContextManager;
 import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
 import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
 
+import java.lang.reflect.Method;
+
 /**
  * @author carlvine500
  */
diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def
index 4b6394da6..2d540d5b8 100644
--- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/resources/skywalking-plugin.def
@@ -17,3 +17,4 @@
 toolkit-trace=org.apache.skywalking.apm.toolkit.activation.trace.ActiveSpanTagActivation
 toolkit-trace=org.apache.skywalking.apm.toolkit.activation.trace.TraceAnnotationActivation
 toolkit-trace=org.apache.skywalking.apm.toolkit.activation.trace.TraceContextActivation
+toolkit-trace=org.apache.skywalking.apm.toolkit.activation.trace.CallableOrRunnableActivation
diff --git a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
similarity index 98%
rename from apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInterceptorTest.java
rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
index c76d65f5a..8c4cd87d8 100644
--- a/apm-sniffer/apm-sdk-plugin/jdk-cross-thread-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdk/thread/CallableOrRunnableInterceptorTest.java
+++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/trace/CallableOrRunnableInterceptorTest.java
@@ -13,22 +13,10 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
-package org.apache.skywalking.apm.plugin.jdk.thread;
+package org.apache.skywalking.apm.toolkit.activation.trace;
 
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.concurrent.Callable;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.modules.junit4.PowerMockRunnerDelegate;
 import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
 import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
 import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@@ -38,6 +26,18 @@
 import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
 import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
 import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.concurrent.Callable;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
diff --git a/docs/cn/Application-toolkit-trace-cross-thread-CN.md b/docs/cn/Application-toolkit-trace-cross-thread-CN.md
index 513c3d82b..4094ebe34 100644
--- a/docs/cn/Application-toolkit-trace-cross-thread-CN.md
+++ b/docs/cn/Application-toolkit-trace-cross-thread-CN.md
@@ -30,6 +30,15 @@
         }
     }));
 ```
+或者
+```java
+    ExecutorService executorService = Executors.newFixedThreadPool(1);
+    executorService.execute(RunnableWrapper.of(new Runnable() {
+        @Override public void run() {
+            //your code
+        }
+    }));
+```
 _示例代码,仅供参考_
 
 
diff --git a/docs/en/Application-toolkit-trace-cross-thread.md b/docs/en/Application-toolkit-trace-cross-thread.md
index 308cb83c9..2b00c4420 100644
--- a/docs/en/Application-toolkit-trace-cross-thread.md
+++ b/docs/en/Application-toolkit-trace-cross-thread.md
@@ -30,6 +30,16 @@
         }
     }));
 ```
+or 
+```java
+    ExecutorService executorService = Executors.newFixedThreadPool(1);
+    executorService.execute(RunnableWrapper.of(new Runnable() {
+        @Override public void run() {
+            //your code
+        }
+    }));
+```
+
 _Sample codes only_
 
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services