use of com.hazelcast.nio.serialization.Serializer in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method build.
@Override
public InternalSerializationService build() {
initVersions();
if (config != null) {
addConfigDataSerializableFactories(dataSerializableFactories, config, classLoader);
addConfigPortableFactories(portableFactories, config, classLoader);
classDefinitions.addAll(config.getClassDefinitions());
}
InputOutputFactory inputOutputFactory = createInputOutputFactory();
InternalSerializationService ss = createSerializationService(inputOutputFactory);
registerSerializerHooks(ss);
if (config != null) {
if (config.getGlobalSerializerConfig() != null) {
GlobalSerializerConfig globalSerializerConfig = config.getGlobalSerializerConfig();
Serializer serializer = globalSerializerConfig.getImplementation();
if (serializer == null) {
try {
serializer = ClassLoaderUtil.newInstance(classLoader, globalSerializerConfig.getClassName());
} catch (Exception e) {
throw new HazelcastSerializationException(e);
}
}
if (serializer instanceof HazelcastInstanceAware) {
((HazelcastInstanceAware) serializer).setHazelcastInstance(hazelcastInstance);
}
((AbstractSerializationService) ss).registerGlobal(serializer, globalSerializerConfig.isOverrideJavaSerialization());
}
}
return ss;
}
use of com.hazelcast.nio.serialization.Serializer in project hazelcast by hazelcast.
the class SerializerHookLoader method load.
private void load() {
try {
final Iterator<SerializerHook> hooks = ServiceLoader.iterator(SerializerHook.class, FACTORY_ID, classLoader);
while (hooks.hasNext()) {
final SerializerHook hook = hooks.next();
final Class serializationType = hook.getSerializationType();
if (serializationType != null) {
serializers.put(serializationType, hook);
}
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
if (serializerConfigs != null) {
for (SerializerConfig serializerConfig : serializerConfigs) {
Serializer serializer = serializerConfig.getImplementation();
Class serializationType = serializerConfig.getTypeClass();
if (serializationType == null) {
try {
serializationType = ClassLoaderUtil.loadClass(classLoader, serializerConfig.getTypeClassName());
} catch (ClassNotFoundException e) {
throw new HazelcastSerializationException(e);
}
}
if (serializer == null) {
serializer = createSerializerInstance(serializerConfig, serializationType);
}
register(serializationType, serializer);
}
}
}
use of com.hazelcast.nio.serialization.Serializer in project hazelcast by hazelcast.
the class StreamSerializerAdapterTest method testAdaptor.
@Test
public void testAdaptor() throws Exception {
int[] testIn = new int[] { 1, 2, 3 };
ByteArrayObjectDataOutput out = new ByteArrayObjectDataOutput(100, mockSerializationService, ByteOrder.BIG_ENDIAN);
ByteArrayObjectDataInput in = new ByteArrayObjectDataInput(out.buffer, mockSerializationService, ByteOrder.BIG_ENDIAN);
adapter.write(out, testIn);
int[] read = (int[]) adapter.read(in);
Serializer impl = adapter.getImpl();
assertArrayEquals(testIn, read);
assertEquals(serializer, impl);
}
use of com.hazelcast.nio.serialization.Serializer in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method registerSerializerHooks.
private void registerSerializerHooks(InternalSerializationService ss) {
SerializerHookLoader serializerHookLoader = new SerializerHookLoader(config, classLoader);
Map<Class, Object> serializers = serializerHookLoader.getSerializers();
for (Map.Entry<Class, Object> entry : serializers.entrySet()) {
Class serializationType = entry.getKey();
Object value = entry.getValue();
Serializer serializer;
if (value instanceof SerializerHook) {
serializer = ((SerializerHook) value).createSerializer();
} else {
serializer = (Serializer) value;
}
if (value instanceof HazelcastInstanceAware) {
((HazelcastInstanceAware) value).setHazelcastInstance(hazelcastInstance);
}
if (ClassLoaderUtil.isInternalType(value.getClass())) {
((AbstractSerializationService) ss).safeRegister(serializationType, serializer);
} else {
((AbstractSerializationService) ss).register(serializationType, serializer);
}
}
}
use of com.hazelcast.nio.serialization.Serializer in project hazelcast by hazelcast.
the class ByteArraySerializerAdapterTest method testAdaptor.
@Test
public void testAdaptor() throws Exception {
byte[] testByteArray = new byte[] { 1, 2, 3 };
ByteArrayObjectDataOutput out = new ByteArrayObjectDataOutput(10, mockSerializationService, ByteOrder.BIG_ENDIAN);
ByteArrayObjectDataInput in = new ByteArrayObjectDataInput(out.buffer, mockSerializationService, ByteOrder.BIG_ENDIAN);
adapter.write(out, testByteArray);
byte[] read = (byte[]) adapter.read(in);
Serializer impl = adapter.getImpl();
assertArrayEquals(testByteArray, read);
assertEquals(serializer, impl);
assertEquals(serializer.getTypeId(), adapter.getTypeId());
}
Aggregations