java is not enabled,如何修复从java.lang抛出的Hazelcast。IllegalStateException:不支持用户代码部署;对于EntryProcessor(How ...

I am trying to set up a code for Hazelcast using EntryProcessor for our application. To analyze why the code for EntryProcessor was not working in our application, I am trying to setup a similar example on my local machine to reproduce the issue. However, even before I can reproduce the same issue I am facing another issue which should be reproducible as follows:

Download Hazelcast IMDG 3.10.6 from here. and unzip it.

Create a new Java application and add the code given under Java Client –> EntryProcessor of the main page.

Add hazelcast-3.10.6 and hazelcast-client-3.10.6 jars present under lib folder of the unzipped hazelcast folder.

Start hazelcast member (server) from start.bat file present under bin folder.

Run the Java Client code given in step 2.

I am pasting the Java client code below as well for reference.

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 implements Serializable {

@Override

public Object process(Map.Entry 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 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();

}

}

I expected the code to run without any issues, since the Map example given for Java Client in the hazelcast site works just fine. Also since we are explicitly enabling user code deployment for the ClientConfig, I do not understand why we are getting this issue.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值