Search in sources :

Example 1 with SerializerHook

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);
        }
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializerHook(com.hazelcast.nio.serialization.SerializerHook) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 2 with SerializerHook

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);
        }
    }
}
Also used : HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) HashMap(java.util.HashMap) Map(java.util.Map) SerializerHook(com.hazelcast.nio.serialization.SerializerHook) Serializer(com.hazelcast.nio.serialization.Serializer)

Aggregations

Serializer (com.hazelcast.nio.serialization.Serializer)2 SerializerHook (com.hazelcast.nio.serialization.SerializerHook)2 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1