公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

本文介绍了如何修复因引发java.lang.IlLegalStateException而引发的Hazelcast:未为EntryProcessor启用用户代码部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EntryProcessor为我们的应用程序设置一个用于Hazelcast的代码。为了分析为什么EntryProcessor的代码在我们的应用程序中不起作用,我尝试在我的本地计算机上设置一个类似的示例来重现该问题。然而,即使在我可以复制相同的问题之前,我还面临着另一个问题,该问题应该如下所示:

    从here下载Hazelcast IMDG 3.10.6。然后将其解压缩。
    新建Java应用程序并添加main page的Java客户端–>EntryProcessor下给出的代码。
    将Hazelcast-3.10.6和Hazelcast-Client-3.10.6 Jars添加到解压缩的Hazelcast文件夹的lib文件夹下。
    从bin文件夹下的start.bat文件启动Hazelcast成员(服务器)。
    运行步骤2中给出的Java客户端代码。

我还粘贴了下面的Java客户端代码以供参考。

package client;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.config.ClientUserCodeDeploymentConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.map.AbstractEntryProcessor;

import java.io.Serializable;
import java.util.Map;

public class EntryProcessorSample {

    public static class IncEntryProcessor extends AbstractEntryProcessor<String, Integer> implements Serializable {
        @Override
        public Object process(Map.Entry<String, Integer> entry) {
            // Get the value passed
            int oldValue = entry.getValue();
            // Update the value
            int newValue = oldValue + 1;
            // Update the value back to the entry stored in the Hazelcast Member this EntryProcessor is running on.
            entry.setValue(newValue);
            // No need to return anything back to the caller, we can return whatever we like here.
            return null;
        }
    }

    public static void main(String[] args) {
        // Enable Code Deployment from this Client classpath to the Cluster Members classpath
        // User Code Deployment needs to be enabled on the Cluster Members as well.
        ClientConfig config = new ClientConfig();
        ClientUserCodeDeploymentConfig userCodeDeploymentConfig = config.getUserCodeDeploymentConfig();
        userCodeDeploymentConfig.setEnabled(true);
        userCodeDeploymentConfig.addClass(EntryProcessorSample.IncEntryProcessor.class);
        // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
        HazelcastInstance hz = HazelcastClient.newHazelcastClient(config);
        // Get the Distributed Map from Cluster.
        IMap<String, Integer> map = hz.getMap("my-distributed-map");
        // Put the integer value of 0 into the Distributed Map
        map.put("key", 0);
        // Run the IncEntryProcessor class on the Hazelcast Cluster Member holding the key called "key"
        map.executeOnKey("key", new IncEntryProcessor());
        // Show that the IncEntryProcessor updated the value.
        System.out.println("new value:" + map.get("key"));
        // Shutdown this Hazelcast Client
        hz.shutdown();
    }
} 

我希望代码运行时没有任何问题,因为hazelcast site中给出的Java客户端的Map示例运行得很好。另外,由于我们显式启用了客户端配置的用户代码部署,我不明白为什么会出现此问题。

推荐答案

您也需要在成员端开启User Code Deployment。

这篇关于如何修复因引发java.lang.IlLegalStateException而引发的Hazelcast:未为EntryProcessor启用用户代码部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

分享到:
标签:Java 代码 修复 启用 引发 用户 部署
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定