繁体   English   中英

为什么 apache ignite 没有反序列化 java.util.Collections$SetFromMap?

[英]Why apache ignite is not deserializing the java.util.Collections$SetFromMap?

Apache 当我尝试将数据放入缓存时,ignite 抛出以下异常,

Caused by: class org.apache.ignite.IgniteCheckedException: Failed to deserialize object with given class loader: [clsLdr=org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager$CacheClassLoader@5d5b5fa7, err=Failed to deserialize object [typeName=java.util.Collections$SetFromMap]]
    Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.ignite.internal.marshaller.optimized.OptimizedObjectInputStream.readSerializable(OptimizedObjectInputStream.java:608)
        ... 43 more
    Caused by: java.lang.ClassNotFoundException: com.example.springapachecache.HelloWorld$1

程序:

 package com.example.springapachecache;

 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;

 import java.util.*;

 public class HelloWorld {
 public static void main(String[] args) throws IgniteException {
    // Preparing IgniteConfiguration using Java APIs
    IgniteConfiguration cfg = new IgniteConfiguration();

    // The node will be started as a client node.
    cfg.setClientMode(true);

    // Classes of custom Java logic will be transferred over the wire from this app.
    cfg.setPeerClassLoadingEnabled(true);

    // Setting up an IP Finder to ensure the client can locate the servers.
    TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
    ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));

    // Starting the node
    Ignite ignite = Ignition.start(cfg);
    IgniteCache<Integer, Set<String>> setCache = ignite.getOrCreateCache("mySetCache");
    System.out.println("setCache before: "+setCache.get(1));
    Set<String> meetingUuids = Collections.newSetFromMap(new LinkedHashMap<String, Boolean>() {
        // Set backed by LRU map.
        private static final long serialVersionUID = -8251614405342939979L;
        @Override
        protected boolean removeEldestEntry(Map.Entry<String, Boolean> eldest) {
            return size() > 1000;
        }
    });

    meetingUuids.add("meetingId");
   //        Set<String> meetingUuidSet = new HashSet<>(meetingUuids);
   //        setCache.put(3, meetingUuidSet);
    setCache.put(1, meetingUuids);
    System.out.println("setCache after: "+setCache.get(1));

    // Disconnect from the cluster.
    ignite.close();
}

}

使用简单的 linkedHashMap(Set meetingUuids = Collections.newSetFromMap(new LinkedHashMap<String, Boolean>()) 构建 Set 工作正常。你能帮忙吗?

你在最后一段中暗示了这个问题。 你可以在 Ignite 中存储 Sets,你可以在 .network 上“peer class load”代码。 不能做的是对等 class 加载您的“模型”中使用的代码,即用于定义缓存的任何 class。 在您的示例代码中,这是Collections.newSetFromMap中的闭包。

我认为将自定义 Set 存储在 Ignite 中有点混乱。 例如,您不能使用 SQL 查询 collections。 所以最好的解决方案是 model 你的数据不同。

如果你真的想要 go 这条路线,如果你把你的 class 的副本放在服务器端它应该可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM