Skip to content

Commit

Permalink
Merge branch 'cassandra-4.0' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
belliottsmith committed Nov 10, 2021
2 parents 6329229 + 07b908c commit cedde3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -532,7 +532,7 @@
<dependency groupId="com.google.code.java-allocation-instrumenter" artifactId="java-allocation-instrumenter" version="${allocation-instrumenter.version}" scope="test">
<exclusion groupId="com.google.guava" artifactId="guava"/>
</dependency>
<dependency groupId="org.apache.cassandra" artifactId="dtest-api" version="0.0.10" scope="test"/>
<dependency groupId="org.apache.cassandra" artifactId="dtest-api" version="0.0.11" scope="test"/>
<dependency groupId="org.reflections" artifactId="reflections" version="0.9.12" scope="test"/>
<dependency groupId="com.puppycrawl.tools" artifactId="checkstyle" version="8.40" scope="test"/>
<dependency groupId="org.apache.hadoop" artifactId="hadoop-core" version="1.0.3" scope="provided">
Expand Down
Expand Up @@ -20,6 +20,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -239,14 +240,18 @@ private IInvokableInstance newInstance(int generation)
IInvokableInstance instance;
try
{
instance = Instance.transferAdhoc((SerializableTriFunction<IInstanceConfig, ClassLoader, FileSystem, Instance>)Instance::new, classLoader)
instance = Instance.transferAdhocPropagate((SerializableTriFunction<IInstanceConfig, ClassLoader, FileSystem, Instance>)Instance::new, classLoader)
.apply(config.forVersion(version.version), classLoader, root.getFileSystem());
}
catch (NoSuchMethodError e)
catch (InvocationTargetException e)
{
instance = Instance.transferAdhoc((SerializableBiFunction<IInstanceConfig, ClassLoader, Instance>)Instance::new, classLoader)
.apply(config.forVersion(version.version), classLoader);
}
catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}

if (instanceInitializer != null)
instanceInitializer.beforeStartup(instance);
Expand Down
Expand Up @@ -170,6 +170,18 @@ public <T extends Serializable> T transfer(T in)
}

public static <T extends Serializable> T transferAdhoc(T object, ClassLoader classLoader)
{
try
{
return transferOneObjectAdhoc(object, classLoader, lookupDeserializeOneObject(classLoader));
}
catch (IllegalAccessException | InvocationTargetException e)
{
throw new RuntimeException(e);
}
}

public static <T extends Serializable> T transferAdhocPropagate(T object, ClassLoader classLoader) throws InvocationTargetException, IllegalAccessException
{
return transferOneObjectAdhoc(object, classLoader, lookupDeserializeOneObject(classLoader));
}
Expand All @@ -188,21 +200,14 @@ public <T extends Serializable> T apply(T in)
};
}

private static <T extends Serializable> T transferOneObjectAdhoc(T object, ClassLoader classLoader, Method deserializeOnInstance)
private static <T extends Serializable> T transferOneObjectAdhoc(T object, ClassLoader classLoader, Method deserializeOnInstance) throws IllegalAccessException, InvocationTargetException
{
byte[] bytes = serializeOneObject(object);
try
{
Object onInstance = deserializeOnInstance.invoke(null, bytes);
if (onInstance.getClass().getClassLoader() != classLoader)
throw new IllegalStateException(onInstance + " seemingly from wrong class loader: " + onInstance.getClass().getClassLoader() + ", but expected " + classLoader);
Object onInstance = deserializeOnInstance.invoke(null, bytes);
if (onInstance.getClass().getClassLoader() != classLoader)
throw new IllegalStateException(onInstance + " seemingly from wrong class loader: " + onInstance.getClass().getClassLoader() + ", but expected " + classLoader);

return (T) onInstance;
}
catch (IllegalAccessException | InvocationTargetException e)
{
throw new RuntimeException(e);
}
return (T) onInstance;
}

private static Method lookupDeserializeOneObject(ClassLoader classLoader)
Expand Down

0 comments on commit cedde3d

Please sign in to comment.