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/04/26 03:23:01 UTC

[GitHub] wu-sheng commented on a change in pull request #1118: Spring aop patch

wu-sheng commented on a change in pull request #1118: Spring aop patch 
URL: https://github.com/apache/incubator-skywalking/pull/1118#discussion_r184261573
 
 

 ##########
 File path: apm-sniffer/apm-sdk-plugin/spring-plugins/core-patch/src/main/java/org/apache/skywalking/apm/plugin/spring/patch/AopExpressionMatchInterceptor.java
 ##########
 @@ -0,0 +1,64 @@
+/*
+ * 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.plugin.spring.patch;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * {@link AopExpressionMatchInterceptor} check if the method is match the enhanced method
+ * if yes,return false else return true;
+ *
+ * @author lican
+ */
+public class AopExpressionMatchInterceptor implements StaticMethodsAroundInterceptor {
+
+    private List<String> methodNames = new ArrayList<String>(2);
+
+    public AopExpressionMatchInterceptor() {
+        for (Method method : EnhancedInstance.class.getDeclaredMethods()) {
+            methodNames.add(method.getName());
+        }
+    }
+
+    @Override
+    public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, MethodInterceptResult result) {
+
+    }
+
+    @Override
+    public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret) {
+        Method targetAopMethod = (Method) allArguments[1];
+        Class<?> targetAopClass = (Class<?>) allArguments[2];
+        if (EnhancedInstance.class.isAssignableFrom(targetAopClass) && methodNames.contains(targetAopMethod.getName())) {
 
 Review comment:
   This is based on method name match, which is good enough in most cases. But have you tried to use method signature? Such as `Method#equal`?

----------------------------------------------------------------
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