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

#39 Support for Hazelcast 4.0 #40

Merged
merged 3 commits into from
Feb 13, 2020
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<module>subzero-all-it-hz310</module>
<module>subzero-all-it-hz311</module>
<module>subzero-all-it-hz312</module>
<module>subzero-all-it-hz40</module>
</modules>
</profile>

Expand Down
40 changes: 40 additions & 0 deletions subzero-all-it-hz40/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>subzero</artifactId>
<groupId>info.jerrinot</groupId>
<version>0.10-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>subzero-all-it-hz40</artifactId>

<properties>
<hazelcast.version>4.0</hazelcast.version>
</properties>

<dependencies>
<dependency>
<groupId>info.jerrinot</groupId>
<artifactId>subzero-it-base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package info.jerrinot.subzero.it.hz40;

import info.jerrinot.subzero.it.BaseSmokeTests;

public class Hazelcast40_SmokeTest extends BaseSmokeTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class ClassLoaderUtils {
private static final boolean DEBUG_CLASSLOADING = Boolean.getBoolean("subzero.debug.classloading");
private static final Method loadClassMethodRef = getClassLoadMethod();

public static ClassLoader getConfiguredClassLoader(HazelcastInstance hz) {
try {
Expand Down Expand Up @@ -40,4 +41,40 @@ private static ClassLoader tryToGetClassLoader(HazelcastInstance hz) {
}
}
}

public static Class<?> loadClass(String className, ClassLoader classLoader) throws InvocationTargetException, IllegalAccessException {
return (Class<?>) loadClassMethodRef.invoke(null, classLoader, className);
}

private static Method getClassLoadMethod() {
Class<?> classLoaderUtilClass = getClassLoaderUtilClass();
try {
return classLoaderUtilClass.getDeclaredMethod("loadClass", ClassLoader.class, String.class);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}

private static Class<?> getClassLoaderUtilClass() {
String[] possibleNames = {
"com.hazelcast.nio.ClassLoaderUtil",
"com.hazelcast.internal.nio.ClassLoaderUtil"
};

for (String possibleName : possibleNames) {
Class<?> loadedClass = loadClass(possibleName);
if (loadedClass != null) return loadedClass;
}
throw new IllegalStateException("unable to load ClassLoaderUtil");
}

private static Class<?> loadClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
} catch (NoClassDefFoundError e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package info.jerrinot.subzero.internal.strategy;

import com.esotericsoftware.kryo.util.DefaultClassResolver;
import com.hazelcast.nio.ClassLoaderUtil;
import info.jerrinot.subzero.internal.ClassLoaderUtils;

import java.lang.reflect.InvocationTargetException;

/**
* Delegates class loading to Hazelcast -> SubZero will use the same strategy
Expand All @@ -19,9 +21,15 @@ public DelegatingClassResolver(ClassLoader classLoader) {
@Override
protected Class<?> getTypeByName(String className) {
try {
return ClassLoaderUtil.loadClass(classLoader, className);
} catch (ClassNotFoundException e) {
return null;
return ClassLoaderUtils.loadClass(className, classLoader);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof ClassNotFoundException) {
return null;
}
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}

}