How can I check if a hazelcast cluster is alive from a java client?

u6f6o picture u6f6o · Dec 19, 2014 · Viewed 8.7k times · Source

We use hazelcast in client-server mode. The hazelcast cluster contains 2 hazelcast nodes and we have about 25 clients connected to the cluster.

What I am lookin for now is a simple check that tries to figure out if the cluster is still alive. It should be a rather cheap operation because this check will occure on every client quite frequently (once every second I could imagine).

What is the best way to do so?

Answer

pveentjer picture pveentjer · Dec 23, 2014

The simplest way would be the register a LifecycleListener to the client HazelcastInstance:

    HazelcastInstance client = HazelcastClient.newHazelcastClient();
    client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
        @Override
        public void stateChanged(LifecycleEvent event) {

        }
    })

The client uses a periodic heartbeat to detect if the cluster is still running.