forked from alibaba/jvm-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b980e0c
commit b65a253
Showing
19 changed files
with
207 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
sandbox-api/src/main/java/com/alibaba/jvm/sandbox/api/filter/ExtFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.