private void AddConfigPortableFactories(IDictionary <int, IPortableFactory> portableFactories,
                                                SerializationConfig config)
        {
            foreach (var entry in config.GetPortableFactories())
            {
                int factoryId            = entry.Key;
                IPortableFactory factory = entry.Value;
                if (factoryId <= 0)
                {
                    throw new ArgumentException("IPortableFactory factoryId must be positive! -> " + factory);
                }
                if (portableFactories.ContainsKey(factoryId))
                {
                    throw new ArgumentException("IPortableFactory with factoryId '" + factoryId +
                                                "' is already registered!");
                }
                portableFactories.Add(factoryId, factory);
            }
            foreach (var entry in config.GetPortableFactoryClasses())
            {
                int    factoryId        = entry.Key;
                string factoryClassName = entry.Value;
                if (factoryId <= 0)
                {
                    throw new ArgumentException("IPortableFactory factoryId must be positive! -> " + factoryClassName);
                }
                if (portableFactories.ContainsKey(factoryId))
                {
                    throw new ArgumentException("IPortableFactory with factoryId '" + factoryId +
                                                "' is already registered!");
                }

                var type = Type.GetType(factoryClassName);
                if (type == null)
                {
                    throw new HazelcastSerializationException("Unable to find type " + factoryClassName);
                }
                if (!typeof(IPortableFactory).IsAssignableFrom(type))
                {
                    throw new HazelcastSerializationException("Type " + type + " does not implement IPortableFactory");
                }
                var factory = Activator.CreateInstance(type) as IPortableFactory;
                portableFactories.Add(factoryId, factory);
            }

            foreach (IPortableFactory f in portableFactories.Values)
            {
                if (f is IHazelcastInstanceAware)
                {
                    ((IHazelcastInstanceAware)f).SetHazelcastInstance(_hazelcastInstance);
                }
            }
        }
 public virtual SerializationConfig AddPortableFactory(int factoryId, IPortableFactory portableFactory)
 {
     GetPortableFactories().Add(factoryId, portableFactory);
     return this;
 }
 /// <summary>
 /// Adds a <see cref="IPortableFactory"/> mapped with a factory id to be registered
 /// </summary>
 /// <param name="factoryId">factory ID of <see cref="IPortableFactory"/> to be registered</param>
 /// <param name="portableFactory">factory instance to be registered</param>
 /// <returns>configured <see cref="SerializationConfig"/> for chaining</returns>
 public virtual SerializationConfig AddPortableFactory(int factoryId, IPortableFactory portableFactory)
 {
     GetPortableFactories().Add(factoryId, portableFactory);
     return(this);
 }
Exemple #4
0
 public ISerializationServiceBuilder AddPortableFactory(int id, IPortableFactory factory)
 {
     _portableFactories.Add(id, factory);
     return(this);
 }
Exemple #5
0
 public SerializationConfig AddPortableFactory(int factoryId, IPortableFactory portableFactory)
 {
     PortableFactories.Add(factoryId, portableFactory);
     return(this);
 }
 public ISerializationServiceBuilder AddPortableFactory(int id, IPortableFactory factory)
 {
     _portableFactories.Add(id, factory);
     return this;
 }