This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 e6b8bcd1e58 Add AgentBuilderFactory (#23394)
e6b8bcd1e58 is described below
commit e6b8bcd1e58448f893d373c4e451b5dfb008b62c
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 7 21:25:09 2023 +0800
Add AgentBuilderFactory (#23394)
---
.../agent/core/ShardingSphereAgent.java | 27 ++--------
.../agent/core/builder/AgentBuilderFactory.java | 60 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 22 deletions(-)
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
index f3cebf8adea..053e188e5fb 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/ShardingSphereAgent.java
@@ -19,20 +19,14 @@ package org.apache.shardingsphere.agent.core;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.agent.builder.AgentBuilder;
-import net.bytebuddy.dynamic.scaffold.TypeValidation;
-import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.builder.AgentBuilderFactory;
import org.apache.shardingsphere.agent.core.path.AgentPath;
-import
org.apache.shardingsphere.agent.core.plugin.yaml.plugin.loader.PluginConfigurationLoader;
-import org.apache.shardingsphere.agent.core.logging.LoggingListener;
import org.apache.shardingsphere.agent.core.plugin.PluginJar;
+import
org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfiguration;
import
org.apache.shardingsphere.agent.core.plugin.loader.AdvisorConfigurationLoader;
import org.apache.shardingsphere.agent.core.plugin.loader.AgentPluginLoader;
-import org.apache.shardingsphere.agent.core.builder.AgentJunction;
-import org.apache.shardingsphere.agent.core.builder.AgentTransformer;
-import
org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfiguration;
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import
org.apache.shardingsphere.agent.core.plugin.yaml.plugin.loader.PluginConfigurationLoader;
import java.io.File;
import java.io.IOException;
@@ -59,7 +53,7 @@ public final class ShardingSphereAgent {
Collection<PluginJar> pluginJars = AgentPluginLoader.load(rootPath);
boolean isEnhancedForProxy = isEnhancedForProxy();
Map<String, AdvisorConfiguration> advisorConfigs =
AdvisorConfigurationLoader.load(pluginJars, pluginConfigs.keySet(),
isEnhancedForProxy);
- setUpAgentBuilder(instrumentation, pluginConfigs, pluginJars,
advisorConfigs, isEnhancedForProxy);
+ AgentBuilderFactory.create(pluginConfigs, pluginJars, advisorConfigs,
isEnhancedForProxy).installOn(instrumentation);
}
private static boolean isEnhancedForProxy() {
@@ -70,15 +64,4 @@ public final class ShardingSphereAgent {
}
return true;
}
-
- private static void setUpAgentBuilder(final Instrumentation
instrumentation, final Map<String, PluginConfiguration> pluginConfigs,
- final Collection<PluginJar>
pluginJars, final Map<String, AdvisorConfiguration> advisorConfigs, final
boolean isEnhancedForProxy) {
- AgentBuilder agentBuilder = new AgentBuilder.Default().with(new
ByteBuddy().with(TypeValidation.ENABLED))
- .ignore(ElementMatchers.isSynthetic())
-
.or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent."));
- agentBuilder.type(new AgentJunction(advisorConfigs))
- .transform(new AgentTransformer(pluginConfigs, pluginJars,
advisorConfigs, isEnhancedForProxy))
- .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
- .with(new LoggingListener()).installOn(instrumentation);
- }
}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactory.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactory.java
new file mode 100644
index 00000000000..b8cef666a9b
--- /dev/null
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactory.java
@@ -0,0 +1,60 @@
+/*
+ * 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.builder;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.agent.builder.AgentBuilder;
+import net.bytebuddy.dynamic.scaffold.TypeValidation;
+import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.logging.LoggingListener;
+import org.apache.shardingsphere.agent.core.plugin.PluginJar;
+import
org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfiguration;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Agent builder factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class AgentBuilderFactory {
+
+ /**
+ * Create agent builder.
+ *
+ * @param pluginConfigs plugin configurations
+ * @param pluginJars plugin jars
+ * @param advisorConfigs advisor configurations
+ * @param isEnhancedForProxy is enhanced for proxy
+ * @return agent builder
+ */
+ public static AgentBuilder create(final Map<String, PluginConfiguration>
pluginConfigs,
+ final Collection<PluginJar> pluginJars,
final Map<String, AdvisorConfiguration> advisorConfigs, final boolean
isEnhancedForProxy) {
+ return new AgentBuilder.Default()
+ .with(new ByteBuddy().with(TypeValidation.ENABLED))
+ .ignore(ElementMatchers.isSynthetic())
+
.or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent."))
+ .type(new AgentJunction(advisorConfigs))
+ .transform(new AgentTransformer(pluginConfigs, pluginJars,
advisorConfigs, isEnhancedForProxy))
+ .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
+ .with(new LoggingListener());
+ }
+}