Hello people and good day, i'm trying to build an interface so, the interface it will be an external client that i need to get access from my linux console and execute the commands, this is the interface
public class HazelcastCacheImpl implements HazelcastCache {
private HazelcastInstance clientInstance;
public Boolean initCache() {
HazelcastInstance status = Hazelcast.newHazelcastInstance();
if (status.getLifecycleService().isRunning()) {
return true;
} else {
System.out.println("There was a problem trying to run the cluster node");
return false;
}
}
public Boolean getEntry(String CacheName, String claveReq) {
IMap<String, ResponseSerializable> map = clientInstance.getMap(CacheName);
// Predicate<String,ResponseSerializable> query = Predicates.equal("claveReq", claveReq);
if (!map.isEmpty()) {
map.values(query);
} else {
return false;
}
return false;
}
public Boolean putEntry(String CacheName, Object key, Object value) {
KeySerializable keyAux = null;
ResponseSerializable responseAux = null;
IMap<String, ResponseSerializable> map = clientInstance.getMap(CacheName);
if (key.getClass().equals(KeySerializable.class) && value.getClass().equals(ResponseSerializable.class)) {
keyAux = (KeySerializable) key;
responseAux = (ResponseSerializable) value;
String keyOR = keyAux.getClaveReq();
map.put(keyOR, responseAux);
return true;
} else {
System.out.println("the map doesn't exist or wrong data format");
return false;
}
}
public int removeEntry(String CacheName, String claveReq, int id_interno_pe, String cod_nrbe_en, int num_sec_ac) {
IMap<String, ResponseSerializable> map = clientInstance.getMap(CacheName);
Predicate<String, ResponseSerializable> query = Predicates.equal("claveReq", claveReq);
if (!map.isEmpty()) {
map.values(query);
map.remove(claveReq);
return 0;
} else {
return 0;
}
}
public Boolean removeCache(String CacheName) {
IMap<String, ResponseSerializable> map = clientInstance.getMap(CacheName);
if (!map.isEmpty()) {
map.destroy();
System.out.println("Cache removed");
return true;
} else {
System.out.println("cannot be deleted because the map doesn't exist, try with the right map name");
return false;
}
}
}
so... what i need the method "initCache" to do is... connect to an external cluster so it will be a HazelcastClient then i need to check somethings that i dont know how to do it, if the client is alive/running, if the client exist well delete the corrupt client and run a new one, if there is no client then run
and the main problem it's about connection lost or connection proble, i dont know how to try a new connection if the connection is lost
¿Any hint friends?
Best, Luis.