public ISerializationService Build() { if (_portableVersion < 0) { _portableVersion = 0; } if (_config != null) { AddConfigDataSerializableFactories(_dataSerializableFactories, _config); AddConfigPortableFactories(_portableFactories, _config); _classDefinitions = _classDefinitions.Union(_config.GetClassDefinitions()).ToList(); } //TODO: Add support for multiple versions var ss = new SerializationService( CreateInputOutputFactory(), _portableVersion, _dataSerializableFactories, _portableFactories, _classDefinitions, _checkClassDefErrors, _partitioningStrategy, _initialOutputBufferSize); if (_config != null) { if (_config.GetGlobalSerializerConfig() != null) { var globalSerializerConfig = _config.GetGlobalSerializerConfig(); var serializer = globalSerializerConfig.GetImplementation(); if (serializer == null) { try { var className = globalSerializerConfig.GetClassName(); var type = Type.GetType(className); if (type != null) { serializer = Activator.CreateInstance(type) as ISerializer; } } catch (Exception e) { throw new HazelcastSerializationException(e); } } var aware = serializer as IHazelcastInstanceAware; if (aware != null) { aware.SetHazelcastInstance(_hazelcastInstance); } ss.RegisterGlobal(serializer, globalSerializerConfig.GetOverrideClrSerialization()); } var typeSerializers = _config.GetSerializerConfigs(); foreach (var serializerConfig in typeSerializers) { var serializer = serializerConfig.GetImplementation(); if (serializer == null) { try { var className = serializerConfig.GetClassName(); var type = Type.GetType(className); if (type != null) { serializer = Activator.CreateInstance(type) as ISerializer; } } catch (Exception e) { throw new HazelcastSerializationException(e); } } if (serializer is IHazelcastInstanceAware) { ((IHazelcastInstanceAware)serializer).SetHazelcastInstance(_hazelcastInstance); } var typeClass = serializerConfig.GetTypeClass(); if (typeClass == null) { try { var className = serializerConfig.GetTypeClassName(); typeClass = Type.GetType(className); } catch (TypeLoadException e) { throw new HazelcastSerializationException(e); } } ss.Register(typeClass, serializer); } } return(ss); }
public ISerializationService Build() { if (_portableVersion < 0) { _portableVersion = 0; } if (_config != null) { AddConfigDataSerializableFactories(_dataSerializableFactories, _config); AddConfigPortableFactories(_portableFactories, _config); classDefinitions = classDefinitions.Union(_config.GetClassDefinitions()).ToList(); } //TODO: add support for multiple versions var ss = new SerializationService( CreateInputOutputFactory(), _portableVersion, _dataSerializableFactories, _portableFactories, classDefinitions, _checkClassDefErrors, _managedContext, _partitioningStrategy, _initialOutputBufferSize, _enableCompression, _enableSharedObject); if (_config != null) { if (_config.GetGlobalSerializerConfig() != null) { GlobalSerializerConfig globalSerializerConfig = _config.GetGlobalSerializerConfig(); ISerializer serializer = globalSerializerConfig.GetImplementation(); if (serializer == null) { try { string className = globalSerializerConfig.GetClassName(); Type type = Type.GetType(className); if (type != null) { serializer = Activator.CreateInstance(type) as ISerializer; } } catch (Exception e) { throw new HazelcastSerializationException(e); } } var aware = serializer as IHazelcastInstanceAware; if (aware != null) { aware.SetHazelcastInstance(_hazelcastInstance); } ss.RegisterGlobal(serializer); } ICollection <SerializerConfig> typeSerializers = _config.GetSerializerConfigs(); foreach (SerializerConfig serializerConfig in typeSerializers) { ISerializer serializer = serializerConfig.GetImplementation(); if (serializer == null) { try { string className = serializerConfig.GetClassName(); Type type = Type.GetType(className); if (type != null) { serializer = Activator.CreateInstance(type) as ISerializer; } } catch (Exception e) { throw new HazelcastSerializationException(e); } } if (serializer is IHazelcastInstanceAware) { ((IHazelcastInstanceAware)serializer).SetHazelcastInstance(_hazelcastInstance); } Type typeClass = serializerConfig.GetTypeClass(); if (typeClass == null) { try { string className = serializerConfig.GetTypeClassName(); typeClass = Type.GetType(className); } catch (TypeLoadException e) { throw new HazelcastSerializationException(e); } } ////call by reflaction //MethodInfo method = typeof(ISerializationService).GetMethod("Register"); //MethodInfo generic = method.MakeGenericMethod(typeClass); //generic.Invoke(ss, new object[] { serializer }); ////mimics: ss.Register<typeClass>(serializer);" ss.Register(typeClass, serializer); } } return(ss); }