名为' hz:impl:cacheService'的服务未找到

时间:2016-11-22 21:30:20

标签: hazelcast jcache

我正在编写我的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();
    }
}

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:2)

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

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/*"