com.hazelcast.core.Cluster.shutdown()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中com.hazelcast.core.Cluster.shutdown()方法的一些代码示例,展示了Cluster.shutdown()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.shutdown()方法的具体详情如下:
包路径:com.hazelcast.core.Cluster
类名称:Cluster
方法名:shutdown

Cluster.shutdown介绍

[英]Changes state of the cluster to the ClusterState#PASSIVE transactionally, then triggers the shutdown process on each node. Transaction will be TWO_PHASEand will have 1 durability by default. If you want to override transaction options, use #shutdown(TransactionOptions).

If the cluster is already in ClusterState#PASSIVE, shutdown process begins immediately. All the node join / leave rules described in ClusterState#PASSIVE state also applies here.

Any node can start the shutdown process. A shutdown command is sent to other nodes periodically until either all other nodes leave the cluster or a configurable timeout occurs (see GroupProperty#CLUSTER_SHUTDOWN_TIMEOUT_SECONDS). If some of the nodes do not shutdown before the timeout duration, shutdown can be also invoked on them.
[中]以事务方式将集群的状态更改为ClusterState#被动,然后在每个节点上触发关闭进程。事务将是两个阶段,默认情况下将有1个持久性。如果要覆盖事务选项,请使用#shutdown(TransactionOptions)。
如果集群已经处于ClusterState#被动状态,则关闭过程立即开始。ClusterState#被动状态中描述的所有节点加入/离开规则也适用于此处。
任何节点都可以启动关闭过程。定期向其他节点发送关机命令,直到所有其他节点离开集群或出现可配置超时(请参阅GroupProperty#cluster _shutdown _timeout _SECONDS)。如果某些节点在超时持续时间之前未关闭,也可以对其调用shutdown。

代码示例

代码示例来源:origin: hazelcast/hazelcast-code-samples

  1. public static void main(String[] args) {
  2. final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
  3. final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
  4. System.out.println("Instance-1 members: " + instance1.getCluster().getMembers());
  5. System.out.println("Instance-2 members: " + instance2.getCluster().getMembers());
  6. // shutdown cluster
  7. instance2.getCluster().shutdown();
  8. System.out.println("Instance-1: Is running?: " + instance1.getLifecycleService().isRunning());
  9. System.out.println("Instance-2: Is running?: " + instance2.getLifecycleService().isRunning());
  10. }
  11. }

代码示例来源:origin: hazelcast/hazelcast-jet

  1. @Override
  2. public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
  3. String resultString = "SUCCESS";
  4. try {
  5. mcs.getHazelcastInstance().getCluster().shutdown();
  6. } catch (Exception e) {
  7. ILogger logger = mcs.getHazelcastInstance().node.nodeEngine.getLogger(getClass());
  8. logger.warning("Cluster can not be shutdown: ", e);
  9. resultString = e.getMessage();
  10. }
  11. JsonObject result = new JsonObject().add("result", resultString);
  12. out.add("result", result);
  13. }

代码示例来源:origin: com.hazelcast/hazelcast-all

  1. @Override
  2. public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
  3. String resultString = "SUCCESS";
  4. try {
  5. mcs.getHazelcastInstance().getCluster().shutdown();
  6. } catch (Exception e) {
  7. ILogger logger = mcs.getHazelcastInstance().node.nodeEngine.getLogger(getClass());
  8. logger.warning("Cluster can not be shutdown: ", e);
  9. resultString = e.getMessage();
  10. }
  11. JsonObject result = new JsonObject().add("result", resultString);
  12. out.add("result", result);
  13. }

代码示例来源:origin: hazelcast/hazelcast-code-samples

  1. public static void main(String[] args) {
  2. IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5701"));
  3. IOUtil.delete(new File(HOT_RESTART_ROOT_DIR + "5702"));
  4. HazelcastInstance instance1 = newHazelcastInstance(5701);
  5. HazelcastInstance instance2 = newHazelcastInstance(5702);
  6. Cache<Integer, String> cache = createCache(instance1);
  7. for (int i = 0; i < 50; i++) {
  8. cache.put(i, "value" + i);
  9. }
  10. instance2.getCluster().shutdown();
  11. // Offloading to a thread.
  12. // Because all instances should start in parallel
  13. // to be able to do hot-restart cluster verification
  14. new Thread() {
  15. public void run() {
  16. newHazelcastInstance(5701);
  17. }
  18. }.start();
  19. instance2 = newHazelcastInstance(5702);
  20. instance2.getCluster().changeClusterState(ClusterState.ACTIVE);
  21. cache = createCache(instance2);
  22. for (int i = 0; i < 50; i++) {
  23. System.out.println("cache.get(" + i + ") = " + cache.get(i));
  24. }
  25. Hazelcast.shutdownAll();
  26. }

相关文章