No DataSerializeFactory registered for namespace

放肆的年华 提交于 2019-12-22 18:29:18

问题


I tried it in HZ 3.4 and 3.4.1 but with the same output

I`m trying to import dummy data to my Hazelcast cluster, with following function

    HazelcastInstance cluster = HazelcastClient.newHazelcastClient(this.conf);
    Map<String, Customer> mapCustomers = cluster.getMap("customers");

    System.out.println(mapCustomers.size());
    System.out.println("hello world");


    for (int customerID = 0; customerID < 2000; customerID++) {
        Customer p = new Customer();
        mapCustomers.put(Integer.toString(customerID), p);
        System.out.println("inserted customer number " + Integer.toString(customerID));
    }
    cluster.shutdown();

when I first run this code, there are no issues and the output is something like this

0
hello world
inserted customer number 0
inserted customer number 1
inserted customer number 2
inserted customer number 3

the problem is if I try to run the import function if there are data already - everytime I got

4
hello world
Exception in thread "main"
com.hazelcast.nio.serialization.HazelcastSerializationException: No DataSerializerFactory registered for namespace: 1
at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:98)
at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:39)
at com.hazelcast.nio.serialization.StreamSerializerAdapter.toObject(StreamSerializerAdapter.java:65)
at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:260)
at com.hazelcast.client.spi.ClientProxy.toObject(ClientProxy.java:173)
at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:128)
at com.hazelcast.client.proxy.ClientMapProxy.put(ClientMapProxy.java:352)
at com.hazelcast.client.proxy.ClientMapProxy.put(ClientMapProxy.java:200)
at com.test.queries.Importer.importDummyData(Importer.java:42)
at run_import.main(run_import.java:9)

I am using DataSerializableFactory

public class SerializerFactory implements DataSerializableFactory {

public static final int FACTORY_ID = 1;

public static final int CUSTOMER_TYPE = 1;

public static final int ORDER_TYPE = 2;

@Override
public IdentifiedDataSerializable create(int typeId) {
    switch (typeId) {
        case CUSTOMER_TYPE:
            return  new Customer();
        case ORDER_TYPE:
            return new Order();
    }
    return null;
}

}

public class Customer implements IdentifiedDataSerializable {
 ....
@Override
public int getFactoryId() {
    return SerializerFactory.FACTORY_ID;
}

@Override
public int getId() {
    return SerializerFactory.CUSTOMER_TYPE;
}
....
}

and my xml config:

....
<serialization>
    <data-serializable-factories>
        <data-serializable-factory factory-id="1">
            SerializerFactory
        </data-serializable-factory>
    </data-serializable-factories>
    <portable-version>0</portable-version>
</serialization>
....

回答1:


You have to configure the DataSerializableFactory on both ends, servers and clients. That also means the code needs to be available at both positions :)



来源:https://stackoverflow.com/questions/28612473/no-dataserializefactory-registered-for-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!