use of com.hazelcast.nio.serialization.SerializerHook 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.SerializerHook 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);
}
}
}
Aggregations