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