You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/19 10:54:36 UTC
[shardingsphere] branch master updated: Add YamlPointcutParameterConfiguration (#22974)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 4459e9ff27b Add YamlPointcutParameterConfiguration (#22974)
4459e9ff27b is described below
commit 4459e9ff27b62e945d248f9f85cec9ba9dcc8132
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Dec 19 18:54:26 2022 +0800
Add YamlPointcutParameterConfiguration (#22974)
---
.../yaml/entity/YamlPointcutConfiguration.java | 5 ++++
...ava => YamlPointcutParameterConfiguration.java} | 6 ++--
.../swapper/YamlAdvisorConfigurationSwapper.java | 34 +++++++++++++++++-----
3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java
index 4373da6d8d4..bc08ffd2d42 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java
@@ -20,6 +20,9 @@ package org.apache.shardingsphere.agent.core.plugin.yaml.entity;
import lombok.Getter;
import lombok.Setter;
+import java.util.Collection;
+import java.util.LinkedList;
+
/**
* YAML pointcut configuration.
*/
@@ -30,4 +33,6 @@ public final class YamlPointcutConfiguration {
private String name;
private String type;
+
+ private Collection<YamlPointcutParameterConfiguration> params = new LinkedList<>();
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
similarity index 88%
copy from agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java
copy to agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
index 4373da6d8d4..39f128daa93 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/entity/YamlPointcutParameterConfiguration.java
@@ -21,13 +21,13 @@ import lombok.Getter;
import lombok.Setter;
/**
- * YAML pointcut configuration.
+ * YAML pointcut parameter configuration.
*/
@Getter
@Setter
-public final class YamlPointcutConfiguration {
+public final class YamlPointcutParameterConfiguration {
- private String name;
+ private int index;
private String type;
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
index 63dbae5110c..df1ddd41e06 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/yaml/swapper/YamlAdvisorConfigurationSwapper.java
@@ -17,12 +17,17 @@
package org.apache.shardingsphere.agent.core.plugin.yaml.swapper;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.matcher.ElementMatcher.Junction;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
import org.apache.shardingsphere.agent.config.advisor.MethodAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfigurationRegistryFactory;
import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlPointcutConfiguration;
+import org.apache.shardingsphere.agent.core.plugin.yaml.entity.YamlPointcutParameterConfiguration;
+
+import java.util.Optional;
/**
* YAML advisor configuration swapper.
@@ -38,14 +43,29 @@ public final class YamlAdvisorConfigurationSwapper {
*/
public AdvisorConfiguration swapToObject(final YamlAdvisorConfiguration yamlAdvisorConfig, final String type) {
AdvisorConfiguration result = AdvisorConfigurationRegistryFactory.getRegistry(type).getAdvisorConfiguration(yamlAdvisorConfig.getTarget());
- String[] constructPointcuts = yamlAdvisorConfig.getPointcuts().stream().filter(each -> "construct".equals(each.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
- if (constructPointcuts.length > 0) {
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor(), yamlAdvisorConfig.getAdvice()));
- }
- String[] methodPointcuts = yamlAdvisorConfig.getPointcuts().stream().filter(each -> "method".equals(each.getType())).map(YamlPointcutConfiguration::getName).toArray(String[]::new);
- if (methodPointcuts.length > 0) {
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.namedOneOf(methodPointcuts), yamlAdvisorConfig.getAdvice()));
+ for (YamlPointcutConfiguration each : yamlAdvisorConfig.getPointcuts()) {
+ Optional<Junction<? super MethodDescription>> pointcut = createPointcut(each);
+ if (pointcut.isPresent()) {
+ appendParameters(each, pointcut.get());
+ result.getAdvisors().add(new MethodAdvisorConfiguration(pointcut.get(), yamlAdvisorConfig.getAdvice()));
+ }
}
return result;
}
+
+ private Optional<Junction<? super MethodDescription>> createPointcut(final YamlPointcutConfiguration yamlPointcutConfig) {
+ if ("constructor".equals(yamlPointcutConfig.getType())) {
+ return Optional.of(ElementMatchers.isConstructor());
+ }
+ if ("method".equals(yamlPointcutConfig.getType())) {
+ return Optional.of(ElementMatchers.namedOneOf(yamlPointcutConfig.getName()));
+ }
+ return Optional.empty();
+ }
+
+ private void appendParameters(final YamlPointcutConfiguration yamlPointcutConfig, final Junction<? super MethodDescription> pointcut) {
+ for (YamlPointcutParameterConfiguration each : yamlPointcutConfig.getParams()) {
+ pointcut.and(ElementMatchers.takesArgument(each.getIndex(), ElementMatchers.named(each.getType())));
+ }
+ }
}