Get the number of currently available slots on this tasktracker for the
given type of the task.
@param taskType the {@link TaskType} to check for number of available slots
@return the number of currently available slots for the given
<code>taskType</code>
499617
public int getAvailableSlots(TaskType taskType) {
    int availableSlots = 0;
    if (taskType == TaskType.MAP) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(trackerName + " getAvailSlots:" +
        		     " max(m)=" + status.getMaxMapSlots() + 
        		     " occupied(m)=" + status.countOccupiedMapSlots());
      }
      availableSlots = status.getAvailableMapSlots();
    } else {
      if (LOG.isDebugEnabled()) {
        LOG.debug(trackerName + " getAvailSlots:" +
                  " max(r)=" + status.getMaxReduceSlots() + 
                  " occupied(r)=" + status.countOccupiedReduceSlots());
      }
      availableSlots = status.getAvailableReduceSlots();
    }
    return availableSlots;
  }
1307076
public static void logInvalidTaskType(final Logger logger,
			final TaskTypes type)
	{

		logger.logMessage(Level.INFO, "Invalid TaskType: " + type);
	}
987236
@Service
    public Task poll(String taskType, String workerId, String domain) {
        LOGGER.debug("Task being polled: /tasks/poll/{}?{}&{}", taskType, workerId, domain);
        Task task = executionService.getLastPollTask(taskType, workerId, domain);
        if (task != null) {
            LOGGER.debug("The Task {} being returned for /tasks/poll/{}?{}&{}", task, taskType, workerId, domain);
        }
        Monitors.recordTaskPollCount(taskType, domain, 1);
        return task;
    }
452510
public int getMaxSlots(TaskTrackerStatus status, TaskType type) {
    return (type == TaskType.MAP) ? status.getMaxMapSlots() :
        status.getMaxReduceSlots();
  }
1046040
@Service
    public Map<String, Integer> getTaskQueueSizes(List<String> taskTypes) {
        return executionService.getTaskQueueSizes(taskTypes);
    }
642072
private String getConfigurationType(final CCTask task) {
    final String outputType = task.getOuttype();
    String targtype = "2"; // Win32 (x86) Dynamic-Link Library";
    if ("executable".equals(outputType)) {
      targtype = "1"; // "Win32 (x86) Console Application";
    } else if ("static".equals(outputType)) {
      targtype = "4"; // "Win32 (x86) Static Library";
    }
    return targtype;
  }
823146
private String extractAndConvertTaskType(Task task)
   {
      String activityType = (String) task.getCachedValue(m_activityTypeField);
      if (activityType == null)
      {
         activityType = "Resource Dependent";
      }
      else
      {
         if (ACTIVITY_TYPE_MAP.containsKey(activityType))
         {
            activityType = ACTIVITY_TYPE_MAP.get(activityType);
         }
      }
      return activityType;
   }
555585
private boolean atSpeculativeCap(TaskType type) {
     float numTasks = (type == TaskType.MAP) ?
       (float)(runningMapTasks - speculativeMapTasks) :
       (float)(runningReduceTasks - speculativeReduceTasks);
     if (numTasks == 0){
       return true; // avoid divide by zero
     }
     int speculativeTaskCount = type == TaskType.MAP ? speculativeMapTasks
         : speculativeReduceTasks;
     int totalSpeculativeTaskCount = type == TaskType.MAP ?
         totalSpeculativeMapTasks.get() : totalSpeculativeReduceTasks.get();
     //return true if totalSpecTask < max(10, 0.01 * total-slots,
     //                                   0.1 * total-running-tasks)

     if (speculativeTaskCount < MIN_SPEC_CAP) {
       return false; // at least one slow tracker's worth of slots(default=10)
     }
     ClusterStatus c = jobtracker.getClusterStatus(false);
     int numSlots = (type == TaskType.MAP ? c.getMaxMapTasks() : c.getMaxReduceTasks());
     if (speculativeTaskCount < numSlots * MIN_SLOTS_CAP) {
       return false;
     }
     // Check if the total CAP has been reached
     if (totalSpeculativeTaskCount >= numSlots * TOTAL_SPECULATIVECAP) {
       return true;
     }
     boolean atCap = (((speculativeTaskCount)/numTasks) >= speculativeCap);
     if (LOG.isDebugEnabled()) {
       LOG.debug("SpeculativeCap is "+speculativeCap+", specTasks/numTasks is " +
           ((speculativeTaskCount)/numTasks)+
           ", so atSpecCap() is returning "+atCap);
     }
     return atCap;
   }
