Source:
<code>private Thread initAndStartHeartbeat(final StormAMRMClient client, final BlockingQueue<Container> launcherQueue, final int heartBeatIntervalMs) { Thread thread = new Thread() { @Override public void run() { try { while (client.getServiceState() == Service.STATE.STARTED && !Thread.currentThread().isInterrupted()) { Thread.sleep(heartBeatIntervalMs); AllocateResponse allocResponse = client.allocate(0.5f); if (allocResponse.getAMResponse().getReboot()) { LOG.info("Got Reboot from the RM"); _handler.stop(); System.exit(0); } List<Container> allocatedContainers = allocResponse.getAMResponse().getAllocatedContainers(); if (allocatedContainers.size() > 0) { LOG.info("HB: Received allocated containers (" + allocatedContainers.size() + ")"); client.addAllocatedContainers(allocatedContainers); if (client.supervisorsAreToRun()) { LOG.info("HB: Supervisors are to run, so queueing (" + allocatedContainers.size() + ") containers..."); launcherQueue.addAll(allocatedContainers); } else { LOG.info("HB: Supervisors are to stop, so releasing all containers..."); client.stopAllSupervisors(); } } List<ContainerStatus> completedContainers = allocResponse.getAMResponse().getCompletedContainersStatuses(); if (completedContainers.size() > 0 && client.supervisorsAreToRun()) { LOG.info("HB: Containers completed (" + completedContainers.size() + "), so releasing them."); <START> client.stopAllSupervisors(); <END> } } } catch (Throwable t) { LOG.error("Unhandled error in AM: ", t); _handler.stop(); System.exit(1); } } }; thread.start(); return thread; }</code><technical_language>this time a supervisor crashes for reason other supervisors stopped? I this is behavior want. If startAllSupervisors release finished containers appropriately, need add in else will</technical_language>

Target:
private Thread initAndStartHeartbeat(final StormAMRMClient client, final BlockingQueue<Container> launcherQueue, final int heartBeatIntervalMs) { Thread thread = new Thread() { @Override public void run() { try { while (client.getServiceState() == Service.STATE.STARTED && !Thread.currentThread().isInterrupted()) { Thread.sleep(heartBeatIntervalMs); AllocateResponse allocResponse = client.allocate(0.5f); if (allocResponse.getAMResponse().getReboot()) { LOG.info("Got Reboot from the RM"); _handler.stop(); System.exit(0); } List<Container> allocatedContainers = allocResponse.getAMResponse().getAllocatedContainers(); if (allocatedContainers.size() > 0) { LOG.info("HB: Received allocated containers (" + allocatedContainers.size() + ")"); client.addAllocatedContainers(allocatedContainers); if (client.supervisorsAreToRun()) { LOG.info("HB: Supervisors are to run, so queueing (" + allocatedContainers.size() + ") containers..."); launcherQueue.addAll(allocatedContainers); } else { LOG.info("HB: Supervisors are to stop, so releasing all containers..."); client.stopAllSupervisors(); } } List<ContainerStatus> completedContainers = allocResponse.getAMResponse().getCompletedContainersStatuses(); if (completedContainers.size() > 0 && client.supervisorsAreToRun()) { LOG.info("HB: Containers completed (" + completedContainers.size() + "), so releasing them."); client.startAllSupervisors(); } } } catch (Throwable t) { LOG.error("Unhandled error in AM: ", t); _handler.stop(); System.exit(1); } } }; thread.start(); return thread; }