Search in sources :

Example 1 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 2 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class DefaultClientExtension method createSerializationService.

@Override
public InternalSerializationService createSerializationService(byte version) {
    InternalSerializationService ss;
    try {
        ClientConfig config = client.getClientConfig();
        ClassLoader configClassLoader = config.getClassLoader();
        HazelcastInstance hazelcastInstance = client;
        PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
        SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
        SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
        if (version > 0) {
            builder.setVersion(version);
        }
        ss = builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(new HazelcastClientManagedContext(client, config.getManagedContext())).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).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) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 3 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class XmlClientConfigBuilderTest method testSerializationConfig.

@Test
public void testSerializationConfig() {
    final SerializationConfig serializationConfig = clientConfig.getSerializationConfig();
    assertEquals(3, serializationConfig.getPortableVersion());
    final Map<Integer, String> dsClasses = serializationConfig.getDataSerializableFactoryClasses();
    assertEquals(1, dsClasses.size());
    assertEquals("com.hazelcast.examples.DataSerializableFactory", dsClasses.get(1));
    final Map<Integer, String> pfClasses = serializationConfig.getPortableFactoryClasses();
    assertEquals(1, pfClasses.size());
    assertEquals("com.hazelcast.examples.PortableFactory", pfClasses.get(2));
    final Collection<SerializerConfig> serializerConfigs = serializationConfig.getSerializerConfigs();
    assertEquals(1, serializerConfigs.size());
    final SerializerConfig serializerConfig = serializerConfigs.iterator().next();
    assertEquals("com.hazelcast.examples.DummyType", serializerConfig.getTypeClassName());
    assertEquals("com.hazelcast.examples.SerializerFactory", serializerConfig.getClassName());
    final GlobalSerializerConfig globalSerializerConfig = serializationConfig.getGlobalSerializerConfig();
    assertEquals("com.hazelcast.examples.GlobalSerializerFactory", globalSerializerConfig.getClassName());
    assertEquals(ByteOrder.BIG_ENDIAN, serializationConfig.getByteOrder());
    assertEquals(true, serializationConfig.isCheckClassDefErrors());
    assertEquals(false, serializationConfig.isAllowUnsafe());
    assertEquals(false, serializationConfig.isEnableCompression());
    assertEquals(true, serializationConfig.isEnableSharedObject());
    assertEquals(true, serializationConfig.isUseNativeByteOrder());
}
Also used : GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) XMLConfigBuilderTest(com.hazelcast.config.XMLConfigBuilderTest)

Example 4 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class PortableTest method testWriteObjectWithCustomSerializable.

@Test
public void testWriteObjectWithCustomSerializable() {
    SerializationConfig config = new SerializationConfig();
    SerializerConfig sc = new SerializerConfig().setImplementation(new CustomSerializationTest.FooXmlSerializer()).setTypeClass(CustomSerializationTest.Foo.class);
    config.addSerializerConfig(sc);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).setConfig(config).build();
    CustomSerializationTest.Foo foo = new CustomSerializationTest.Foo("f");
    ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(foo);
    Data data = serializationService.toData(objectCarryingPortable1);
    ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
    assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class CustomSerializationTest method testSerializer.

private void testSerializer(ByteOrder order, boolean allowUnsafe) throws Exception {
    SerializationConfig config = new SerializationConfig();
    config.setAllowUnsafe(allowUnsafe).setByteOrder(order).setUseNativeByteOrder(false);
    SerializerConfig sc = new SerializerConfig().setImplementation(new FooXmlSerializer()).setTypeClass(Foo.class);
    config.addSerializerConfig(sc);
    SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    Foo foo = new Foo("f");
    Data d = ss.toData(foo);
    Foo newFoo = ss.toObject(d);
    assertEquals(newFoo, foo);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService)

Aggregations

SerializationConfig (com.hazelcast.config.SerializationConfig)73 Test (org.junit.Test)45 QuickTest (com.hazelcast.test.annotation.QuickTest)37 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)36 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)23 SerializerConfig (com.hazelcast.config.SerializerConfig)21 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Data (com.hazelcast.internal.serialization.Data)18 SerializationService (com.hazelcast.internal.serialization.SerializationService)14 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ClientConfig (com.hazelcast.client.config.ClientConfig)8 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)7 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)6 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)6 SerializationService (com.hazelcast.spi.serialization.SerializationService)6 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)6 Config (com.hazelcast.config.Config)5