Search in sources :

Example 6 with SerializationConfig

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;
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) Config(com.hazelcast.config.Config) SerializationConfig(com.hazelcast.config.SerializationConfig) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) VersionMismatchException(com.hazelcast.internal.cluster.impl.VersionMismatchException)

Example 7 with SerializationConfig

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());
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SampleIdentifiedDataSerializable(com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with SerializationConfig

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);
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SampleIdentifiedDataSerializable(com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with SerializationConfig

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);
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with SerializationConfig

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();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

SerializationConfig (com.hazelcast.config.SerializationConfig)24 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Test (org.junit.Test)18 SerializerConfig (com.hazelcast.config.SerializerConfig)14 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)11 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 SerializationService (com.hazelcast.spi.serialization.SerializationService)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)4 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)3 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)3 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)3 Config (com.hazelcast.config.Config)2 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2