You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/12/01 12:27:56 UTC

[shardingsphere] branch master updated: Agent code optimize (#8448)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 56b160e  Agent  code optimize (#8448)
56b160e is described below

commit 56b160ea98896e6b5215ad5212b4eed33ff09e0f
Author: xiaoyu <54...@qq.com>
AuthorDate: Tue Dec 1 20:27:36 2020 +0800

    Agent  code optimize (#8448)
    
    * agent code optimize.
    
    * fix checkstyle
    
    * fix agent code style
    
    * fix checkstyle
    
    * agent code optimize.
---
 .../agent/bootstrap/ShardingSphereAgent.java       |  5 --
 .../agent/core/ShardingSphereTransformer.java      | 10 ++-
 ...java => PluginDefinitionNotFoundException.java} | 14 +++-
 ...viceDefine.java => PluginAdviceDefinition.java} | 74 +++++++++++++---------
 .../{PluginDefine.java => PluginDefinition.java}   | 12 ++--
 .../agent/core/plugin/PluginLoader.java            | 34 ++++------
 .../core/plugin/advice/MethodAroundAdvice.java     |  6 +-
 .../core/plugin/advice/MethodInvocationResult.java |  4 +-
 .../core/plugin/advice/OverrideArgsInvoker.java    |  4 +-
 .../plugin/advice/StaticMethodAroundAdvice.java    |  6 +-
 .../advice/StaticMethodAroundInterceptor.java      |  6 +-
 .../agent/core/plugin/advice/TargetObject.java     |  4 +-
 .../core/plugin/point/ClassStaticMethodPoint.java  |  2 +-
 .../agent/core/plugin/point/ConstructorPoint.java  |  2 +-
 .../core/plugin/point/InstanceMethodPoint.java     |  2 +-
 .../agent/core/utils/SingletonHolder.java          |  1 +
 .../shardingsphere-agent-tracer-sample/pom.xml     |  2 +-
 ...uginDefine.java => SamplePluginDefinition.java} |  8 +--
 18 files changed, 102 insertions(+), 94 deletions(-)

