本文介绍了在客户端中使用Near Cache的Hazelcast ClassNotFound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过以下方式使用Hazelcast(3.9.2、3.11没什么区别):我有Hazelcast服务器(成员).我专门运行它们,而不是嵌入它们.我不想教Hazelcast成员要在其中存储的类.我使用了捆绑的hazelcast.xml文件,并执行了以下插件(3.9.2)

I try to use Hazelcast (3.9.2, 3.11 no difference) in the following way:I got Hazelcast servers (members). I run them dedicated, not embedded.I do not want to teach the Hazelcast members the classes I want to store within them. I used the bundled hazelcast.xml file and did the following addon (3.9.2)

<replicatedmap name="default">
    <in-memory-format>BINARY</in-memory-format>
    <statistics-enabled>true</statistics-enabled>
</replicatedmap>

我还激活了TCP,而不是多播(true/false)那就是我所做的所有更改.我从一位成员开始听127.0.0.1:5701

I also activated TCP, not Multicast (true/false)That is all changes I did. I started with one Member listening to 127.0.0.1:5701

然后,我尝试将Hazelcast客户端附加到用于存储和检索Map的成员上(Primally ReplicatedMaps,但是Map在我的情况下也不起作用)

Then I try to attach Hazelcast clients to the member for storing and retrieving Maps (Primarily ReplicatedMaps, but Maps also do not work in my scenario)

我的客户端代码如下(缓存只是一个没有属性的可序列化的类):

My Client Code looks like this (Cache is just a Serializable Class with no attributes):

public class Main {
  public static final String HAZELCAST_INSTANCE_NAME = "HAZI";
  public static final String REPLICATEDMAP_NAME = "REP_MAP";
  public static final String MAP_NAME = "NORMAL_MAP";

public static void main(String[] args) {
    init();
    HazelcastInstance instance = HazelcastClient.getHazelcastClientByName(HAZELCAST_INSTANCE_NAME);
    Map<String, Object> repMap = instance.getReplicatedMap(REPLICATEDMAP_NAME);
    repMap.put("MyKey", new Cache());
    System.err.println("Retrieve " + repMap.get("MyKey"));
    Map<String, Object> normalMap = instance.getReplicatedMap(MAP_NAME);
    normalMap.put("MyKey", new Cache());
    System.err.println("Retrieve " + normalMap.get("MyKey"));
    System.exit(1);
}

private static void init() {
    ClientConfig cfg = new ClientConfig();
    cfg.setInstanceName(HAZELCAST_INSTANCE_NAME);
    cfg.addNearCacheConfig(defineNearCache(REPLICATEDMAP_NAME));
    cfg.addNearCacheConfig(defineNearCache(MAP_NAME));
    // for analysis in the hazelcast management console
    cfg.getProperties().put("hazelcast.client.statistics.enabled", "true");
    cfg.getProperties().put("hazelcast.client.statistics.period.seconds", "60");
    cfg.getNetworkConfig().addAddress("127.0.0.1:5701");
    if (HazelcastClient.newHazelcastClient(cfg) == null) {
        System.err.println(" !!! ERROR in Cache Config !!!");
    }
}
private static NearCacheConfig defineNearCache(String mapName) {
    EvictionConfig evictionConfig = new EvictionConfig()
            .setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT)
            .setSize(200);
    return new NearCacheConfig()
            .setName(mapName)
            .setInMemoryFormat(InMemoryFormat.BINARY)
            .setInvalidateOnChange(true)
            .setEvictionConfig(evictionConfig);
}

}

我现在的问题是:使用此代码,我得到一个ClassNotFoundError尝试将东西放到复制的地图或常规地图上,但是放在专用的Hazelcast服务器(成员)中,而不是在客户端上.

My problem now is: Using this code I get a ClassNotFoundError trying put put things to the replicated map or regular map, but in the dedicated Hazelcast server (member), not on the client side.

    SCHWERWIEGEND: [127.0.0.1]:5701 [dev] [3.9.2] hz._hzInstance_1_dev.event-3 caught an exception while processing task:com.hazelcast.spi.impl.eventservice.impl.LocalEventDispatcher@eeed098
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: de.empic.hazelwar.model.Cache
        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:185)
        at com.hazelcast.map.impl.DataAwareEntryEvent.getValue(DataAwareEntryEvent.java:90)
        at com.hazelcast.client.impl.protocol.task.replicatedmap.AbstractReplicatedMapAddEntryListenerMessageTask.handleEvent(AbstractReplicatedMapAddEntryListenerMessageTask.java:92)
        at com.hazelcast.client.impl.protocol.task.replicatedmap.AbstractReplicatedMapAddEntryListenerMessageTask.entryAdded(AbstractReplicatedMapAddEntryListenerMessageTask.java:132)
        at com.hazelcast.replicatedmap.impl.ReplicatedMapEventPublishingService.dispatchEvent(ReplicatedMapEventPublishingService.java:82)
        at com.hazelcast.replicatedmap.impl.ReplicatedMapService.dispatchEvent(ReplicatedMapService.java:247)
        at com.hazelcast.spi.impl.eventservice.impl.LocalEventDispatcher.run(LocalEventDispatcher.java:64)
        at com.hazelcast.util.executor.StripedExecutor$Worker.process(StripedExecutor.java:225)
        at com.hazelcast.util.executor.StripedExecutor$Worker.run(StripedExecutor.java:208)
Caused by: java.lang.ClassNotFoundException: de.empic.hazelwar.model.Cache
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:173)
    at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:147)
    at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:591)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1868)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1751)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)
    ... 10 more

每当我从客户端配置中删除Near缓存配置时,所有工作都非常完美,除了我当然没有Near缓存.

Whenever I remove the near cache config from the client config, all works pretty perfect, except I do not have a near cache of course.

我在这里想念什么?

推荐答案

我的问题是使用3.11.1版本的hazelcast解决的.

My problem is solved using the 3.11.1 version of hazelcast.

这篇关于在客户端中使用Near Cache的Hazelcast ClassNotFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:25