use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class DefaultNodeExtension method createSerializationService.
public InternalSerializationService createSerializationService() {
InternalSerializationService ss;
try {
Config config = node.getConfig();
ClassLoader configClassLoader = node.getConfigClassLoader();
HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
byte version = (byte) node.getProperties().getInteger(GroupProperty.SERIALIZATION_VERSION);
ss = (InternalSerializationService) builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(hazelcastInstance.managedContext).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setVersion(version).build();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
return ss;
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class SerializerHookLoaderTest method testLoad_withParametrizedConstructor.
@Test
public void testLoad_withParametrizedConstructor() throws Exception {
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setClassName("com.hazelcast.internal.serialization.impl.TestSerializerHook$TestSerializerWithTypeConstructor");
serializerConfig.setTypeClassName("com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable");
SerializationConfig serializationConfig = getConfig().getSerializationConfig();
serializationConfig.addSerializerConfig(serializerConfig);
SerializerHookLoader hook = new SerializerHookLoader(serializationConfig, classLoader);
Map<Class, Object> serializers = hook.getSerializers();
TestSerializerHook.TestSerializerWithTypeConstructor serializer = (TestSerializerHook.TestSerializerWithTypeConstructor) serializers.get(SampleIdentifiedDataSerializable.class);
assertEquals(SampleIdentifiedDataSerializable.class, serializer.getClazz());
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class SerializerHookLoaderTest method testLoad_withParametrizedConstructorAndCompatibilitySwitchOn.
@Test
public void testLoad_withParametrizedConstructorAndCompatibilitySwitchOn() throws Exception {
String propName = "hazelcast.compat.serializers.use.default.constructor.only";
String origProperty = System.getProperty(propName);
try {
System.setProperty(propName, "true");
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setClassName("com.hazelcast.internal.serialization.impl.TestSerializerHook$TestSerializerWithTypeConstructor");
serializerConfig.setTypeClassName("com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable");
SerializationConfig serializationConfig = getConfig().getSerializationConfig();
serializationConfig.addSerializerConfig(serializerConfig);
SerializerHookLoader hook = new SerializerHookLoader(serializationConfig, classLoader);
Map<Class, Object> serializers = hook.getSerializers();
TestSerializerHook.TestSerializerWithTypeConstructor serializer = (TestSerializerHook.TestSerializerWithTypeConstructor) serializers.get(SampleIdentifiedDataSerializable.class);
assertNull(serializer.getClazz());
} finally {
if (origProperty != null) {
System.setProperty(propName, origProperty);
} else
System.clearProperty(propName);
}
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class SerializerHookLoaderTest method testLoad_withDefaultConstructor.
@Test
public void testLoad_withDefaultConstructor() throws Exception {
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setClassName("com.hazelcast.internal.serialization.impl.TestSerializerHook$TestSerializer");
serializerConfig.setTypeClassName("com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable");
SerializationConfig serializationConfig = getConfig().getSerializationConfig();
serializationConfig.addSerializerConfig(serializerConfig);
SerializerHookLoader hook = new SerializerHookLoader(serializationConfig, classLoader);
Map<Class, Object> serializers = hook.getSerializers();
assertNotNull(serializers);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class BinaryCompatibilityTest method createSerializationService.
private SerializationService createSerializationService() {
SerializationConfig config = new SerializationConfig();
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
config.addSerializerConfig(serializerConfig);
}
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
config.addSerializerConfig(serializerConfig);
}
config.setAllowUnsafe(allowUnsafe);
config.setByteOrder(byteOrder);
ClassDefinition classDefinition = new ClassDefinitionBuilder(ReferenceObjects.PORTABLE_FACTORY_ID, ReferenceObjects.INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
return new DefaultSerializationServiceBuilder().setConfig(config).setVersion(version).addPortableFactory(ReferenceObjects.PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(ReferenceObjects.IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).addClassDefinition(classDefinition).build();
}
Aggregations