public static void main(String[] args) { System.setProperty("hazelcast.phone.home.enabled", "false"); HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(); HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(); IMap<Object, Object> map = instance2.getMap("test-map"); // initialize partition assignments map.size(); System.out.println("Instance-1 Cluster State: " + instance1.getCluster().getClusterState()); System.out.println("Instance-2 Cluster State: " + instance2.getCluster().getClusterState()); instance2.getCluster().changeClusterState(ClusterState.NO_MIGRATION); System.out.println("Instance-1 Cluster State: " + instance1.getCluster().getClusterState()); System.out.println("Instance-2 Cluster State: " + instance2.getCluster().getClusterState()); // start a new instance HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(); System.out.println("Instance-3 Members: " + instance3.getCluster().getMembers()); System.out.println("Instance-3 Cluster State: " + instance3.getCluster().getClusterState()); Hazelcast.shutdownAll(); } }
System.out.println("Instance-2 Cluster State: " + instance2.getCluster().getClusterState()); instance2.getCluster().changeClusterState(ClusterState.FROZEN); System.out.println("Instance-1 Cluster State: " + instance1.getCluster().getClusterState()); System.out.println("Instance-2 Cluster State: " + instance2.getCluster().getClusterState());
public static void main(String[] args) throws InterruptedException { IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5701")); IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5702")); HazelcastInstance instance1 = newHazelcastInstance(5701); HazelcastInstance instance2 = newHazelcastInstance(5702); Cache<Integer, String> cache = createCache(instance2); for (int i = 0; i < 50; i++) { cache.put(i, "value" + i); } instance2.getCluster().changeClusterState(ClusterState.PASSIVE); instance1.shutdown(); Thread.sleep(5000L); instance1 = newHazelcastInstance(5701); instance1.getCluster().changeClusterState(ClusterState.ACTIVE); for (int i = 0; i < 50; i++) { System.out.println("cache.get(" + i + ") = " + cache.get(i)); } Hazelcast.shutdownAll(); }
@Override public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception { String resultString = "SUCCESS"; try { Cluster cluster = mcs.getHazelcastInstance().getCluster(); cluster.changeClusterState(getClusterState(state)); } catch (Exception e) { ILogger logger = mcs.getHazelcastInstance().node.nodeEngine.getLogger(getClass()); logger.warning("Cluster state can not be changed: ", e); resultString = FAILURE + e.getMessage(); } JsonObject result = new JsonObject().add("result", resultString); out.add("result", result); }
instance2.getCluster().changeClusterState(ClusterState.PASSIVE); System.out.println("Instance-1 Cluster State: " + instance1.getCluster().getClusterState()); System.out.println("Instance-2 Cluster State: " + instance2.getCluster().getClusterState());
@Override public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception { String resultString = "SUCCESS"; try { Cluster cluster = mcs.getHazelcastInstance().getCluster(); cluster.changeClusterState(getClusterState(state)); } catch (Exception e) { ILogger logger = mcs.getHazelcastInstance().node.nodeEngine.getLogger(getClass()); logger.warning("Cluster state can not be changed: ", e); resultString = FAILURE + e.getMessage(); } JsonObject result = new JsonObject().add("result", resultString); out.add("result", result); }
public static void main(String[] args) { IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5701")); IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5702")); HazelcastInstance instance1 = newHazelcastInstance(5701); HazelcastInstance instance2 = newHazelcastInstance(5702); Cache<Integer, String> cache = createCache(instance1); for (int i = 0; i < 50; i++) { cache.put(i, "value" + i); } instance2.getCluster().shutdown(); // Offloading to a thread. // Because all instances should start in parallel // to be able to do hot-restart cluster verification new Thread() { public void run() { newHazelcastInstance(5701); } }.start(); instance2 = newHazelcastInstance(5702); instance2.getCluster().changeClusterState(ClusterState.ACTIVE); cache = createCache(instance2); for (int i = 0; i < 50; i++) { System.out.println("cache.get(" + i + ") = " + cache.get(i)); } Hazelcast.shutdownAll(); }