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 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;
}
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());
}
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);
}
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);
}
Aggregations