1

我正在编写我的 hazelcast 原型代码。运行阅读器时遇到以下错误。不知道我错过了什么。

SEVERE: [host1]:5701 [dev] [3.7.3] Service with name'hz:impl:cacheService' not found!
com.hazelcast.core.HazelcastException: Service with name 'hz:impl:cacheService' not found!
    at com.hazelcast.spi.impl.NodeEngineImpl.getService(NodeEngineImpl.java:350)
    at com.hazelcast.spi.Operation.getService(Operation.java:239)
    at com.hazelcast.cache.impl.operation.PostJoinCacheOperation.run(PostJoinCacheOperation.java:44)
    at com.hazelcast.internal.cluster.impl.operations.PostJoinOperation.run(PostJoinOperation.java:93)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:181)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.run(OperationExecutorImpl.java:375)
    at com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl.run(OperationServiceImpl.java:267)
    at com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl.runOperationOnCallingThread(OperationServiceImpl.java:262)
    at com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation.runPostJoinOp(FinalizeJoinOperation.java:139)
    at com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOperation.run(FinalizeJoinOperation.java:104)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:181)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:396)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:117)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:102)
Caused by: com.hazelcast.spi.exception.ServiceNotFoundException: Service with name 'hz:impl:cacheService' not found!
    ... 14 more

这是我的代码

public class Reader {
    public static void main(String[] args) throws InterruptedException {

        Config config = new Config();
        config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(“host1”).setEnabled(true);
        config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(“host2”).setEnabled(true);
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
        IMap<String, DataDetail> mapCustomers = hz.getMap("customers");

        while (true) {
            mapCustomers.lock("Joe");
            try {
                System.out.println("Joe(R) => " + mapCustomers.get("Joe").getTimeStamp());
                Thread.sleep(2000);
            } finally {
                mapCustomers.unlock("Joe");
            }
        }
    }
}


public class Writer {
    public static void main(String[] args) throws InterruptedException {
        Config config = new Config();
         config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(“host1”).setEnabled(true);
        config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(“host2”).setEnabled(true);
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
        HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
        IMap<String, DataDetail> mapCustomers = hz.getMap("customers");
        DataDetail od = new DataDetail ();
        od.setDataId(“X1”);
        od.setTimeStamp(0);
        int i = 1;
        while (true) {
            mapCustomers.lock("Joe");
            try {
                mapCustomers.put("Joe", od);
                od.setTimeStamp(od.getTimeStamp() + 1);
                Thread.sleep(2000);
                DataDetail localOd =  mapCustomers.get("Joe");
                System.out.println("Joe(W) => " + localOd.getTimeStamp());
            } finally {
                mapCustomers.unlock("Joe");
            }
        }

    }
}


public class DataDetail  implements DataSerializable {
    String dataId;
    Integer timeStamp;

    public DataDetail() {
    }

    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    public String getDataId() {
        return this.dataId;
    }

    public void setTimeStamp(Integer timeStamp) {
        this.timeStamp = timeStamp;
    }

    public Integer getTimeStamp() {
        return this.timeStamp;
    }

    public void writeData( ObjectDataOutput out ) throws IOException {
        out.writeUTF(dataId);
        out.writeInt(timeStamp);
    }

    public void readData( ObjectDataInput in ) throws IOException {
        dataId = in.readUTF();
        timeStamp = in.readInt();
    }
}
4

2 回答 2

5

您必须将 JCache API 类 (JAR) 添加到类路径中,否则 CacheService 不会启动。

于 2016-11-22T22:21:07.293 回答
2

如果要使用 jcache 连接 Hazelcast 服务器,则必须cache-api-1.1.0.jarlib目录中添加。之后,您必须在导出时显示 jcache api CLASSPATHjar start.sh

当 中的前一个export CLASSPATH表达式start.sh

export CLASSPATH="$HAZELCAST_HOME/lib/hazelcast-all-3.9.3.jar"

编辑后:

export CLASSPATH="$HAZELCAST_HOME/lib/hazelcast-all-3.9.3.jar:$HAZELCAST_HOME/lib/cache-api-1.1.0.jar:$CLASSPATH/*" 
于 2018-09-10T14:12:21.907 回答