Skip to content

Commit

Permalink
提交1.0.11,兼容1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmanpushcart committed Feb 26, 2018
1 parent b980e0c commit b65a253
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 119 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.0.11-SNAPSHOT</version>
<version>1.0.11</version>
<packaging>pom</packaging>

<name>sandbox ${project.version}</name>
Expand Down
2 changes: 1 addition & 1 deletion sandbox-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.0.11-SNAPSHOT</version>
<version>1.0.11</version>
</parent>
<artifactId>sandbox-agent</artifactId>
<name>sandbox-agent ${project.version}</name>
Expand Down
2 changes: 1 addition & 1 deletion sandbox-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.0.11-SNAPSHOT</version>
<version>1.0.11</version>
</parent>
<artifactId>sandbox-api</artifactId>
<name>sandbox-api ${project.version}</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.alibaba.jvm.sandbox.api.filter;

import com.alibaba.jvm.sandbox.api.annotation.IncludeBootstrap;
import com.alibaba.jvm.sandbox.api.annotation.IncludeSubClasses;

/**
* 增强过滤器
* <p>
* 原有的{@link Filter}表现形式过于单薄而且纵深扩展能力偏差,所以使用了一些Annotation进行扩展,
* 扩展之后的结果最终会以ExtFilter的形式在容器内部运转
*
* @author luanjia@taobao.com
* @since {@code sandbox-api:1.0.11}
*/
public interface ExtFilter extends Filter {

/**
* 是否搜索子类或实现类
*
* @return TRUE:搜索子类或实现类;FALSE:不搜索
*/
boolean isIncludeSubClasses();

/**
* 是否搜索来自BootstrapClassLoader所加载的类
*
* @return TRUE:搜索;FALSE:不搜索;最终容器是否会对BootstrapClassLoader所加载的类进行处理,
* 还需要参考{@code sandbox.properties#unsafe.enable=true}配合使用才能生效
*/
boolean isIncludeBootstrap();

/**
* 增强过滤器工厂类
*/
class ExtFilterFactory {

/**
* 生产增强过滤器
*
* @param filter 原生过滤器
* @param isIncludeSubClasses 是否包含子类
* @param isIncludeBootstrap 是否搜索BootstrapClassLoader所加载的类
* @return 增强过滤器
*/
public static ExtFilter make(final Filter filter,
final boolean isIncludeSubClasses,
final boolean isIncludeBootstrap) {
return new ExtFilter() {

@Override
public boolean isIncludeSubClasses() {
return isIncludeSubClasses;
}

@Override
public boolean isIncludeBootstrap() {
return isIncludeBootstrap;
}

@Override
public boolean doClassFilter(final int access,
final String javaClassName,
final String superClassTypeJavaClassName,
final String[] interfaceTypeJavaClassNameArray,
final String[] annotationTypeJavaClassNameArray) {
return filter.doClassFilter(
access,
javaClassName,
superClassTypeJavaClassName,
interfaceTypeJavaClassNameArray,
annotationTypeJavaClassNameArray
);
}

@Override
public boolean doMethodFilter(final int access,
final String javaMethodName,
final String[] parameterTypeJavaClassNameArray,
final String[] throwsTypeJavaClassNameArray,
final String[] annotationTypeJavaClassNameArray) {
return filter.doMethodFilter(
access,
javaMethodName,
parameterTypeJavaClassNameArray,
throwsTypeJavaClassNameArray,
annotationTypeJavaClassNameArray
);
}
};
}

/**
* 生产增强过滤器
*
* @param filter 原生过滤器
* @return 增强过滤器
*/
public static ExtFilter make(final Filter filter) {
return
filter instanceof ExtFilter
? (ExtFilter) filter
: make(
filter,
filter.getClass().isAnnotationPresent(IncludeSubClasses.class),
filter.getClass().isAnnotationPresent(IncludeBootstrap.class)
);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.alibaba.jvm.sandbox.api.listener.ext;

import com.alibaba.jvm.sandbox.api.annotation.IncludeBootstrap;
import com.alibaba.jvm.sandbox.api.annotation.IncludeSubClasses;
import com.alibaba.jvm.sandbox.api.event.Event;
import com.alibaba.jvm.sandbox.api.filter.AccessFlags;
import com.alibaba.jvm.sandbox.api.filter.ExtFilter;
import com.alibaba.jvm.sandbox.api.filter.Filter;
import com.alibaba.jvm.sandbox.api.listener.EventListener;
import com.alibaba.jvm.sandbox.api.resource.ModuleEventWatcher;
Expand Down Expand Up @@ -571,7 +570,7 @@ && matching(javaMethodName, bfBehavior.pattern)
}
};//filter

filters.add(wrap(filter, bfClass));
filters.add(makeExtFilter(filter, bfClass));
}
return new EventWatchCondition() {
@Override
Expand All @@ -581,16 +580,13 @@ public Filter[] getOrFilterArray() {
};
}

