| 764 | } |
| 765 | |
| 766 | public void restartNet() throws Exception { |
| 767 | logger.debug("Raft.Net {} Restart ...", raftName); |
| 768 | try { |
| 769 | if (raft != null) |
| 770 | raft.getServer().stop(); |
| 771 | if (raft != null) { |
| 772 | for (int i = 0; ; ) { |
| 773 | try { |
| 774 | raft.getServer().start(); |
| 775 | break; |
| 776 | } catch (Exception e) { |
| 777 | if (!(e instanceof BindException) && !(e.getCause() instanceof BindException) || ++i > 30) |
| 778 | throw e; |
| 779 | //noinspection BusyWait |
| 780 | Thread.sleep(100); // 稍等一小会,上个ServerSocket还没真正关闭 |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } catch (Exception e) { |
| 785 | logger.error("RestartNet exception", e); |
| 786 | throw e; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | public void stopRaft() throws Exception { |
| 791 | lock(); |