Hi,
It is an internal method and subjected to change, I won't recommend to use it.
For your use case, I recommend LifecycleService. From there, you can check if your client is connected the cluster or not via a listener.
Note that, this is still not answering if cluster is alive or not. It still be the case that cluster is there but your connection is broken for any other reason.
CLIENT_CONNECTED and CLIENT_DISCONNECTED is enough for your use case. Other events will also be thrown for the client, but in your particular case, you can ignore them.
HazelcastInstance client = HazelcastClient.newHazelcastClient();
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
//handle CLIENT_CONNECTED , CLIENT_DISCONNECTED
}
});
Alternatively we have a utility implementation to check the current state as follows:
ClientConfig config = new ClientConfig();
ClientStateListener clientStateListener = new ClientStateListener(config);
HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
System.out.println(clientStateListener.isConnected());
Also note that following method can return true even if client is not connected. Client will try to connect back to cluster for some time(according to user configuration), and eventually be shutdown. This return false only when client is shutdown.
HazelcastInstance hzInstance = HazelcastClient.newHazelcastClient();
hzInstance.getLifecycleService().isRunning()
Regards