Skip to content

Commit

Permalink
support delegate from classLoaderHook for getResourceAsStream (#811)
Browse files Browse the repository at this point in the history
* support delegate from classLoaderHook for getResourceAsStream

* rm guice-multibinding

* remove guice multi binding lib

* Revert "support delegate from classLoaderHook for getResourceAsStream"

This reverts commit 5bd306b.

* fix typo

* remove guice-multibinding

* fix format
  • Loading branch information
lvjing2 committed Jan 2, 2024
1 parent dfef361 commit 3bcf96f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
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

0 comments on commit 3bcf96f

Please sign in to comment.