0

我需要在 IMap 中动态添加某些类型为字符串、日期、int 的可移植字段的索引。

  1. 首先,在向包含某些条目的 Map 添加索引时,会引发 Hazelcast 未处理异常,说明找不到工厂 ID 的 PortableFactory:XXX。
  2. 其次,我在将条目加载到地图之前尝试了另一种添加索引的方法,在添加索引时没有发现任何问题,但是在再次设置条目时,我遇到了与上述相同的异常。但令人惊讶的是,我在地图内发现了一个异常情况的记录。

是否为期望在服务器端的类定义的可移植对象添加索引?但是对于便携式序列化,不需要按照文档在服务器端定义类。

会员配置:

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>
    <management-center enabled="true">http://localhost:8085/mancenter</management-center>
    <network>
        <port auto-increment="true" port-count="100">5701</port>
        <outbound-ports>           
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="true">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>           
            <discovery-strategies>
            </discovery-strategies>
        </join>
        <interfaces enabled="false">
            <interface>10.10.1.*</interface>
        </interfaces>       
    </network>   
    <map name="default">       
        <in-memory-format>BINARY</in-memory-format>
        <backup-count>1</backup-count>                       
        <cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
    </map>     
    <serialization>
        <portable-version>0</portable-version>
    </serialization>
    <services enable-defaults="true"/>
    <lite-member enabled="false"/>
</hazelcast>

请在下面找到客户端代码:

private static void DoMapIndexing()
{
IMap<TKey, TValue> map = GetMap<TKey, TValue>("testMap"); 
map.AddIndex("name", false);
map.AddIndex("DOB", true);
}

private static IMap<TKey, TValue> GetMap<TKey, TValue>(string mapName)
{
IHazelcastInstance client = getHazelcastClientConnection();
return client.GetMap<TKey, TValue>(mapName);
}

private static IHazelcastInstance getHazelcastClientConnection()
{
ClientConfig config = new ClientConfig();
config.GetNetworkConfig().AddAddress("x.x.x.x");
IDictionary<int, IPortableFactory> factoryClasses = new Dictionary<int, IPortableFactory>();
factoryClasses.Add(2000, new BusinessObjectPortableFactory());
config.GetSerializationConfig().SetPortableFactories(factoryClasses);
return HazelcastClient.NewHazelcastClient(config);
}

4

0 回答 0