本文介绍了在hazelcast管理中心控制台上获取SerializationException,将自定义对象用作键,在地图中使用值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Hazelcast集群中创建了一个地图.我可以在地图的Hazelcast管理中心UI上看到增加的条目数".在控制台上,我也可以使用m.size命令获取大小.

I have created a map in Hazelcast cluster. I can see the increased count of Entries on Hazelcast management center UI for my map. On console I can also get the size using m.size command.

我知道像Integer和String这样的原始包装器类,我可以使用m.get命令查看任何键的值.我将自定义对象用作地图的键和值,因此无法在控制台上使用m.keys或m.values命令.

I know for primitive wrapper classes like Integer and String I can use m.get command to see the values for any key. I am using custom objects as key and value for map, so I am not able to use m.keys or m.values command on console.

使用HazelcastSerializationException给出错误.我应该在Hazelcast Management中心方面进行哪些更改,以便在控制台上反序列化数据?

It gives Error with HazelcastSerializationException. What should I change on Hazelcast Management center side to get data deserialized on console?

我使用hazelcast版本3.8.1,并使用startManCenter.bat脚本在mancenter目录中运行Hazelcast管理中心.

I use hazelcast version 3.8.1 and run Hazelcast Management center in mancenter directory using startManCenter.bat script.

我不知道Hazelcast管理中心将如何获取自定义类.我应该将我的课程文件或已编译的jar复制到Hazelcast Management中心的某个位置,以便获取所需的课程吗?

I wonder how Hazelcast Management center will get the custom classes. Should I copy my class files or compiled jar to somewhere on Hazelcast Management center, so that it can get required classes?

这是来自管理中心控制台的日志:

Here is the log from management center console:

    hazelcast[rules_cache] > m.size
Size = 7
hazelcast[rules_cache] > m.keys
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.rulemanagement.model.RuleCacheKey
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)
    at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:184)
    at com.hazelcast.client.spi.ClientProxy.toObject(ClientProxy.java:187)
    at com.hazelcast.client.proxy.ClientMapProxy.keySet(ClientMapProxy.java:1047)
    at com.hazelcast.client.console.ClientConsoleApp.handleMapKeys(ClientConsoleApp.java:835)
    at com.hazelcast.client.console.ClientConsoleApp.handleCommand(ClientConsoleApp.java:369)
    at com.hazelcast.client.console.ClientConsoleApp.start(ClientConsoleApp.java:184)
    at com.hazelcast.client.console.ClientConsoleApp.main(ClientConsoleApp.java:1564)
Caused by: java.lang.ClassNotFoundException: com.rulemanagement.model.RuleCacheKey
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:149)
    at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:123)
    at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:522)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
    ... 8 more
hazelcast[rules_cache] >

推荐答案

我正在使用hazelcast-3.8.1 zip软件包随附的clientConsole.bat.它在演示文件夹下.我已在该演示文件夹中添加了hazelcast-client.xml文件,以连接到远程hazelcast节点.这为我提供了类似于在hazelcast管理中心控制台"选项卡上看到的控制台.

I am using the clientConsole.bat provided with hazelcast-3.8.1 zip package.It is under demo folder. I have added hazelcast-client.xml file in that demo folder to connect to remote hazelcast node. This provides me the console similar to what we see on hazelcast management center console tab.

使用clientConsole.bat的好处是,即使未配置管理中心,我也可以查询通过hazelcast群集创建的地图.

Benefit to use clientConsole.bat is that even if management center is not configured, I can query my map created over hazelcast cluster.

我只能使用m.size命令来查看地图是否正在获取新条目.由于我将自定义类用于键/值对,因此其他命令(例如m.keys和m.values)由于SerializationException而失败.

I was able to use only m.size command to see if map is getting new entries. Since I was using custom class for key/value pair so other commands like m.keys and m.values were failing due to SerializationException.

解决方案:我在hazelcast-3.8.1 \ lib目录中添加了包含这些类的jar,并修改了clientConsole.bat脚本以从lib目录中加载其他jar.现在,我可以运行m.keys和m.values命令了.

Solution: I added the jars containing those classes in hazelcast-3.8.1\lib directory and modified clientConsole.bat script to load additional jars from lib directory. Now I am able to run m.keys and m.values command.

这篇关于在hazelcast管理中心控制台上获取SerializationException,将自定义对象用作键,在地图中使用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:25