diff --git a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index 76cce23..90bfbc8 100644
--- a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++ b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -47,24 +47,19 @@ public class ShardingSphereAgent {
     public static void premain(final String agentArgs, final Instrumentation instrumentation) throws IOException {
         AgentConfiguration agentConfiguration = AgentConfigurationLoader.load();
         SingletonHolder.INSTANCE.put(agentConfiguration);
-
         ByteBuddy byteBuddy = new ByteBuddy().with(TypeValidation.ENABLED);
-    
         AgentBuilder builder = new AgentBuilder.Default()
             .with(byteBuddy)
             .ignore(ElementMatchers.isSynthetic())
             .or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent."))
             .or(ElementMatchers.not(ElementMatchers.nameStartsWith("org.apache.shardingsphere.")));
-    
         PluginLoader pluginLoader = PluginLoader.getInstance();
         pluginLoader.initialAllServices();
-    
         builder.type(pluginLoader.typeMatcher())
                .transform(new ShardingSphereTransformer(pluginLoader))
                .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                .with(new LoggingListener())
                .installOn(instrumentation);
-    
         pluginLoader.startAllServices();
         Runtime.getRuntime().addShutdownHook(new Thread(pluginLoader::shutdownAllServices));
     }
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereTransformer.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereTransformer.java
index 68e5e35..622a24c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereTransformer.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereTransformer.java
@@ -27,7 +27,7 @@ import net.bytebuddy.implementation.MethodDelegation;
 import net.bytebuddy.implementation.SuperMethodCall;
 import net.bytebuddy.jar.asm.Opcodes;
 import net.bytebuddy.utility.JavaModule;
-import org.apache.shardingsphere.agent.core.plugin.PluginAdviceDefine;
+import org.apache.shardingsphere.agent.core.plugin.PluginAdviceDefinition;
 import org.apache.shardingsphere.agent.core.plugin.PluginLoader;
 import org.apache.shardingsphere.agent.core.plugin.advice.ConstructorMethodInterceptor;
 import org.apache.shardingsphere.agent.core.plugin.advice.MethodAroundInterceptor;
@@ -57,7 +57,7 @@ public class ShardingSphereTransformer implements AgentBuilder.Transformer {
             DynamicType.Builder<?> newBuilder = builder.defineField("_SSExtraData_", Map.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_VOLATILE)
                     .implement(TargetObject.class)
                     .intercept(FieldAccessor.ofField("_SSExtraData_"));
-            final PluginAdviceDefine define = pluginLoader.loadPluginAdviceDefine(typeDescription);
+            final PluginAdviceDefinition define = pluginLoader.loadPluginAdviceDefine(typeDescription);
             for (ConstructorPoint point : define.getConstructorPoints()) {
                 try {
                     final ConstructorMethodInterceptor interceptor = new ConstructorMethodInterceptor(pluginLoader.getOrCreateInstance(point.getAdvice()));
@@ -72,8 +72,7 @@ public class ShardingSphereTransformer implements AgentBuilder.Transformer {
             for (ClassStaticMethodPoint point : define.getClassStaticMethodPoints()) {
                 try {
                     final StaticMethodAroundInterceptor interceptor = new StaticMethodAroundInterceptor(pluginLoader.getOrCreateInstance(point.getAdvice()));
-                    newBuilder = newBuilder.method(point.getMethodsMatcher())
-                            .intercept(MethodDelegation.withDefaultConfiguration().to(interceptor));
+                    newBuilder = newBuilder.method(point.getMethodsMatcher()).intercept(MethodDelegation.withDefaultConfiguration().to(interceptor));
                     // CHECKSTYLE:OFF
                 } catch (Exception e) {
                     // CHECKSTYLE:ON
@@ -83,8 +82,7 @@ public class ShardingSphereTransformer implements AgentBuilder.Transformer {
             for (InstanceMethodPoint point : define.getInstanceMethodPoints()) {
                 try {
                     final MethodAroundInterceptor interceptor = new MethodAroundInterceptor(pluginLoader.getOrCreateInstance(point.getAdvice()));
-                    newBuilder = newBuilder.method(point.getMethodMatcher())
-                            .intercept(MethodDelegation.withDefaultConfiguration().to(interceptor));
+                    newBuilder = newBuilder.method(point.getMethodMatcher()).intercept(MethodDelegation.withDefaultConfiguration().to(interceptor));
                     // CHECKSTYLE:OFF
                 } catch (Exception e) {
                     // CHECKSTYLE:ON
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AdviceNotFoundException.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java
similarity index 65%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AdviceNotFoundException.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java
index 1c59c54..8ce3639 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/AdviceNotFoundException.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/exception/PluginDefinitionNotFoundException.java
@@ -19,7 +19,17 @@
 package org.apache.shardingsphere.agent.core.exception;
 
 /**
- * Advice not found exception.
+ * Plugin definition not found exception.
  */
-public class AdviceNotFoundException extends RuntimeException {
+public class PluginDefinitionNotFoundException extends RuntimeException {
+    
+    /**
+     * Constructs an exception with formatted error message and arguments.
+     *
+     * @param errorMessage formatted error message
+     * @param args arguments of error message
+     */
+    public PluginDefinitionNotFoundException(final String errorMessage, final Object... args) {
+        super(String.format(errorMessage, args));
+    }
 }
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefinition.java
similarity index 83%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefine.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefinition.java
index 8715355..ebb73c5 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefine.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginAdviceDefinition.java
@@ -19,6 +19,7 @@
 package org.apache.shardingsphere.agent.core.plugin;
 
 import com.google.common.collect.Lists;
+import java.util.Collections;
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.matcher.ElementMatcher;
 import net.bytebuddy.matcher.ElementMatchers;
@@ -29,17 +30,17 @@ import org.apache.shardingsphere.agent.core.plugin.point.InstanceMethodPoint;
 import java.util.List;
 
 /**
- * Plugin advice define.
+ * Plugin advice definition.
  *
  * <code>
- * PluginAdviceDefine.intercept("Target.class")
+ * PluginAdviceDefinition.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 {
+public final class PluginAdviceDefinition {
     
     private final String classNameOfTarget;
     
@@ -49,10 +50,10 @@ public final class PluginAdviceDefine {
     
     private final List<ClassStaticMethodPoint> classStaticMethodPoints;
     
-    private PluginAdviceDefine(final String classNameOfTarget,
-                               final List<ConstructorPoint> constructorPoints,
-                               final List<InstanceMethodPoint> instanceMethodPoints,
-                               final List<ClassStaticMethodPoint> classStaticMethodPoints) {
+    private PluginAdviceDefinition(final String classNameOfTarget,
+                                   final List<ConstructorPoint> constructorPoints,
+                                   final List<InstanceMethodPoint> instanceMethodPoints,
+                                   final List<ClassStaticMethodPoint> classStaticMethodPoints) {
         this.classNameOfTarget = classNameOfTarget;
         this.constructorPoints = constructorPoints;
         this.instanceMethodPoints = instanceMethodPoints;
@@ -60,8 +61,18 @@ public final class PluginAdviceDefine {
     }
     
     /**
+     * Create default plugin advice definition.
+     *
+     * @return plugin advice definition
+     */
+    public static PluginAdviceDefinition createDefault() {
+        return new PluginAdviceDefinition("", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+    }
+    
+    /**
      * Get class name of target.
-     * @return class name.
+     *
+     * @return class name
      */
     public String getClassNameOfTarget() {
         return classNameOfTarget;
@@ -70,8 +81,8 @@ public final class PluginAdviceDefine {
     /**
      * Intercept target class.
      *
-     * @param classNameOfTarget a class name of wanted advice target.
-     * @return builder.
+     * @param classNameOfTarget a class name of wanted advice target
+     * @return builder
      */
     public static Builder intercept(final String classNameOfTarget) {
         return new Builder(classNameOfTarget);
@@ -80,7 +91,7 @@ public final class PluginAdviceDefine {
     /**
      * To get static method point configurations.
      *
-     * @return series of static method point configuration.
+     * @return series of static method point configuration
      */
     public List<ClassStaticMethodPoint> getClassStaticMethodPoints() {
         return classStaticMethodPoints;
@@ -89,7 +100,7 @@ public final class PluginAdviceDefine {
     /**
      * To get constructor point configurations.
      *
-     * @return series of constructor point configuration.
+     * @return series of constructor point configuration
      */
     public List<ConstructorPoint> getConstructorPoints() {
         return constructorPoints;
@@ -98,14 +109,14 @@ public final class PluginAdviceDefine {
     /**
      * To get instance point configurations.
      *
-     * @return series of instance method point configuration.
+     * @return series of instance method point configuration
      */
     public List<InstanceMethodPoint> getInstanceMethodPoints() {
         return instanceMethodPoints;
     }
     
     /**
-     * Plugin advice configuration builder.
+     * Plugin advice definition configuration builder.
      */
     public static final class Builder {
         
@@ -125,7 +136,7 @@ public final class PluginAdviceDefine {
          * Configure the intercepting point on constructor.
          *
          * @param matcher constraints
-         * @return configuration builder
+         * @return configuration point builder
          */
         public ConstructorPointBuilder onConstructor(final ElementMatcher<? super MethodDescription> matcher) {
             return new ConstructorPointBuilder(this, matcher);
@@ -135,7 +146,7 @@ public final class PluginAdviceDefine {
          * Configure the intercepting point around instance method.
          *
          * @param matcher constraints
-         * @return configuration builder
+         * @return instance method point builder
          */
         public InstanceMethodPointBuilder aroundInstanceMethod(final ElementMatcher<? super MethodDescription> matcher) {
             return new InstanceMethodPointBuilder(this, matcher);
@@ -145,25 +156,26 @@ public final class PluginAdviceDefine {
          * Configure the intercepting point around instance method.
          *
          * @param matcher constraints
-         * @return configuration builder
+         * @return static method point builder
          */
         public StaticMethodPointBuilder aroundClassStaticMethod(final ElementMatcher<? super MethodDescription> matcher) {
             return new StaticMethodPointBuilder(this, matcher);
         }
         
         /**
-         * Build configuration.
+         * Build plugin advice definition.
          *
-         * @return plugin advice definition.
+         * @return plugin advice definition
          */
-        public PluginAdviceDefine install() {
-            return new PluginAdviceDefine(classNameOfTarget, constructorPoints, instanceMethodPoints, classStaticMethodPoints);
+        public PluginAdviceDefinition install() {
+            return new PluginAdviceDefinition(classNameOfTarget, constructorPoints, instanceMethodPoints, classStaticMethodPoints);
         }
         
         /**
          * Instance method intercepting point configuration builder.
          */
         public static final class InstanceMethodPointBuilder {
+            
             private final Builder builder;
             
             private String classNameOfAdvice;
@@ -181,7 +193,7 @@ public final class PluginAdviceDefine {
              * Configure implementation for interceptor point.
              *
              * @param classNameOfAdvice the class name of advice
-             * @return instance method point builder.
+             * @return instance method point builder
              */
             public InstanceMethodPointBuilder implement(final String classNameOfAdvice) {
                 this.classNameOfAdvice = classNameOfAdvice;
@@ -191,8 +203,8 @@ public final class PluginAdviceDefine {
             /**
              * Configure whether or not override the origin method arguments.
              *
-             * @param overrideArgs whether to override origin method arguments.
-             * @return instance method point configurer.
+             * @param overrideArgs whether to override origin method arguments
+             * @return instance method point configurer
              */
             public InstanceMethodPointBuilder overrideArgs(final boolean overrideArgs) {
                 this.overrideArgs = overrideArgs;
@@ -202,7 +214,7 @@ public final class PluginAdviceDefine {
             /**
              * Build instance methods configuration.
              *
-             * @return plugin advice builder.
+             * @return plugin advice builder
              */
             public Builder build() {
                 builder.instanceMethodPoints.add(new InstanceMethodPoint(matcher, classNameOfAdvice, overrideArgs));
@@ -232,7 +244,7 @@ public final class PluginAdviceDefine {
              * Configure implementation for intercepting point.
              *
              * @param classNameOfAdvice the class name of advice
-             * @return static method point configurer.
+             * @return static method point configurer
              */
             public StaticMethodPointBuilder implement(final String classNameOfAdvice) {
                 this.classNameOfAdvice = classNameOfAdvice;
@@ -242,8 +254,8 @@ public final class PluginAdviceDefine {
             /**
              * Configure whether or not override the origin method arguments.
              *
-             * @param overrideArgs whether to override origin method arguments.
-             * @return static method point configurer.
+             * @param overrideArgs whether to override origin method arguments
+             * @return static method point configurer
              */
             public StaticMethodPointBuilder overrideArgs(final boolean overrideArgs) {
                 this.overrideArgs = overrideArgs;
@@ -253,7 +265,7 @@ public final class PluginAdviceDefine {
             /**
              * Build static methods configuration.
              *
-             * @return plugin advice builder.
+             * @return builder
              */
             public Builder build() {
                 builder.classStaticMethodPoints.add(new ClassStaticMethodPoint(matcher, classNameOfAdvice, overrideArgs));
@@ -281,7 +293,7 @@ public final class PluginAdviceDefine {
              * Configure implementation for intercepting point.
              *
              * @param classNameOfAdvice the class name of advice
-             * @return constructor point builder.
+             * @return constructor point builder
              */
             public ConstructorPointBuilder implement(final String classNameOfAdvice) {
                 this.classNameOfAdvice = classNameOfAdvice;
@@ -291,7 +303,7 @@ public final class PluginAdviceDefine {
             /**
              * Build constructor point configuration.
              *
-             * @return plugin advice builder.
+             * @return plugin advice builder
              */
             public Builder build() {
                 builder.constructorPoints.add(new ConstructorPoint(matcher, classNameOfAdvice));
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefinition.java
similarity index 82%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefine.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefinition.java
index b8b4379..f926296 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefine.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginDefinition.java
@@ -28,9 +28,9 @@ import java.util.stream.Collectors;
 /**
  * Plugin definition.
  */
-public abstract class PluginDefine {
+public abstract class PluginDefinition {
     
-    private final Map<String, PluginAdviceDefine.Builder> defineMap = Maps.newHashMap();
+    private final Map<String, PluginAdviceDefinition.Builder> defineMap = Maps.newHashMap();
     
     private final List<Class<? extends Service>> services = Lists.newArrayList();
     
@@ -39,11 +39,11 @@ public abstract class PluginDefine {
      */
     protected abstract void define();
     
-    protected PluginAdviceDefine.Builder intercept(final String classNameOfTarget) {
+    protected PluginAdviceDefinition.Builder intercept(final String classNameOfTarget) {
         if (defineMap.containsKey(classNameOfTarget)) {
             return defineMap.get(classNameOfTarget);
         }
-        PluginAdviceDefine.Builder builder = PluginAdviceDefine.intercept(classNameOfTarget);
+        PluginAdviceDefinition.Builder builder = PluginAdviceDefinition.intercept(classNameOfTarget);
         defineMap.put(classNameOfTarget, builder);
         return builder;
     }
@@ -62,9 +62,9 @@ public abstract class PluginDefine {
      *
      * @return configurations.
      */
-    public final List<PluginAdviceDefine> build() {
+    public final List<PluginAdviceDefinition> build() {
         define();
-        return defineMap.values().stream().map(PluginAdviceDefine.Builder::install).collect(Collectors.toList());
+        return defineMap.values().stream().map(PluginAdviceDefinition.Builder::install).collect(Collectors.toList());
     }
     
     /**
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
index 7e9f97a..b1fbd2e 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
@@ -27,9 +27,8 @@ import lombok.extern.slf4j.Slf4j;
 import net.bytebuddy.description.type.TypeDescription;
 import net.bytebuddy.matcher.ElementMatcher;
 import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.core.common.AgentPathLocator;
-import org.apache.shardingsphere.agent.core.exception.AdviceNotFoundException;
 
+import org.apache.shardingsphere.agent.core.common.AgentPathLocator;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.File;
@@ -59,7 +58,7 @@ public final class PluginLoader extends ClassLoader implements Closeable {
     
     private final List<Service> services = Lists.newArrayList();
     
-    private Map<String, PluginAdviceDefine> pluginDefineMap;
+    private Map<String, PluginAdviceDefinition> pluginDefineMap;
     
     private PluginLoader() {
         try {
@@ -106,9 +105,9 @@ public final class PluginLoader extends ClassLoader implements Closeable {
         return INSTANCE;
     }
     
-    private Map<String, PluginAdviceDefine> loadAllPlugins() throws IOException {
+    private Map<String, PluginAdviceDefinition> loadAllPlugins() throws IOException {
         File[] jarFiles = AgentPathLocator.getAgentPath().listFiles(file -> file.getName().endsWith(".jar"));
-        ImmutableMap.Builder<String, PluginAdviceDefine> pluginDefineMap = ImmutableMap.builder();
+        ImmutableMap.Builder<String, PluginAdviceDefinition> pluginDefineMap = ImmutableMap.builder();
         if (jarFiles == null) {
             return pluginDefineMap.build();
         }
@@ -125,16 +124,15 @@ public final class PluginLoader extends ClassLoader implements Closeable {
             }
             ByteStreams.copy(jar.getInputStream(jar.getEntry(classNameToPath(entrypoint))), outputStream);
             try {
-                PluginDefine config = (PluginDefine) defineClass(entrypoint, outputStream.toByteArray(), 0, outputStream.size())
-                        .newInstance();
-                config.getAllServices().forEach(klass -> {
+                PluginDefinition pluginDefinition = (PluginDefinition) defineClass(entrypoint, outputStream.toByteArray(), 0, outputStream.size()).newInstance();
+                pluginDefinition.getAllServices().forEach(klass -> {
                     try {
                         services.add(klass.newInstance());
                     } catch (InstantiationException | IllegalAccessException e) {
                         log.error("Failed to create service instance, {}.", klass.getTypeName(), e);
                     }
                 });
-                config.build().forEach(plugin -> pluginDefineMap.put(plugin.getClassNameOfTarget(), plugin));
+                pluginDefinition.build().forEach(plugin -> pluginDefineMap.put(plugin.getClassNameOfTarget(), plugin));
             } catch (InstantiationException | IllegalAccessException e) {
                 log.error("Failed to load plugin definition, {}.", entrypoint, e);
             }
@@ -159,7 +157,7 @@ public final class PluginLoader extends ClassLoader implements Closeable {
      * To detect the type whether or not exists.
      *
      * @param typeDescription TypeDescription
-     * @return contains when it is true.
+     * @return contains when it is true
      */
     public boolean containsType(final TypeDescription typeDescription) {
         return pluginDefineMap.containsKey(typeDescription.getTypeName());
@@ -169,25 +167,22 @@ public final class PluginLoader extends ClassLoader implements Closeable {
      * Load the definition configuration by TypeDescription.
      *
      * @param typeDescription TypeDescription
-     * @return the plugin definition configurations.
+     * @return the plugin definition configurations
      */
-    public PluginAdviceDefine loadPluginAdviceDefine(final TypeDescription typeDescription) {
-        if (pluginDefineMap.containsKey(typeDescription.getTypeName())) {
-            return pluginDefineMap.get(typeDescription.getTypeName());
-        }
-        throw new AdviceNotFoundException();
+    public PluginAdviceDefinition loadPluginAdviceDefine(final TypeDescription typeDescription) {
+        return pluginDefineMap.getOrDefault(typeDescription.getTypeName(), PluginAdviceDefinition.createDefault());
     }
     
     /**
      * To get or create instance of the advice class. Create new one and caching when it is not exist.
      *
      * @param classNameOfAdvice class name of advice
-     * @param <T> advice type.
+     * @param <T> advice type
      * @return instance of advice
      */
     @SneakyThrows({ClassNotFoundException.class, IllegalAccessException.class, InstantiationException.class})
+    @SuppressWarnings("unchecked")
     public <T> T getOrCreateInstance(final String classNameOfAdvice) {
-
         if (objectPool.containsKey(classNameOfAdvice)) {
             return (T) objectPool.get(classNameOfAdvice);
         }
@@ -195,8 +190,7 @@ public final class PluginLoader extends ClassLoader implements Closeable {
         try {
             Object inst = objectPool.get(classNameOfAdvice);
             if (Objects.isNull(inst)) {
-                inst = Class.forName(classNameOfAdvice, true, this)
-                        .newInstance();
+                inst = Class.forName(classNameOfAdvice, true, this).newInstance();
                 objectPool.put(classNameOfAdvice, inst);
             }
             return (T) inst;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java
index 4db2771..5af9c3a 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodAroundAdvice.java
@@ -31,12 +31,12 @@ public interface MethodAroundAdvice {
      * @param target the target object
      * @param method the target method
      * @param args all method arguments
-     * @param result wrapped class of result to detect whether or not to execute the origin method.
+     * @param result 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.
+     * 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
@@ -51,7 +51,7 @@ public interface MethodAroundAdvice {
      * @param target the target object
      * @param method the target method
      * @param args all method arguments
-     * @param throwable exception from target method.
+     * @param throwable exception from target method
      */
     void onThrowing(TargetObject target, Method method, Object[] args, Throwable throwable);
 }
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodInvocationResult.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodInvocationResult.java
index 9bcb77f..76265fb 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodInvocationResult.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/MethodInvocationResult.java
@@ -40,7 +40,7 @@ public class MethodInvocationResult {
     /**
      * Whether or not to discard origin method.
      *
-     * @return to replace the origin result if true.
+     * @return to replace the origin result if true
      */
     public boolean isRebased() {
         return isRebased;
@@ -49,7 +49,7 @@ public class MethodInvocationResult {
     /**
      * Result that is provided by per-method advice.
      *
-     * @return the advice result.
+     * @return the advice result
      */
     public Object getResult() {
         return result;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/OverrideArgsInvoker.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/OverrideArgsInvoker.java
index bce2036..164d86c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/OverrideArgsInvoker.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/OverrideArgsInvoker.java
@@ -26,8 +26,8 @@ public interface OverrideArgsInvoker {
     /**
      * Invocation origin method.
      *
-     * @param args the origin method arguments.
-     * @return the result of the origin method.
+     * @param args the origin method arguments
+     * @return the result of the origin method
      */
     Object call(Object[] args);
     
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java
index c853f71..05a1437 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundAdvice.java
@@ -31,7 +31,7 @@ public interface StaticMethodAroundAdvice {
      * @param klass the target class
      * @param method the target method
      * @param args all method arguments
-     * @param result wrapped class of result to detect whether or not to execute the origin method.
+     * @param result wrapped class of result to detect whether or not to execute the origin method
      */
     void beforeMethod(Class<?> klass, Method method, Object[] args, MethodInvocationResult result);
     
@@ -41,7 +41,7 @@ public interface StaticMethodAroundAdvice {
      * @param klass the target class
      * @param method the target method
      * @param args all method arguments
-     * @param result wrapped class of result to detect whether or not to execute the origin method.
+     * @param result wrapped class of result to detect whether or not to execute the origin method
      */
     void afterMethod(Class<?> klass, Method method, Object[] args, MethodInvocationResult result);
     
@@ -51,7 +51,7 @@ public interface StaticMethodAroundAdvice {
      * @param klass the target class
      * @param method the target method
      * @param args all method arguments
-     * @param throwable exception from target method.
+     * @param throwable exception from target method
      */
     void onThrowing(Class<?> klass, Method method, Object[] args, Throwable throwable);
 }
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundInterceptor.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundInterceptor.java
index 36f2daa..06e77c9 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundInterceptor.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/StaticMethodAroundInterceptor.java
@@ -46,12 +46,12 @@ public class StaticMethodAroundInterceptor {
      * @param klass the class of target
      * @param method the intercepted method
      * @param args the all arguments of method
-     * @param uber the origin method invocation
+     * @param callable the origin method invocation
      * @return the return value of target invocation
      */
     @RuntimeType
     @SneakyThrows
-    public Object intercept(final @Origin Class<?> klass, final @Origin Method method, final @AllArguments Object[] args, final @SuperCall Callable<?> uber) {
+    public Object intercept(final @Origin Class<?> klass, final @Origin Method method, final @AllArguments Object[] args, final @SuperCall Callable<?> callable) {
         final MethodInvocationResult result = new MethodInvocationResult();
         final Object ret;
         try {
@@ -65,7 +65,7 @@ public class StaticMethodAroundInterceptor {
             if (result.isRebased()) {
                 ret = result.getResult();
             } else {
-                ret = uber.call();
+                ret = callable.call();
             }
             // CHECKSTYLE:OFF
         } catch (Throwable throwable) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/TargetObject.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/TargetObject.java
index a378ad0..b0b31af 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/TargetObject.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/advice/TargetObject.java
@@ -26,14 +26,14 @@ public interface TargetObject {
     /**
      * Get the variable from context.
      *
-     * @return the attachment.
+     * @return the attachment
      */
     Object getAttachment();
     
     /**
      * Store a variable into context.
      *
-     * @param attachment what variable you want to store.
+     * @param attachment what variable you want to store
      */
     void setAttachment(Object attachment);
 }
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ClassStaticMethodPoint.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ClassStaticMethodPoint.java
index fc25bd5..66abb0d 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ClassStaticMethodPoint.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ClassStaticMethodPoint.java
@@ -50,7 +50,7 @@ public class ClassStaticMethodPoint {
     /**
      * To get the class name of advice.
      *
-     * @return the class name of advice.
+     * @return the class name of advice
      */
     public String getAdvice() {
         return advice;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ConstructorPoint.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ConstructorPoint.java
index 1ce19ad..9282312 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ConstructorPoint.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/ConstructorPoint.java
@@ -47,7 +47,7 @@ public class ConstructorPoint {
     /**
      * To get the class name of advice.
      *
-     * @return the class name of advice.
+     * @return the class name of advice
      */
     public String getAdvice() {
         return advice;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/InstanceMethodPoint.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/InstanceMethodPoint.java
index d1b3c35..e25502b 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/InstanceMethodPoint.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/point/InstanceMethodPoint.java
@@ -50,7 +50,7 @@ public class InstanceMethodPoint {
     /**
      * To get the class name of advice.
      *
-     * @return the class name of advice.
+     * @return the class name of advice
      */
     public String getAdvice() {
         return advice;
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/utils/SingletonHolder.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/utils/SingletonHolder.java
index 3d46153..50428a9 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/utils/SingletonHolder.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/utils/SingletonHolder.java
@@ -48,6 +48,7 @@ public enum SingletonHolder {
      * @param clazz clazz
      * @return object
      */
+    @SuppressWarnings("unchecked")
     public <T> T get(final Class<T> clazz) {
         return (T) SINGLES.get(clazz.getName());
     }
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
index efcc8b0..6a86735 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/pom.xml
@@ -31,7 +31,7 @@
     <artifactId>shardingsphere-agent-tracer-sample</artifactId>
 
     <properties>
-        <entrypoint.class>org.apache.shardingsphere.agent.plugin.trace.SamplePluginDefine</entrypoint.class>
+        <entrypoint.class>org.apache.shardingsphere.agent.plugin.trace.SamplePluginDefinition</entrypoint.class>
     </properties>
 
 </project>
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
similarity index 88%
rename from shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java
rename to shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
index 05fe07d..280344f 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefine.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracers/shardingsphere-agent-tracer-sample/src/main/java/org/apache/shardingsphere/agent/plugin/trace/SamplePluginDefinition.java
@@ -19,12 +19,12 @@
 package org.apache.shardingsphere.agent.plugin.trace;
 
 import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.core.plugin.PluginDefine;
+import org.apache.shardingsphere.agent.core.plugin.PluginDefinition;
 
 /**
- * Sample.
+ * Sample plugin definition.
  */
-public class SamplePluginDefine extends PluginDefine {
+public class SamplePluginDefinition extends PluginDefinition {
 
     @Override
     protected void define() {
@@ -32,8 +32,6 @@ public class SamplePluginDefine extends PluginDefine {
                 .aroundInstanceMethod(ElementMatchers.named("run"))
                 .implement("org.apache.shardingsphere.agent.plugin.trace.SampleAdvice")
                 .build();
-    
         registerService(SampleTracer.class);
     }
-
 }