【发布时间】:2021-08-16 14:51:18
【问题描述】:
我编写了这个自定义聚合器,它的聚合响应是一个 HashMap。我在客户端反序列化器上遇到问题,在下面给出的错误中失败。任何线索可能是什么问题?
public class CountFixtureBySportAggregator extends Aggregator<HashMap.Entry<TraderVWFixtureKey, TraderVWFixture>, HashMap<Integer, Integer>> {
private static final long serialVersionUID = 1L;
private final HashMap<Integer, Set<String>> countBySportIdMap;
public CountFixtureBySportAggregator() {countBySportIdMap = new HashMap<>();}
@Override
public void accumulate(HashMap.Entry<TraderVWFixtureKey, TraderVWFixture> input) {
TraderVWFixture inputValue = input.getValue();
Integer sportId = inputValue.getSportId();
Set<String> matchIds = countBySportIdMap.getOrDefault(sportId, new HashSet<>());
if (inputValue.getOutrightId() == null) {
matchIds.add(inputValue.getMatchId());
} else {
matchIds.add(inputValue.getOutrightId());
}
countBySportIdMap.put(sportId, matchIds);
}
@Override
public void combine(Aggregator aggregator) {
CountFixtureBySportAggregator countFixtureBySportAggregator = (CountFixtureBySportAggregator) aggregator;
Map<Integer, Set<String>> sportCountMap = countFixtureBySportAggregator.getCountBySportIdMap();
for (Map.Entry<Integer, Set<String>> entry : sportCountMap.entrySet()) {
Integer key = entry.getKey();
countBySportIdMap.computeIfAbsent(key, integer -> new HashSet<>());
countBySportIdMap.get(key).addAll(entry.getValue());
}
}
@Override
public HashMap<Integer, Integer> aggregate() {
return new HashMap(countBySportIdMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().size())));
}
public HashMap<Integer, Set<String>> getCountBySportIdMap() { return countBySportIdMap; }
}
客户端反序列化错误:
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type -322. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:238)
at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:182)
at com.hazelcast.client.spi.ClientProxy.toObject(ClientProxy.java:102)
at com.hazelcast.client.proxy.ClientMapProxy.aggregate(ClientMapProxy.java:1543)
【问题讨论】:
-
聚合器中使用的所有类定义都可以序列化吗?请参阅jet-start.sh/docs/api/serialization#serialization-of-pipelines 另外,您在嵌入式 Hazelcast 实例中运行聚合器时是否遇到异常?
标签: java serialization hazelcast hazelcast-jet