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.
Merge pull request alibaba#92 from zhaoyb1990/feature/classloader_opt…
…imize 开放模块指定类加载器路由能力
- Loading branch information
Showing
6 changed files
with
213 additions
and
17 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
sandbox-common-api/src/main/java/com/alibaba/jvm/sandbox/api/routing/RoutingExt.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,17 @@ | ||
package com.alibaba.jvm.sandbox.api.routing; | ||
|
||
/** | ||
* <p> | ||
* 提供给模块的扩展类路由白名单spi | ||
* | ||
* @author yuebing.zyb@alibaba-inc.com 2018/4/24 10:38. | ||
*/ | ||
public interface RoutingExt { | ||
|
||
/** | ||
* 获取类的特殊路由方式 | ||
* | ||
* @return 类路由方式 | ||
*/ | ||
RoutingInfo getSpecialRouting(); | ||
} |
90 changes: 90 additions & 0 deletions
90
sandbox-common-api/src/main/java/com/alibaba/jvm/sandbox/api/routing/RoutingInfo.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,90 @@ | ||
package com.alibaba.jvm.sandbox.api.routing; | ||
|
||
/** | ||
* <p> | ||
* 提供给模块使用的目标类路由白名单,白名单的类不隔离 | ||
* | ||
* 模块可以通过引入业务包进行编码 | ||
* | ||
* 使用类的时候,调用业务的类加载器,保证模块可以正常使用业务系统中的类 | ||
* | ||
* @author yuebing.zyb@alibaba-inc.com 2018/4/24 10:38. | ||
*/ | ||
public class RoutingInfo { | ||
|
||
/** | ||
* 路由类型 | ||
*/ | ||
public enum Type { | ||
/** | ||
* 被pattern匹配的类,由目标的类的类加载器进行加载 | ||
*/ | ||
TARGET_CLASS, | ||
/** | ||
* 被pattern匹配的类,由目标类载器进行加载 | ||
*/ | ||
TARGET_CLASS_LOADER | ||
} | ||
|
||
/** | ||
* 路由匹配正则表达式 | ||
*/ | ||
private String[] pattern; | ||
|
||
/** | ||
* 路由类型 | ||
*/ | ||
private RoutingInfo.Type type; | ||
|
||
/** | ||
* 目标类 | ||
*/ | ||
private String targetClass; | ||
|
||
/** | ||
* 目标类加载器 | ||
*/ | ||
private ClassLoader targetClassloader; | ||
|
||
private RoutingInfo() {} | ||
|
||
/** | ||
* 使用目标类的加载器进行路由 | ||
* | ||
* @param targetClass 目标类 | ||
* @param pattern 匹配类正则 | ||
*/ | ||
public RoutingInfo(String targetClass, String... pattern) { | ||
this.type = Type.TARGET_CLASS; | ||
this.pattern = pattern; | ||
this.targetClass = targetClass; | ||
} | ||
|
||
/** | ||
* 使用目标类的加载器进行路由 | ||
* | ||
* @param classLoader | ||
* @param pattern | ||
*/ | ||
public RoutingInfo(ClassLoader classLoader, String... pattern) { | ||
this.type = Type.TARGET_CLASS_LOADER; | ||
this.pattern = pattern; | ||
this.targetClassloader = classLoader; | ||
} | ||
|
||
public String[] getPattern() { | ||
return pattern; | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public String getTargetClass() { | ||
return targetClass; | ||
} | ||
|
||
public ClassLoader getTargetClassloader() { | ||
return targetClassloader; | ||
} | ||
} |
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