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 7c687fd16c6 Rename AgentPointcut (#22803)
7c687fd16c6 is described below
commit 7c687fd16c61714380fb0cee0c349cd843f479d3
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 11 18:26:29 2022 +0800
Rename AgentPointcut (#22803)
---
.../AgentPointcut.java} | 24 +++---
.../ConstructorPointcut.java} | 8 +-
.../InstanceMethodPointcut.java} | 8 +-
.../PluginPointcuts.java} | 40 ++++-----
.../StaticMethodPointcut.java} | 8 +-
.../agent/spi/PluginDefinitionService.java | 4 +-
.../transformer/ShardingSphereTransformer.java | 94 +++++++++++-----------
.../AbstractPluginDefinitionService.java | 6 +-
.../core/definition/InterceptorPointRegistry.java | 8 +-
.../agent/core/plugin/AgentPluginLoader.java | 24 +++---
.../agent/core/plugin/PluginLoader.java | 4 +-
.../transformer/ShardingSphereTransformerTest.java | 8 +-
.../core/plugin/loader/AgentPluginLoaderTest.java | 4 +-
.../PrometheusPluginDefinitionService.java | 2 +-
14 files changed, 120 insertions(+), 122 deletions(-)
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/AgentPointcut.java
similarity index 72%
copy from
agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
copy to
agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/AgentPointcut.java
index 363822dedb6..e51f117774a 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/AgentPointcut.java
@@ -15,21 +15,27 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.api.interceptor;
+package org.apache.shardingsphere.agent.api.pointcut;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
/**
- * constructor interceptor point.
+ * Agent pointcut.
*/
-@RequiredArgsConstructor
-@Getter
-public final class ConstructorInterceptorPoint {
+public interface AgentPointcut {
- private final ElementMatcher<? super MethodDescription> matcher;
+ /**
+ * Get matcher.
+ *
+ * @return matcher
+ */
+ ElementMatcher<? super MethodDescription> getMatcher();
- private final String advice;
+ /**
+ * Get advice class name.
+ *
+ * @return advice class name
+ */
+ String getAdviceClassName();
}
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/ConstructorPointcut.java
similarity index 85%
rename from
agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
rename to
agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/ConstructorPointcut.java
index 363822dedb6..7d968e6809c 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/ConstructorInterceptorPoint.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/ConstructorPointcut.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.api.interceptor;
+package org.apache.shardingsphere.agent.api.pointcut;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -23,13 +23,13 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
/**
- * constructor interceptor point.
+ * Constructor Pointcut.
*/
@RequiredArgsConstructor
@Getter
-public final class ConstructorInterceptorPoint {
+public final class ConstructorPointcut implements AgentPointcut {
private final ElementMatcher<? super MethodDescription> matcher;
- private final String advice;
+ private final String adviceClassName;
}
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/StaticMethodInterceptorPoint.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/InstanceMethodPointcut.java
similarity index 85%
rename from
agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/StaticMethodInterceptorPoint.java
rename to
agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/InstanceMethodPointcut.java
index 692c0a36f81..731b481189c 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/StaticMethodInterceptorPoint.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/InstanceMethodPointcut.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.api.interceptor;
+package org.apache.shardingsphere.agent.api.pointcut;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -23,15 +23,15 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
/**
- * Static method interceptor point.
+ * Instance method pointcut.
*/
@RequiredArgsConstructor
@Getter
-public final class StaticMethodInterceptorPoint {
+public final class InstanceMethodPointcut implements AgentPointcut {
private final ElementMatcher<? super MethodDescription> matcher;
- private final String advice;
+ private final String adviceClassName;
private final boolean overrideArgs;
}
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/PluginInterceptorPoint.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/PluginPointcuts.java
similarity index 81%
rename from
agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/PluginInterceptorPoint.java
rename to
agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/PluginPointcuts.java
index 9b00b71e49c..aee83e4723c 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/PluginInterceptorPoint.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/PluginPointcuts.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.api.interceptor;
+package org.apache.shardingsphere.agent.api.pointcut;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -28,35 +28,27 @@ import java.util.Collections;
import java.util.List;
/**
- * Plugin interceptor point.
- *
- * {@code
- * PluginInterceptorPoint.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();
- * }
+ * Plugin pointcuts.
*/
@RequiredArgsConstructor
@Getter
-public final class PluginInterceptorPoint {
+public final class PluginPointcuts {
private final String targetClassName;
- private final List<ConstructorInterceptorPoint>
constructorInterceptorPoints;
+ private final List<ConstructorPointcut> constructorPointcuts;
- private final List<InstanceMethodInterceptorPoint>
instanceMethodInterceptorPoints;
+ private final List<InstanceMethodPointcut> instanceMethodPointcuts;
- private final List<StaticMethodInterceptorPoint>
staticMethodInterceptorPoints;
+ private final List<StaticMethodPointcut> staticMethodPointcuts;
/**
* Create plugin interceptor point.
*
* @return plugin interceptor point
*/
- public static PluginInterceptorPoint createDefault() {
- return new PluginInterceptorPoint("", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
+ public static PluginPointcuts createDefault() {
+ return new PluginPointcuts("", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
}
/**
@@ -77,11 +69,11 @@ public final class PluginInterceptorPoint {
private final String targetClassName;
- private final List<ConstructorInterceptorPoint>
constructorInterceptorPoints = new ArrayList<>();
+ private final List<ConstructorPointcut> constructorPointcuts = new
ArrayList<>();
- private final List<InstanceMethodInterceptorPoint>
instanceMethodInterceptorPoints = new ArrayList<>();
+ private final List<InstanceMethodPointcut> instanceMethodPointcuts =
new ArrayList<>();
- private final List<StaticMethodInterceptorPoint>
staticMethodInterceptorPoints = new ArrayList<>();
+ private final List<StaticMethodPointcut> staticMethodPointcuts = new
ArrayList<>();
/**
* Configure the intercepting point on constructor.
@@ -118,8 +110,8 @@ public final class PluginInterceptorPoint {
*
* @return plugin advice definition
*/
- public PluginInterceptorPoint install() {
- return new PluginInterceptorPoint(targetClassName,
constructorInterceptorPoints, instanceMethodInterceptorPoints,
staticMethodInterceptorPoints);
+ public PluginPointcuts install() {
+ return new PluginPointcuts(targetClassName, constructorPointcuts,
instanceMethodPointcuts, staticMethodPointcuts);
}
/**
@@ -164,7 +156,7 @@ public final class PluginInterceptorPoint {
* @return plugin advice builder
*/
public Builder build() {
- builder.instanceMethodInterceptorPoints.add(new
InstanceMethodInterceptorPoint(matcher, adviceClassName, overrideArgs));
+ builder.instanceMethodPointcuts.add(new
InstanceMethodPointcut(matcher, adviceClassName, overrideArgs));
return builder;
}
}
@@ -215,7 +207,7 @@ public final class PluginInterceptorPoint {
* @return builder
*/
public Builder build() {
- builder.staticMethodInterceptorPoints.add(new
StaticMethodInterceptorPoint(matcher, adviceClassName, overrideArgs));
+ builder.staticMethodPointcuts.add(new
StaticMethodPointcut(matcher, adviceClassName, overrideArgs));
return builder;
}
}
@@ -253,7 +245,7 @@ public final class PluginInterceptorPoint {
* @return plugin advice builder
*/
public Builder build() {
- builder.constructorInterceptorPoints.add(new
ConstructorInterceptorPoint(matcher, adviceClassName));
+ builder.constructorPointcuts.add(new
ConstructorPointcut(matcher, adviceClassName));
return builder;
}
}
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/InstanceMethodInterceptorPoint.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/StaticMethodPointcut.java
similarity index 85%
rename from
agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/InstanceMethodInterceptorPoint.java
rename to
agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/StaticMethodPointcut.java
index 7cf51055531..140a8853197 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/api/interceptor/InstanceMethodInterceptorPoint.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/api/pointcut/StaticMethodPointcut.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.api.interceptor;
+package org.apache.shardingsphere.agent.api.pointcut;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -23,15 +23,15 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
/**
- * Instance method interceptor point.
+ * Static method pointcut.
*/
@RequiredArgsConstructor
@Getter
-public final class InstanceMethodInterceptorPoint {
+public final class StaticMethodPointcut implements AgentPointcut {
private final ElementMatcher<? super MethodDescription> matcher;
- private final String advice;
+ private final String adviceClassName;
private final boolean overrideArgs;
}
diff --git
a/agent/api/src/main/java/org/apache/shardingsphere/agent/spi/PluginDefinitionService.java
b/agent/api/src/main/java/org/apache/shardingsphere/agent/spi/PluginDefinitionService.java
index 4c2bded28e7..d1d9751cee6 100644
---
a/agent/api/src/main/java/org/apache/shardingsphere/agent/spi/PluginDefinitionService.java
+++
b/agent/api/src/main/java/org/apache/shardingsphere/agent/spi/PluginDefinitionService.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.agent.spi;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
import java.util.Collection;
@@ -32,5 +32,5 @@ public interface PluginDefinitionService extends AgentSPI {
* @param isEnhancedForProxy is enhanced for proxy
* @return plugin interceptor points
*/
- Collection<PluginInterceptorPoint> install(boolean isEnhancedForProxy);
+ Collection<PluginPointcuts> install(boolean isEnhancedForProxy);
}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
index 65d42a61af2..88c938b3398 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformer.java
@@ -35,10 +35,10 @@ import
org.apache.shardingsphere.agent.api.advice.StaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.api.advice.ConstructorAdvice;
import org.apache.shardingsphere.agent.api.advice.InstanceMethodAroundAdvice;
import org.apache.shardingsphere.agent.api.advice.OverrideArgsInvoker;
-import
org.apache.shardingsphere.agent.api.interceptor.StaticMethodInterceptorPoint;
-import
org.apache.shardingsphere.agent.api.interceptor.ConstructorInterceptorPoint;
-import
org.apache.shardingsphere.agent.api.interceptor.InstanceMethodInterceptorPoint;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.StaticMethodPointcut;
+import org.apache.shardingsphere.agent.api.pointcut.ConstructorPointcut;
+import org.apache.shardingsphere.agent.api.pointcut.InstanceMethodPointcut;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
import org.apache.shardingsphere.agent.core.logging.LoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.PluginLoader;
import
org.apache.shardingsphere.agent.core.plugin.interceptor.StaticMethodAroundInterceptor;
@@ -76,18 +76,18 @@ public final class ShardingSphereTransformer implements
Transformer {
return builder;
}
Builder<?> result = builder.defineField(EXTRA_DATA, Object.class,
Opcodes.ACC_PRIVATE |
Opcodes.ACC_VOLATILE).implement(AdviceTargetObject.class).intercept(FieldAccessor.ofField(EXTRA_DATA));
- PluginInterceptorPoint pluginInterceptorPoint =
pluginLoader.loadPluginInterceptorPoint(typeDescription);
- result = interceptConstructor(typeDescription,
pluginInterceptorPoint.getConstructorInterceptorPoints(), result, classLoader);
- result = interceptStaticMethod(typeDescription,
pluginInterceptorPoint.getStaticMethodInterceptorPoints(), result, classLoader);
- result = interceptInstanceMethod(typeDescription,
pluginInterceptorPoint.getInstanceMethodInterceptorPoints(), result,
classLoader);
+ PluginPointcuts pluginPointcuts =
pluginLoader.loadPluginInterceptorPoint(typeDescription);
+ result = interceptConstructor(typeDescription,
pluginPointcuts.getConstructorPointcuts(), result, classLoader);
+ result = interceptStaticMethod(typeDescription,
pluginPointcuts.getStaticMethodPointcuts(), result, classLoader);
+ result = interceptInstanceMethod(typeDescription,
pluginPointcuts.getInstanceMethodPointcuts(), result, classLoader);
return result;
}
private Builder<?> interceptConstructor(final TypeDescription description,
- final
Collection<ConstructorInterceptorPoint> constructorInterceptorPoints, final
Builder<?> builder, final ClassLoader classLoader) {
+ final
Collection<ConstructorPointcut> constructorPointcuts, final Builder<?> builder,
final ClassLoader classLoader) {
Collection<ShardingSphereTransformationPoint<? extends
ConstructorInterceptor>> constructorAdviceComposePoints =
description.getDeclaredMethods().stream()
.filter(MethodDescription::isConstructor)
- .map(each ->
getMatchedTransformationPoint(constructorInterceptorPoints, each, classLoader))
+ .map(each ->
getMatchedTransformationPoint(constructorPointcuts, each, classLoader))
.filter(Objects::nonNull)
.collect(Collectors.toList());
Builder<?> result = builder;
@@ -104,29 +104,29 @@ public final class ShardingSphereTransformer implements
Transformer {
return result;
}
- private ShardingSphereTransformationPoint<? extends
ConstructorInterceptor> getMatchedTransformationPoint(final
Collection<ConstructorInterceptorPoint> constructorInterceptorPoints,
+ private ShardingSphereTransformationPoint<? extends
ConstructorInterceptor> getMatchedTransformationPoint(final
Collection<ConstructorPointcut> constructorPointcuts,
final InDefinedShape methodDescription, final
ClassLoader classLoader) {
- List<ConstructorInterceptorPoint> matchedConstructorInterceptorPoints
= constructorInterceptorPoints
+ List<ConstructorPointcut> matchedConstructorPointcuts =
constructorPointcuts
.stream().filter(each ->
each.getMatcher().matches(methodDescription)).collect(Collectors.toList());
- if (matchedConstructorInterceptorPoints.isEmpty()) {
+ if (matchedConstructorPointcuts.isEmpty()) {
return null;
}
- if (1 == matchedConstructorInterceptorPoints.size()) {
+ if (1 == matchedConstructorPointcuts.size()) {
return new ShardingSphereTransformationPoint<>(
- methodDescription, new
ConstructorInterceptor(pluginLoader.getOrCreateInstance(matchedConstructorInterceptorPoints.get(0).getAdvice(),
classLoader)));
+ methodDescription, new
ConstructorInterceptor(pluginLoader.getOrCreateInstance(matchedConstructorPointcuts.get(0).getAdviceClassName(),
classLoader)));
}
- Collection<ConstructorAdvice> constructorAdvices =
matchedConstructorInterceptorPoints.stream()
- .map(ConstructorInterceptorPoint::getAdvice)
+ Collection<ConstructorAdvice> constructorAdvices =
matchedConstructorPointcuts.stream()
+ .map(ConstructorPointcut::getAdviceClassName)
.map(each -> (ConstructorAdvice)
pluginLoader.getOrCreateInstance(each, classLoader))
.collect(Collectors.toList());
return new ShardingSphereTransformationPoint<>(methodDescription, new
ComposedConstructorInterceptor(constructorAdvices));
}
- private Builder<?> interceptStaticMethod(final TypeDescription
description, final Collection<StaticMethodInterceptorPoint>
staticMethodInterceptorPoints,
+ private Builder<?> interceptStaticMethod(final TypeDescription
description, final Collection<StaticMethodPointcut> staticMethodPointcuts,
final Builder<?> builder, final
ClassLoader classLoader) {
Collection<ShardingSphereTransformationPoint<?>>
staticMethodAdvicePoints = description.getDeclaredMethods().stream()
.filter(each -> each.isStatic() && !(each.isAbstract() ||
each.isSynthetic()))
- .map(each ->
getMatchedStaticMethodPoint(staticMethodInterceptorPoints, each, classLoader))
+ .map(each ->
getMatchedStaticMethodPoint(staticMethodPointcuts, each, classLoader))
.filter(Objects::nonNull)
.collect(Collectors.toList());
Builder<?> result = builder;
@@ -148,47 +148,47 @@ public final class ShardingSphereTransformer implements
Transformer {
return result;
}
- private ShardingSphereTransformationPoint<?>
getMatchedStaticMethodPoint(final Collection<StaticMethodInterceptorPoint>
staticMethodAroundPoints,
+ private ShardingSphereTransformationPoint<?>
getMatchedStaticMethodPoint(final Collection<StaticMethodPointcut>
staticMethodAroundPoints,
final InDefinedShape methodDescription, final ClassLoader classLoader) {
- List<StaticMethodInterceptorPoint> staticMethodInterceptorPoints =
staticMethodAroundPoints.stream().filter(each ->
each.getMatcher().matches(methodDescription)).collect(Collectors.toList());
- if (staticMethodInterceptorPoints.isEmpty()) {
+ List<StaticMethodPointcut> staticMethodPointcuts =
staticMethodAroundPoints.stream().filter(each ->
each.getMatcher().matches(methodDescription)).collect(Collectors.toList());
+ if (staticMethodPointcuts.isEmpty()) {
return null;
}
- if (1 == staticMethodInterceptorPoints.size()) {
- return getSingleStaticMethodPoint(methodDescription,
staticMethodInterceptorPoints.get(0), classLoader);
+ if (1 == staticMethodPointcuts.size()) {
+ return getSingleStaticMethodPoint(methodDescription,
staticMethodPointcuts.get(0), classLoader);
}
- return getComposedStaticMethodPoint(methodDescription,
staticMethodInterceptorPoints, classLoader);
+ return getComposedStaticMethodPoint(methodDescription,
staticMethodPointcuts, classLoader);
}
private ShardingSphereTransformationPoint<?>
getSingleStaticMethodPoint(final InDefinedShape methodDescription,
-
final StaticMethodInterceptorPoint staticMethodInterceptorPoint, final
ClassLoader classLoader) {
- StaticMethodAroundAdvice staticMethodAroundAdvice =
pluginLoader.getOrCreateInstance(staticMethodInterceptorPoint.getAdvice(),
classLoader);
- return staticMethodInterceptorPoint.isOverrideArgs()
+
final StaticMethodPointcut staticMethodPointcut, final ClassLoader classLoader)
{
+ StaticMethodAroundAdvice staticMethodAroundAdvice =
pluginLoader.getOrCreateInstance(staticMethodPointcut.getAdviceClassName(),
classLoader);
+ return staticMethodPointcut.isOverrideArgs()
? new ShardingSphereTransformationPoint<>(methodDescription,
new StaticMethodInterceptorArgsOverride(staticMethodAroundAdvice))
: new ShardingSphereTransformationPoint<>(methodDescription,
new StaticMethodAroundInterceptor(staticMethodAroundAdvice));
}
private ShardingSphereTransformationPoint<?>
getComposedStaticMethodPoint(final InDefinedShape methodDescription,
-
final Collection<StaticMethodInterceptorPoint> staticMethodInterceptorPoints,
final ClassLoader classLoader) {
+
final Collection<StaticMethodPointcut> staticMethodPointcuts, final ClassLoader
classLoader) {
Collection<StaticMethodAroundAdvice> staticMethodAroundAdvices = new
LinkedList<>();
boolean isArgsOverride = false;
- for (StaticMethodInterceptorPoint each :
staticMethodInterceptorPoints) {
+ for (StaticMethodPointcut each : staticMethodPointcuts) {
if (each.isOverrideArgs()) {
isArgsOverride = true;
}
- if (null != each.getAdvice()) {
-
staticMethodAroundAdvices.add(pluginLoader.getOrCreateInstance(each.getAdvice(),
classLoader));
+ if (null != each.getAdviceClassName()) {
+
staticMethodAroundAdvices.add(pluginLoader.getOrCreateInstance(each.getAdviceClassName(),
classLoader));
}
}
return isArgsOverride ? new
ShardingSphereTransformationPoint<>(methodDescription, new
ComposedStaticMethodInterceptorArgsOverride(staticMethodAroundAdvices))
: new ShardingSphereTransformationPoint<>(methodDescription,
new ComposedStaticMethodAroundInterceptor(staticMethodAroundAdvices));
}
- private Builder<?> interceptInstanceMethod(final TypeDescription
description, final Collection<InstanceMethodInterceptorPoint>
instanceMethodInterceptorPoints,
+ private Builder<?> interceptInstanceMethod(final TypeDescription
description, final Collection<InstanceMethodPointcut> instanceMethodPointcuts,
final Builder<?> builder, final
ClassLoader classLoader) {
Collection<ShardingSphereTransformationPoint<?>>
instanceMethodAdviceComposePoints = description.getDeclaredMethods().stream()
.filter(each -> !(each.isAbstract() || each.isSynthetic()))
- .map(each ->
getMatchedInstanceMethodPoint(instanceMethodInterceptorPoints, each,
classLoader))
+ .map(each ->
getMatchedInstanceMethodPoint(instanceMethodPointcuts, each, classLoader))
.filter(Objects::nonNull)
.collect(Collectors.toList());
Builder<?> result = builder;
@@ -210,37 +210,37 @@ public final class ShardingSphereTransformer implements
Transformer {
return result;
}
- private ShardingSphereTransformationPoint<?>
getMatchedInstanceMethodPoint(final Collection<InstanceMethodInterceptorPoint>
instanceMethodAroundPoints,
+ private ShardingSphereTransformationPoint<?>
getMatchedInstanceMethodPoint(final Collection<InstanceMethodPointcut>
instanceMethodAroundPoints,
final InDefinedShape methodDescription, final ClassLoader classLoader) {
- List<InstanceMethodInterceptorPoint> instanceMethodInterceptorPoints =
instanceMethodAroundPoints
+ List<InstanceMethodPointcut> instanceMethodPointcuts =
instanceMethodAroundPoints
.stream().filter(each ->
each.getMatcher().matches(methodDescription)).collect(Collectors.toList());
- if (instanceMethodInterceptorPoints.isEmpty()) {
+ if (instanceMethodPointcuts.isEmpty()) {
return null;
}
- if (1 == instanceMethodInterceptorPoints.size()) {
- return getSingleInstanceMethodPoint(methodDescription,
instanceMethodInterceptorPoints.get(0), classLoader);
+ if (1 == instanceMethodPointcuts.size()) {
+ return getSingleInstanceMethodPoint(methodDescription,
instanceMethodPointcuts.get(0), classLoader);
}
- return getComposeInstanceMethodPoint(methodDescription,
instanceMethodInterceptorPoints, classLoader);
+ return getComposeInstanceMethodPoint(methodDescription,
instanceMethodPointcuts, classLoader);
}
private ShardingSphereTransformationPoint<?>
getSingleInstanceMethodPoint(final InDefinedShape methodDescription,
-
final InstanceMethodInterceptorPoint instanceMethodInterceptorPoint, final
ClassLoader classLoader) {
- InstanceMethodAroundAdvice instanceMethodAroundAdvice =
pluginLoader.getOrCreateInstance(instanceMethodInterceptorPoint.getAdvice(),
classLoader);
- return instanceMethodInterceptorPoint.isOverrideArgs()
+
final InstanceMethodPointcut instanceMethodPointcut, final ClassLoader
classLoader) {
+ InstanceMethodAroundAdvice instanceMethodAroundAdvice =
pluginLoader.getOrCreateInstance(instanceMethodPointcut.getAdviceClassName(),
classLoader);
+ return instanceMethodPointcut.isOverrideArgs()
? new ShardingSphereTransformationPoint<>(methodDescription,
new InstanceMethodInterceptorArgsOverride(instanceMethodAroundAdvice))
: new ShardingSphereTransformationPoint<>(methodDescription,
new InstanceMethodAroundInterceptor(instanceMethodAroundAdvice));
}
private ShardingSphereTransformationPoint<?>
getComposeInstanceMethodPoint(final InDefinedShape methodDescription,
-
final Collection<InstanceMethodInterceptorPoint>
instanceMethodInterceptorPoints, final ClassLoader classLoader) {
+
final Collection<InstanceMethodPointcut> instanceMethodPointcuts, final
ClassLoader classLoader) {
Collection<InstanceMethodAroundAdvice> instanceMethodAroundAdvices =
new LinkedList<>();
boolean isArgsOverride = false;
- for (InstanceMethodInterceptorPoint each :
instanceMethodInterceptorPoints) {
+ for (InstanceMethodPointcut each : instanceMethodPointcuts) {
if (each.isOverrideArgs()) {
isArgsOverride = true;
}
- if (null != each.getAdvice()) {
-
instanceMethodAroundAdvices.add(pluginLoader.getOrCreateInstance(each.getAdvice(),
classLoader));
+ if (null != each.getAdviceClassName()) {
+
instanceMethodAroundAdvices.add(pluginLoader.getOrCreateInstance(each.getAdviceClassName(),
classLoader));
}
}
return isArgsOverride
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/AbstractPluginDefinitionService.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/AbstractPluginDefinitionService.java
index 3e1cf79bb0e..34f48d98c8e 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/AbstractPluginDefinitionService.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/AbstractPluginDefinitionService.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.agent.core.definition;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
-import
org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint.Builder;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts.Builder;
import org.apache.shardingsphere.agent.spi.PluginDefinitionService;
import java.util.Collection;
@@ -31,7 +31,7 @@ public abstract class AbstractPluginDefinitionService
implements PluginDefinitio
private final InterceptorPointRegistry interceptorPointRegistry = new
InterceptorPointRegistry();
@Override
- public final Collection<PluginInterceptorPoint> install(final boolean
isEnhancedForProxy) {
+ public final Collection<PluginPointcuts> install(final boolean
isEnhancedForProxy) {
if (isEnhancedForProxy) {
defineProxyInterceptors();
} else {
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/InterceptorPointRegistry.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/InterceptorPointRegistry.java
index 86ea4bf2960..997811f2999 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/InterceptorPointRegistry.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/definition/InterceptorPointRegistry.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.agent.core.definition;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
-import
org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint.Builder;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts.Builder;
import java.util.Collection;
import java.util.Map;
@@ -39,7 +39,7 @@ public final class InterceptorPointRegistry {
* @return interceptor point builder
*/
public Builder getInterceptorPointBuilder(final String targetClassName) {
- return builders.computeIfAbsent(targetClassName,
PluginInterceptorPoint::intercept);
+ return builders.computeIfAbsent(targetClassName,
PluginPointcuts::intercept);
}
/**
@@ -47,7 +47,7 @@ public final class InterceptorPointRegistry {
*
* @return all interceptor points
*/
- public Collection<PluginInterceptorPoint> getAllInterceptorPoints() {
+ public Collection<PluginPointcuts> getAllInterceptorPoints() {
return
builders.values().stream().map(Builder::install).collect(Collectors.toList());
}
}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
index bc0d2ee4501..c7a3f7582e0 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/AgentPluginLoader.java
@@ -23,7 +23,7 @@ import lombok.Setter;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatcher.Junction;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
import org.apache.shardingsphere.agent.config.AgentConfiguration;
import org.apache.shardingsphere.agent.core.common.AgentClassLoader;
import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
@@ -52,7 +52,7 @@ public final class AgentPluginLoader implements PluginLoader {
private final Collection<PluginJar> pluginJars = new LinkedList<>();
- private Map<String, PluginInterceptorPoint> interceptorPointMap;
+ private Map<String, PluginPointcuts> interceptorPointMap;
@Getter
@Setter
@@ -83,9 +83,9 @@ public final class AgentPluginLoader implements PluginLoader {
private void loadAllPluginInterceptorPoint(final ClassLoader classLoader) {
Collection<String> pluginNames = getPluginNames();
- Map<String, PluginInterceptorPoint> pointMap = new HashMap<>();
+ Map<String, PluginPointcuts> pointMap = new HashMap<>();
loadPluginDefinitionServices(pluginNames, pointMap, classLoader);
- interceptorPointMap = ImmutableMap.<String,
PluginInterceptorPoint>builder().putAll(pointMap).build();
+ interceptorPointMap = ImmutableMap.<String,
PluginPointcuts>builder().putAll(pointMap).build();
}
private Collection<String> getPluginNames() {
@@ -97,21 +97,21 @@ public final class AgentPluginLoader implements
PluginLoader {
return result;
}
- private void loadPluginDefinitionServices(final Collection<String>
pluginNames, final Map<String, PluginInterceptorPoint> pointMap, final
ClassLoader classLoader) {
+ private void loadPluginDefinitionServices(final Collection<String>
pluginNames, final Map<String, PluginPointcuts> pointMap, final ClassLoader
classLoader) {
PluginServiceLoader.newServiceInstances(PluginDefinitionService.class,
classLoader)
.stream()
.filter(each -> pluginNames.contains(each.getType()))
.forEach(each -> buildPluginInterceptorPointMap(each,
pointMap));
}
- private void buildPluginInterceptorPointMap(final PluginDefinitionService
pluginDefinitionService, final Map<String, PluginInterceptorPoint> pointMap) {
+ private void buildPluginInterceptorPointMap(final PluginDefinitionService
pluginDefinitionService, final Map<String, PluginPointcuts> pointMap) {
pluginDefinitionService.install(isEnhancedForProxy).forEach(each -> {
String target = each.getTargetClassName();
if (pointMap.containsKey(target)) {
- PluginInterceptorPoint pluginInterceptorPoint =
pointMap.get(target);
-
pluginInterceptorPoint.getConstructorInterceptorPoints().addAll(each.getConstructorInterceptorPoints());
-
pluginInterceptorPoint.getInstanceMethodInterceptorPoints().addAll(each.getInstanceMethodInterceptorPoints());
-
pluginInterceptorPoint.getStaticMethodInterceptorPoints().addAll(each.getStaticMethodInterceptorPoints());
+ PluginPointcuts pluginPointcuts = pointMap.get(target);
+
pluginPointcuts.getConstructorPointcuts().addAll(each.getConstructorPointcuts());
+
pluginPointcuts.getInstanceMethodPointcuts().addAll(each.getInstanceMethodPointcuts());
+
pluginPointcuts.getStaticMethodPointcuts().addAll(each.getStaticMethodPointcuts());
} else {
pointMap.put(target, each);
}
@@ -149,8 +149,8 @@ public final class AgentPluginLoader implements
PluginLoader {
}
@Override
- public PluginInterceptorPoint loadPluginInterceptorPoint(final
TypeDescription typeDescription) {
- return interceptorPointMap.getOrDefault(typeDescription.getTypeName(),
PluginInterceptorPoint.createDefault());
+ public PluginPointcuts loadPluginInterceptorPoint(final TypeDescription
typeDescription) {
+ return interceptorPointMap.getOrDefault(typeDescription.getTypeName(),
PluginPointcuts.createDefault());
}
@Override
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
index 596bab42044..fee7cc2dea2 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginLoader.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.core.plugin;
import net.bytebuddy.description.type.TypeDescription;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
public interface PluginLoader {
@@ -36,7 +36,7 @@ public interface PluginLoader {
* @param typeDescription type description
* @return plugin interceptor point
*/
- PluginInterceptorPoint loadPluginInterceptorPoint(TypeDescription
typeDescription);
+ PluginPointcuts loadPluginInterceptorPoint(TypeDescription
typeDescription);
/**
* To get or create instance of the advice class. Create new one and
caching when it is not exist.
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
index 136b71b4b2c..5c1ca35634c 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
@@ -23,7 +23,7 @@ import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
import org.apache.shardingsphere.agent.core.bytebuddy.listener.LoggingListener;
import
org.apache.shardingsphere.agent.core.mock.advice.MockStaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.mock.advice.MockConstructorAdvice;
@@ -70,8 +70,8 @@ public final class ShardingSphereTransformerTest {
objectPool.put(MockConstructorAdvice.class.getTypeName(), new
MockConstructorAdvice());
objectPool.put(MockInstanceMethodAroundAdvice.class.getTypeName(), new
MockInstanceMethodAroundAdvice());
objectPool.put(MockStaticMethodAroundAdvice.class.getTypeName(), new
MockStaticMethodAroundAdvice());
- Map<String, PluginInterceptorPoint> interceptorPointMap = new
HashMap<>(2, 1);
- PluginInterceptorPoint interceptorPoint =
PluginInterceptorPoint.intercept("org.apache.shardingsphere.agent.core.mock.material.Material")
+ Map<String, PluginPointcuts> interceptorPointMap = new HashMap<>(2, 1);
+ PluginPointcuts interceptorPoint =
PluginPointcuts.intercept("org.apache.shardingsphere.agent.core.mock.material.Material")
.aroundInstanceMethod(ElementMatchers.named("mock"))
.implement(MockInstanceMethodAroundAdvice.class.getTypeName())
.build()
@@ -83,7 +83,7 @@ public final class ShardingSphereTransformerTest {
.build()
.install();
interceptorPointMap.put(interceptorPoint.getTargetClassName(),
interceptorPoint);
- PluginInterceptorPoint interceptorPointInTwice =
PluginInterceptorPoint.intercept("org.apache.shardingsphere.agent.core.mock.material.RepeatedAdviceMaterial")
+ PluginPointcuts interceptorPointInTwice =
PluginPointcuts.intercept("org.apache.shardingsphere.agent.core.mock.material.RepeatedAdviceMaterial")
.aroundInstanceMethod(ElementMatchers.named("mock"))
.implement(MockInstanceMethodAroundAdvice.class.getTypeName())
.build()
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoaderTest.java
index b9074165e1c..d0c4634e0fc 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoaderTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/AgentPluginLoaderTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.agent.core.plugin.loader;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.pool.TypePool;
-import org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts;
import
org.apache.shardingsphere.agent.core.mock.advice.MockStaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.core.mock.advice.MockConstructorAdvice;
import
org.apache.shardingsphere.agent.core.mock.advice.MockInstanceMethodAroundAdvice;
@@ -59,7 +59,7 @@ public final class AgentPluginLoaderTest {
objectPool.put(MockConstructorAdvice.class.getTypeName(), new
MockConstructorAdvice());
objectPool.put(MockInstanceMethodAroundAdvice.class.getTypeName(), new
MockInstanceMethodAroundAdvice());
objectPool.put(MockStaticMethodAroundAdvice.class.getTypeName(), new
MockStaticMethodAroundAdvice());
- PluginInterceptorPoint interceptorPoint =
PluginInterceptorPoint.intercept("org.apache.shardingsphere.agent.core.mock.material.Material")
+ PluginPointcuts interceptorPoint =
PluginPointcuts.intercept("org.apache.shardingsphere.agent.core.mock.material.Material")
.aroundInstanceMethod(ElementMatchers.named("mock"))
.implement(MockInstanceMethodAroundAdvice.class.getTypeName())
.build()
diff --git
a/agent/plugins/metrics/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusPluginDefinitionService.java
b/agent/plugins/metrics/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusPluginDefinitionService.java
index e9c7dc5cda1..65954618e76 100644
---
a/agent/plugins/metrics/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusPluginDefinitionService.java
+++
b/agent/plugins/metrics/prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/definition/PrometheusPluginDefinitionService.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.definition;
import net.bytebuddy.matcher.ElementMatchers;
-import
org.apache.shardingsphere.agent.api.interceptor.PluginInterceptorPoint.Builder;
+import org.apache.shardingsphere.agent.api.pointcut.PluginPointcuts.Builder;
import
org.apache.shardingsphere.agent.core.definition.AbstractPluginDefinitionService;
import org.apache.shardingsphere.agent.core.yaml.entity.Interceptor;
import org.apache.shardingsphere.agent.core.yaml.entity.TargetPoint;