@Override public void run() { final ClusterServiceImpl clusterService = getService(); final ILogger logger = getLogger(); final ClusterState clusterState = clusterService.getClusterState(); if (clusterState == ClusterState.PASSIVE) { final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine(); if (nodeEngine.isRunning()) { logger.info( "Shutting down node in cluster passive state. Requested by: " + getCallerAddress()); new Thread( new Runnable() { @Override public void run() { final Node node = nodeEngine.getNode(); node.hazelcastInstance.getLifecycleService().shutdown(); } }, nodeEngine.getHazelcastThreadGroup().getThreadNamePrefix(".clusterShutdown")) .start(); } else { logger.info("Node is already shutting down. NodeState: " + nodeEngine.getNode().getState()); } } else { logger.severe( "Can not shut down node because cluster is in " + clusterState + " state. Requested by: " + getCallerAddress()); } }
@Override public void shutdown() { for (Address address : nodes.keySet()) { if (address.equals(node.getThisAddress())) { continue; } final NodeEngineImpl nodeEngine = nodes.get(address); if (nodeEngine != null && nodeEngine.isRunning()) { nodeEngine .getExecutionService() .execute( ExecutionService.SYSTEM_EXECUTOR, new Runnable() { public void run() { ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService(); clusterService.removeAddress(node.getThisAddress()); } }); } } for (MockConnection connection : mapConnections.values()) { connection.close(); } }
public void doJoin() { NodeEngineImpl nodeEngine = null; synchronized (joinerLock) { for (Address address : joinAddresses) { NodeEngineImpl ne = nodes.get(address); if (ne != null && ne.isRunning() && ne.getNode().joined()) { nodeEngine = ne; break; } } Address master = null; if (nodeEngine != null) { if (nodeEngine.getNode().isMaster()) { master = nodeEngine.getThisAddress(); } else { master = nodeEngine.getMasterAddress(); } } if (master == null) { master = node.getThisAddress(); } node.setMasterAddress(master); if (node.getMasterAddress().equals(node.getThisAddress())) { node.setJoined(); node.setAsMaster(); } else { final ClusterJoinManager clusterJoinManager = node.clusterService.getClusterJoinManager(); for (int i = 0; !node.joined() && node.isRunning() && i < 2000; i++) { try { clusterJoinManager.sendJoinRequest(node.getMasterAddress(), true); Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); break; } } if (!node.joined()) { logger.severe( "Node[" + node.getThisAddress() + "] should have been joined to " + node.getMasterAddress()); node.shutdown(true); } } } }
@Override public Connection getOrConnect(Address address) { MockConnection conn = mapConnections.get(address); if (conn == null || !conn.isAlive()) { NodeEngineImpl nodeEngine = nodes.get(address); if (nodeEngine != null && nodeEngine.isRunning()) { MockConnection thisConnection = new MockConnection(address, node.getThisAddress(), node.nodeEngine); conn = new MockConnection(node.getThisAddress(), address, nodeEngine); conn.localConnection = thisConnection; thisConnection.localConnection = conn; mapConnections.put(address, conn); logger.info("Created connection to endpoint: " + address + ", connection: " + conn); } } return conn; }