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 2020/03/05 11:48:54 UTC

[GitHub] [skywalking] huangyoje commented on a change in pull request #4441: Add finagle plugin (#4433)

huangyoje commented on a change in pull request #4441: Add finagle plugin (#4433)
URL: https://github.com/apache/skywalking/pull/4441#discussion_r388244559
 
 

 ##########
 File path: apm-sniffer/apm-sdk-plugin/finagle-6.25.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/finagle/AbstractInterceptor.java
 ##########
 @@ -0,0 +1,76 @@
+/*
+ * 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.finagle;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
+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;
+
+abstract class AbstractInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor {
+    @Override
+    public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
+        if (CompatibilityChecker.isCompatible()) {
+            onConstructImpl(objInst, allArguments);
+        }
+    }
+
+    @Override
+    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
+        if (CompatibilityChecker.isCompatible()) {
+            beforeMethodImpl(objInst, method, allArguments, argumentsTypes, result);
+        }
+    }
+
+    @Override
+    public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
+        if (CompatibilityChecker.isCompatible()) {
+            return afterMethodImpl(objInst, method, allArguments, argumentsTypes, ret);
+        }
+        return ret;
+    }
+
+    @Override
+    public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
+        if (CompatibilityChecker.isCompatible()) {
+            handleMethodExceptionImpl(objInst, method, allArguments, argumentsTypes, t);
+        }
+    }
+
+    protected void onConstructImpl(EnhancedInstance objInst, Object[] allArguments) {
+
+    }
+
+    protected void beforeMethodImpl(EnhancedInstance objInst, Method method, Object[] allArguments,
+                                    Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
+
+    }
+
+    protected Object afterMethodImpl(EnhancedInstance objInst, Method method, Object[] allArguments,
+                                     Class<?>[] argumentsTypes, Object ret) throws Throwable {
+        return ret;
+    }
+
+    protected void handleMethodExceptionImpl(EnhancedInstance objInst, Method method, Object[] allArguments,
+                                             Class<?>[] argumentsTypes, Throwable t) {
+
+    }
 
 Review comment:
   I will make these methods abstract.  
   
   Because `ClientDestTracingFilterInterceptor` need to implement both `onConstructImpl ` and `beforeMethodImpl ` methods and java did not support mutiple inheritance,   so they can not be split into two class. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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