How to stop and shutdown an entire hazelcast cluster?

hazelcast, java

Solution

You can use isClusterSafe as in below example :

public class ShutdownCluster {

public static void main(String[] args) throws Exception {

    HazelcastInstance member1 = Hazelcast.newHazelcastInstance();
    HazelcastInstance member2 = Hazelcast.newHazelcastInstance();
    HazelcastInstance member3 = Hazelcast.newHazelcastInstance();

    if(member1.getPartitionService().isClusterSafe()) {
        IExecutorService executorService = member1.getExecutorService(ShutdownCluster.class.getName());
        executorService.executeOnAllMembers(new ShutdownMember());
    }
}

private static class ShutdownMember implements Runnable, HazelcastInstanceAware, Serializable {

    private HazelcastInstance node;

    @Override
    public void run() {
        node.getLifecycleService().shutdown();
    }

    @Override
    public void setHazelcastInstance(HazelcastInstance node) {
        this.node = node;
    }
}
}

Problem

How do you stop and shutdown a hazelcast cluster? My observation from testing is that whenever a node ist stopped by HazelcastInstance#shutdown() the cluster tries to re-balance or backup the data. How can I first "stop" the cluster and then shut it down? (Or is my observation wrong?)

Original source