Reputation: 4572
I am write my hazelcast prototype code. I encountered the following error when running the reader. Not sure what did I miss.
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
Here is my code
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();
}
}
Upvotes: 1
Views: 1896
Reputation: 45
If you want to use jcache to connect to Hazelcast servers, you have to add cache-api-1.1.0.jar
in the lib
directory. After that, you have to show the jcache api jar when exporting CLASSPATH
in the start.sh
.
When the former export CLASSPATH
expression in start.sh
:
export CLASSPATH="$HAZELCAST_HOME/lib/hazelcast-all-3.9.3.jar"
after the edit:
export CLASSPATH="$HAZELCAST_HOME/lib/hazelcast-all-3.9.3.jar:$HAZELCAST_HOME/lib/cache-api-1.1.0.jar:$CLASSPATH/*"
Upvotes: 2
Reputation: 6104
You have to add the JCache API classes (JAR) to your classpath, otherwise the CacheService is not started.
Upvotes: 5