private Filter wrap(final Filter filter,
final BuildingForClass bfClass) {
Filter targetFilter = filter;
if (bfClass.isIncludeSubClasses) {
targetFilter = new IncludeSubClassWrapFilter(targetFilter);
}
if (bfClass.isIncludeBootstrap) {
targetFilter = new IncludeBootstrapWrapFilter(targetFilter);
}
return targetFilter;
private Filter makeExtFilter(final Filter filter,
final BuildingForClass bfClass) {
return ExtFilter.ExtFilterFactory.make(
filter,
bfClass.isIncludeSubClasses,
bfClass.isIncludeBootstrap
);
}

private ProgressGroup toProgressGroup(final List<Progress> progresses) {
Expand Down Expand Up @@ -636,63 +632,6 @@ public void onUnWatched() {
};
}

/**
* Filter的代理类,
* 很多FilterWrap要基于这个类玩
*/
private class ProxyFilter implements Filter {

final Filter filter;

ProxyFilter(Filter filter) {
this.filter = filter;
}

@Override
public boolean doClassFilter(final int access,
final String javaClassName,
final String superClassTypeJavaClassName,
final String[] interfaceTypeJavaClassNameArray,
final String[] annotationTypeJavaClassNameArray) {
return filter.doClassFilter(
access,
javaClassName,
superClassTypeJavaClassName,
interfaceTypeJavaClassNameArray,
annotationTypeJavaClassNameArray
);
}

@Override
public boolean doMethodFilter(final int access,
final String javaMethodName,
final String[] parameterTypeJavaClassNameArray,
final String[] throwsTypeJavaClassNameArray,
final String[] annotationTypeJavaClassNameArray) {
return filter.doMethodFilter(
access,
javaMethodName,
parameterTypeJavaClassNameArray,
throwsTypeJavaClassNameArray,
annotationTypeJavaClassNameArray
);
}
}

@IncludeSubClasses
private class IncludeSubClassWrapFilter extends ProxyFilter {
IncludeSubClassWrapFilter(Filter filter) {
super(filter);
}
}

@IncludeBootstrap
private class IncludeBootstrapWrapFilter extends ProxyFilter {
IncludeBootstrapWrapFilter(Filter filter) {
super(filter);
}
}

/**
* 观察进度组
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alibaba.jvm.sandbox.api.listener.ext;

import com.alibaba.jvm.sandbox.api.filter.ExtFilter;
import com.alibaba.jvm.sandbox.api.filter.Filter;

/**
Expand All @@ -12,8 +13,15 @@ public interface EventWatchCondition {

/**
* 获取"或"关系的查询过滤器数组
* <p>
* 这里会有点绕,因为在{@code sandbox-api:1.0.10}的时候已经将这个接口披露出来了
* 所以为了向下兼容API,必须保持{@link Filter}的声明。但实际上内部可能是一个{@link ExtFilter},
* 会在容器内部做兼容性判断。
*
* @return "或"关系的查询过滤器数组
* @since {@code sandbox-api:1.0.10}
* @since {@code sandbox-api:1.0.11}
* </p>
*/
Filter[] getOrFilterArray();

Expand Down
2 changes: 1 addition & 1 deletion sandbox-common-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>sandbox</artifactId>
<groupId>com.alibaba.jvm.sandbox</groupId>
<version>1.0.11-SNAPSHOT</version>
<version>1.0.11</version>
</parent>
<artifactId>sandbox-common-api</artifactId>
<name>sandbox-common-api ${project.version}</name>
Expand Down
2 changes: 1 addition & 1 deletion sandbox-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.jvm.sandbox</groupId>
<artifactId>sandbox</artifactId>
<version>1.0.11-SNAPSHOT</version>
<version>1.0.11</version>
</parent>
<artifactId>sandbox-core</artifactId>
<name>sandbox-core ${project.version}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.alibaba.jvm.sandbox.api.filter.Filter;
import com.alibaba.jvm.sandbox.core.CoreConfigure;
import com.alibaba.jvm.sandbox.core.manager.CoreLoadedClassDataSource;
import com.alibaba.jvm.sandbox.core.util.matcher.FilterMatcher;
import com.alibaba.jvm.sandbox.core.util.matcher.ExtFilterMatcher;
import com.alibaba.jvm.sandbox.core.util.matcher.Matcher;
import com.alibaba.jvm.sandbox.core.util.matcher.UnsupportedMatcher;
import com.alibaba.jvm.sandbox.core.util.matcher.structure.ClassStructureFactory;
Expand All @@ -13,6 +13,8 @@
import java.lang.instrument.Instrumentation;
import java.util.*;

import static com.alibaba.jvm.sandbox.api.filter.ExtFilter.ExtFilterFactory.make;

/**
* 已加载类数据源默认实现
*
Expand Down Expand Up @@ -120,7 +122,7 @@ private List<Class<?>> find(final Matcher matcher,
*/
@Override
public Set<Class<?>> find(Filter filter) {
return new LinkedHashSet<Class<?>>(find(new FilterMatcher(filter), false));
return new LinkedHashSet<Class<?>>(find(new ExtFilterMatcher(make(filter)), false));
}

}
Loading

0 comments on commit b65a253

Please sign in to comment.