没有为名称空间注册DataSerializeFactory [英] No DataSerializeFactory registered for namespace

查看:89
本文介绍了没有为名称空间注册DataSerializeFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HZ 3.4和3.4.1中进行了尝试,但是输出相同

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

我试图使用以下功能将虚拟数据导入到Hazelcast集群中

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)

我正在使用DataSerializableFactory

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;
}
....
}

和我的xml config:

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>
....


推荐答案

在两端(服务器和客户端)上配置DataSerializableFactory。这也意味着代码需要在两个位置都可用:)

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

这篇关于没有为名称空间注册DataSerializeFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