Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support delegate from classLoaderHook for getResourceAsStream #811

Merged
merged 8 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions sofa-ark-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@
<version>${guice.version}</version>
</dependency>

<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>4.2.3</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class DirectoryContainerArchive implements ContainerArchive {
private final URL[] urls;

private final static String[] AKR_CONTAINER_JAR = { "aopalliance-1.0", "commons-io-2.7",
"guava-32.1.3-jre", "guice-6.0.0", "guice-multibindings-4.2.3", "failureaccess-1.0.1",
"javax.inject-1", "logback-core-1.2.9", "logback-classic-1.2.9", "slf4j-api-1.7.32",
"guava-32.1.3-jre", "guice-6.0.0", "failureaccess-1.0.1", "javax.inject-1",
"logback-core-1.2.9", "logback-classic-1.2.9", "slf4j-api-1.7.32",
"log-sofa-boot-starter", "log-sofa-boot", "sofa-common-tools",
"netty-all-4.1.94.Final", "netty-transport-4.1.94.Final", "netty-common-4.1.94.Final",
"netty-handler-4.1.94.Final", "netty-codec-4.1.94.Final", "netty-buffer-4.1.94.Final",
Expand Down Expand Up @@ -95,4 +95,4 @@ public InputStream getInputStream(ZipEntry zipEntry) {
public Iterator<Entry> iterator() {
throw new RuntimeException("unreachable invocation.");
}
}
}
4 changes: 0 additions & 4 deletions sofa-ark-parent/core-impl/container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public Class<?> preFindClass(String name, ClassLoaderService classLoaderService,
@Override
public Class<?> postFindClass(String name, ClassLoaderService classLoaderService, Biz biz)
throws ClassNotFoundException {
ClassLoader bizClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz == null || (biz.getBizClassLoader() == bizClassLoader)) {
ClassLoader masterClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz == null || (biz.getBizClassLoader() == masterClassLoader)) {
return null;
}
// The cglib proxy class cannot be delegate to the master, it must be created by the biz's own defineClass
Expand All @@ -60,15 +60,15 @@ public Class<?> postFindClass(String name, ClassLoaderService classLoaderService
return null;
}
// if Master Biz contains same class in multi jar, need to check each whether is provided
Class<?> clazz = bizClassLoader.loadClass(name);
Class<?> clazz = masterClassLoader.loadClass(name);
if (clazz != null) {
if (biz.isDeclared(clazz.getProtectionDomain().getCodeSource().getLocation(), "")) {
return clazz;
}

try {
String classResourceName = name.replace('.', '/') + ".class";
Enumeration<URL> urls = bizClassLoader.getResources(classResourceName);
Enumeration<URL> urls = masterClassLoader.getResources(classResourceName);
while (urls.hasMoreElements()) {
URL resourceUrl = urls.nextElement();
if (resourceUrl != null && biz.isDeclared(resourceUrl, classResourceName)) {
Expand Down Expand Up @@ -97,12 +97,12 @@ public URL postFindResource(String name, ClassLoaderService classLoaderService,
return null;
}

ClassLoader bizClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz.getBizClassLoader() == bizClassLoader) {
ClassLoader masterClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz.getBizClassLoader() == masterClassLoader) {
return null;
}
try {
URL resourceUrl = bizClassLoader.getResource(name);
URL resourceUrl = masterClassLoader.getResource(name);
if (resourceUrl != null && biz.isDeclared(resourceUrl, name)) {
return resourceUrl;
}
Expand All @@ -124,12 +124,12 @@ public Enumeration<URL> postFindResources(String name, ClassLoaderService classL
if (biz == null || (!biz.isDeclaredMode() && shouldSkip(name))) {
return null;
}
ClassLoader bizClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz.getBizClassLoader() == bizClassLoader) {
ClassLoader masterClassLoader = ArkClient.getMasterBiz().getBizClassLoader();
if (biz.getBizClassLoader() == masterClassLoader) {
return null;
}
try {
Enumeration<URL> resourceUrls = bizClassLoader.getResources(name);
Enumeration<URL> resourceUrls = masterClassLoader.getResources(name);
List<URL> matchedResourceUrls = new ArrayList<>();
while (resourceUrls.hasMoreElements()) {
URL resourceUrl = resourceUrls.nextElement();
Expand Down
Loading