yu199195 commented on a change in pull request #8307:
URL: https://github.com/apache/shardingsphere/pull/8307#discussion_r528695254



##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.shardingsphere.agent.core.plugin;
+
+import lombok.SneakyThrows;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Plugins loader.
+ * TODO not-implemented yet
+ */
+public class PluginLoader extends ClassLoader {
+
+    private final ConcurrentHashMap<String, Object> objectPool = new 
ConcurrentHashMap<>();
+
+    private final ReentrantLock lock = new ReentrantLock();
+
+    /**
+     * To find all intercepting target classes then to build TypeMatcher.
+     *
+     * @return TypeMatcher
+     */
+    public ElementMatcher<? super TypeDescription> typeMatcher() {
+        return null;
+    }
+
+    /**
+     * To detect the type whether or not exists.
+     *
+     * @param typeDescription TypeDescription
+     * @return contains when it is true.
+     */
+    public boolean containsType(final TypeDescription typeDescription) {
+        return false;
+    }
+
+    /**
+     * Load the definition configuration by TypeDescription.

Review comment:
        type description.

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefine.java
##########
@@ -0,0 +1,300 @@
+/*
+ * 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.shardingsphere.agent.core.plugin;
+
+import com.google.common.collect.Lists;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import net.bytebuddy.matcher.ElementMatchers;
+import 
org.apache.shardingsphere.agent.core.plugin.point.ClassStaticMethodPoint;
+import org.apache.shardingsphere.agent.core.plugin.point.ConstructorPoint;
+import org.apache.shardingsphere.agent.core.plugin.point.InstanceMethodPoint;
+
+import java.util.List;
+
+/**
+ * The advice of plugin configurer.
+ *
+ * <code>
+ * PluginAdviceDefine.intercept("Target.class")
+ * .onConstructor(ElementMatchers.any()).implement("Advice.class").build()
+ * .method(ElementMatchers.named("greet").implement("Advice.class").build()
+ * 
.staticMethod(ElementMatchers.named("of").implement("OfAdvice.class").build()
+ * .install();
+ * </code>
+ */
+public final class PluginAdviceDefine {
+
+    private final List<ConstructorPoint> constructorPoints;
+
+    private final List<InstanceMethodPoint> instanceMethodPoints;
+
+    private final List<ClassStaticMethodPoint> classStaticMethodPoints;
+
+    private PluginAdviceDefine(final List<ConstructorPoint> constructorPoints,
+                               final List<InstanceMethodPoint> 
instanceMethodPoints,
+                               final List<ClassStaticMethodPoint> 
classStaticMethodPoints) {
+        this.constructorPoints = constructorPoints;
+        this.instanceMethodPoints = instanceMethodPoints;
+        this.classStaticMethodPoints = classStaticMethodPoints;
+    }
+
+    /**
+     * Intercept target class.
+     *
+     * @param classNameOfTarget a class name of wanted advice target.
+     * @return Configurer.
+     */
+    public static Builder intercept(final String classNameOfTarget) {
+        return new Builder(classNameOfTarget);
+    }
+
+    /**
+     * To get static method point configurations.
+     *
+     * @return a series of static method point configuration.
+     */
+    public List<ClassStaticMethodPoint> getClassStaticMethodPoints() {
+        return classStaticMethodPoints;
+    }
+
+    /**
+     * To get constructor point configurations.
+     *
+     * @return a series of constructor point configuration.
+     */
+    public List<ConstructorPoint> getConstructorPoints() {
+        return constructorPoints;
+    }
+
+    /**
+     * To get instance point configurations.
+     *
+     * @return a series of instance method point configuration.
+     */
+    public List<InstanceMethodPoint> getInstanceMethodPoints() {
+        return instanceMethodPoints;
+    }
+
+    /**
+     * Plugin advice configuration builder.
+     */
+    public static final class Builder {
+        private final List<ConstructorPoint> constructorPoints = 
Lists.newArrayList();
+
+        private final List<InstanceMethodPoint> instanceMethodPoints = 
Lists.newArrayList();
+
+        private final List<ClassStaticMethodPoint> classStaticMethodPoints = 
Lists.newArrayList();
+
+        private final String classNameOfTarget;
+
+        private Builder(final String classNameOfTarget) {
+            this.classNameOfTarget = classNameOfTarget;
+        }
+
+        /**
+         * Intercept the new target.
+         *
+         * @param classNameOfTarget the class name of target.
+         * @return Configuration builder.
+         */
+        public Builder intercept(final String classNameOfTarget) {
+            // TODO not-implemented yet
+            return this;
+        }
+
+        /**
+         * to configure the intercepting point on constructor.
+         *
+         * @param matcher constraints
+         * @return Configuration builder
+         */
+        public ConstructorPointBuilder onConstructor(final ElementMatcher<? 
super MethodDescription> matcher) {
+            return new ConstructorPointBuilder(this, matcher);
+        }
+
+        /**
+         * to configure the intercepting point around instance method.
+         *
+         * @param matcher constraints
+         * @return Configuration builder
+         */
+        public InstanceMethodPointBuilder method(final ElementMatcher<? super 
MethodDescription> matcher) {
+            return new InstanceMethodPointBuilder(this, matcher);
+        }
+
+        /**
+         * to configure the intercepting point around instance method.
+         *
+         * @param matcher constraints
+         * @return Configuration builder
+         */
+        public StaticMethodPointBuilder staticMethod(final ElementMatcher<? 
super MethodDescription> matcher) {
+            return new StaticMethodPointBuilder(this, matcher);
+        }
+
+
+        /**
+         * build configuration.
+         *
+         * @return Plugin advice definition.
+         */
+        public PluginAdviceDefine install() {
+            return new PluginAdviceDefine(constructorPoints, 
instanceMethodPoints, classStaticMethodPoints);
+        }
+
+        /**
+         * Instance method intercepting point configuration builder.
+         */
+        public static final class InstanceMethodPointBuilder {
+            private final Builder builder;
+
+            private String classNameOfAdvice;
+
+            private boolean overrideArgs;
+
+            private ElementMatcher<? super MethodDescription> matcher;
+
+            private InstanceMethodPointBuilder(final Builder builder, final 
ElementMatcher<? super MethodDescription> matcher) {
+                this.builder = builder;
+                this.matcher = matcher;
+            }
+
+            /**
+             * to configure implementation for intercepting point.
+             *
+             * @param classNameOfAdvice the class name of advice
+             * @return Instance method point configurer.
+             */
+            public InstanceMethodPointBuilder implement(final String 
classNameOfAdvice) {
+                this.classNameOfAdvice = classNameOfAdvice;
+                return this;
+            }
+
+            /**
+             * to configure whether or not override the origin method 
arguments.
+             *
+             * @param overrideArgs whether to override origin method arguments.
+             * @return Instance method point configurer.
+             */
+            public InstanceMethodPointBuilder overrideArgs(final boolean 
overrideArgs) {
+                this.overrideArgs = overrideArgs;
+                return this;
+            }
+
+            /**
+             * to build instance methods configuration.
+             *
+             * @return Plugin advice builder.
+             */
+            public Builder build() {
+                builder.instanceMethodPoints.add(new 
InstanceMethodPoint(matcher, classNameOfAdvice, overrideArgs));
+                return builder;
+            }
+        }
+
+        /**
+         * Static method intercepting point configuration builder.
+         */
+        public static final class StaticMethodPointBuilder {
+            private final Builder builder;
+
+            private String classNameOfAdvice;
+
+            private boolean overrideArgs;
+
+            private ElementMatcher<? super MethodDescription> matcher;
+
+            private StaticMethodPointBuilder(final Builder builder, final 
ElementMatcher<? super MethodDescription> matcher) {
+                this.builder = builder;
+                this.matcher = ElementMatchers.isStatic().and(matcher);
+            }
+
+            /**
+             * to configure implementation for intercepting point.
+             *
+             * @param classNameOfAdvice the class name of advice
+             * @return Static method point configurer.

Review comment:
       Static method point builder

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.advice;
+
+import java.lang.reflect.Method;
+
+/**
+ * Weaving the advice around the static methods of target class.
+ */
+public interface StaticMethodAroundAdvice {
+
+    /**
+     * Intercept the target method and weave the method before origin method. 
It will invoke before the origin calling.
+     *
+     * @param klass the target class
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void beforeMethod(Class<?> klass, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Intercept the target method and weave the method after origin method. 
It will invoke after the origin calling.
+     *
+     * @param klass the target class
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void afterMethod(Class<?> klass, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Weaving the method after origin method throwing.
+     *
+     * @param klass the target class
+     * @param method the target method
+     * @param args the all method arguments
+     * @param throwable an exception from target method.

Review comment:
       remove an

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/OverrideArgsInvoker.java
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.advice;
+
+/**
+ * Super(origin) method invoker for ByteBuddy only.
+ */
+public interface OverrideArgsInvoker {
+
+    /**
+     * invocation origin method.

Review comment:
       invocation  may be Invocation 

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.advice;
+
+import java.lang.reflect.Method;
+
+/**
+ * Weaving the advice around the static methods of target class.
+ */
+public interface StaticMethodAroundAdvice {
+
+    /**
+     * Intercept the target method and weave the method before origin method. 
It will invoke before the origin calling.
+     *
+     * @param klass the target class
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void beforeMethod(Class<?> klass, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Intercept the target method and weave the method after origin method. 
It will invoke after the origin calling.
+     *
+     * @param klass the target class
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.

Review comment:
       remove A

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.advice;
+
+import java.lang.reflect.Method;
+
+/**
+ * Weaving the advice around the target method.
+ */
+public interface MethodAroundAdvice {
+
+    /**
+     * Intercept the target method and weave the method before origin method. 
It will invoke before the origin calling.
+     *
+     * @param target the target object
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void beforeMethod(TargetObject target, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Intercept the target method and weave the method after origin method.  
It will invoke after the origin calling.
+     *
+     * @param target the target object
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void afterMethod(TargetObject target, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Weaving the method after origin method throwing.
+     *
+     * @param target the target object
+     * @param method the target method
+     * @param args the all method arguments
+     * @param throwable an exception from target method.

Review comment:
       remove an 

##########
File path: 
shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.advice;
+
+import java.lang.reflect.Method;
+
+/**
+ * Weaving the advice around the target method.
+ */
+public interface MethodAroundAdvice {
+
+    /**
+     * Intercept the target method and weave the method before origin method. 
It will invoke before the origin calling.
+     *
+     * @param target the target object
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.
+     */
+    void beforeMethod(TargetObject target, Method method, Object[] args, 
MethodInvocationResult result);
+
+    /**
+     * Intercept the target method and weave the method after origin method.  
It will invoke after the origin calling.
+     *
+     * @param target the target object
+     * @param method the target method
+     * @param args the all method arguments
+     * @param result A wrapped class of result to detect whether or not to 
execute the origin method.

Review comment:
       remove A worlds




----------------------------------------------------------------
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:
[email protected]


Reply via email to