private void doWork() throws InvalidStateTransitionException, AmbariException {
    List<Host> allHosts = clusters.getHosts();
    long now = System.currentTimeMillis();
    for (Host hostObj : allHosts) {
      if (hostObj.getState() == HostState.HEARTBEAT_LOST) {
        //do not check if host already known be lost
        continue;
      }
      Long hostId = hostObj.getHostId();
      HostState hostState = hostObj.getState();

      long lastHeartbeat = 0;
      try {
        lastHeartbeat = clusters.getHostById(hostId).getLastHeartbeatTime();
      } catch (AmbariException e) {
        LOG.warn("Exception in getting host object; Is it fatal?", e);
      }
      if (lastHeartbeat + 2 * threadWakeupInterval < now) {
        handleHeartbeatLost(hostId);
      }
      if (hostState == HostState.WAITING_FOR_HOST_STATUS_UPDATES) {
        long timeSpentInState = hostObj.getTimeInState();
        if (timeSpentInState + 5 * threadWakeupInterval < now) {
          //Go back to init, the agent will be asked to register again in the next heartbeat
          LOG.warn("timeSpentInState + 5*threadWakeupInterval < now, Go back to init");
          hostObj.setState(HostState.INIT);
        }
      }
    }
  }
Monitors the node state and heartbeats.
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java