989933
@Service
    public String requeuePendingTask(String taskType) {
        return String.valueOf(executionService.requeuePendingTasks(taskType));
    }
1310173
public static int getFieldID(FieldType type)
   {
      int result;
      switch (type.getFieldTypeClass())
      {
         case TASK:
         {
            result = MPPTaskField.TASK_FIELD_BASE | MPPTaskField.getID((TaskField) type);
            break;
         }

         case RESOURCE:
         {
            result = MPPResourceField.RESOURCE_FIELD_BASE | MPPResourceField.getID((ResourceField) type);
            break;
         }

         case ASSIGNMENT:
         {
            result = MPPAssignmentField.ASSIGNMENT_FIELD_BASE | MPPAssignmentField.getID((AssignmentField) type);
            break;
         }

         default:
         {
            result = -1;
         }

      }
      return result;
   }
1031537
@Service
    public List<Task> getListOfPendingTask(String taskType, Integer start, Integer count) {
        List<Task> tasks = executionService.getPendingTasksForTaskType(taskType);
        int total = start + count;
        total = (tasks.size() > total) ? total : tasks.size();
        if (start > tasks.size()) start = tasks.size();
        return tasks.subList(start, total);
    }
218186
private function getFactoryForType($taskType)
    {
        foreach ($this->factories as $factory) {
            if ($factory->isTypeSupported($taskType)) {
                return $factory;
            }
        }

        return null;
    }
380520
boolean isStarvedForMinShare(JobInfo info, TaskType taskType) {
    float starvingThreshold = (float) (minTasks(info, taskType) * 0.9);
    return runningTasks(info, taskType) < starvingThreshold;
  }
1266147
public void reserveSlots(TaskType taskType, JobInProgress job, int numSlots) {
    JobID jobId = job.getJobID();
    if (taskType == TaskType.MAP) {
      if (jobForFallowMapSlot != null && 
          !jobForFallowMapSlot.getJobID().equals(jobId)) {
        throw new RuntimeException(trackerName + " already has " + 
                                   "slots reserved for " + 
                                   jobForFallowMapSlot + "; being"  +
                                   " asked to reserve " + numSlots + " for " + 
                                   jobId);
      }

      jobForFallowMapSlot = job;
    } else if (taskType == TaskType.REDUCE){
      if (jobForFallowReduceSlot != null && 
          !jobForFallowReduceSlot.getJobID().equals(jobId)) {
        throw new RuntimeException(trackerName + " already has " + 
                                   "slots reserved for " + 
                                   jobForFallowReduceSlot + "; being"  +
                                   " asked to reserve " + numSlots + " for " + 
                                   jobId);
      }

      jobForFallowReduceSlot = job;
    }
    
    job.reserveTaskTracker(this, taskType, numSlots);
    LOG.info(trackerName + ": Reserved " + numSlots + " " + taskType + 
             " slots for " + jobId);
  }
242823
protected int getCount(int type, Collection<ConnectionListener> listeners)
   {
      int count = 0;

      for (ConnectionListener cl : listeners)
      {
         if (cl.getState() == type)
            count++;
      }

      return count;
   }
727516
public int getThisTaskIndex() {
        List<Integer> tasks = new ArrayList<>(getComponentTasks(getThisComponentId()));
        Collections.sort(tasks);
        for (int i = 0; i < tasks.size(); i++) {
            if (tasks.get(i) == getThisTaskId()) {
                return i;
            }
        }
        throw new RuntimeException("Fatal: could not find this task id in this component");
    }
628738
public int countReduceTasks() {
    int reduceCount = 0;
    for (Iterator<TaskStatus> it = taskReports.iterator(); it.hasNext();) {
      TaskStatus ts = (TaskStatus) it.next();
      if ((!ts.getIsMap()) && isTaskRunning(ts)) {
        reduceCount++;
      }
    }
    return reduceCount;
  }