Appends a task message to the buffer.
@param sourceHSId
@param task
@throws IOException If the buffer is not of the type TASK
@return how many bytes are left in this buffer for adding a new task
1512
public int appendTask(long sourceHSId, TransactionInfoBaseMessage task) throws IOException {
        Preconditions.checkState(compiledSize == 0, "buffer is already compiled");

        final int msgSerializedSize = task.getSerializedSize();
        ensureCapacity(taskHeaderSize() + msgSerializedSize);

        ByteBuffer bb = m_container.b();
        bb.putInt(msgSerializedSize);
        bb.putLong(sourceHSId);

        int limit = bb.limit();
        bb.limit(bb.position() + msgSerializedSize);
        task.flattenToBuffer(bb.slice());
        bb.limit(limit);
        bb.position(bb.position() + msgSerializedSize);

        // Don't allow any further expansion to the underlying buffer
        if (bb.position() + taskHeaderSize() > DEFAULT_BUFFER_SIZE) {
            compile();
            return 0;
        } else {
            return DEFAULT_BUFFER_SIZE - (bb.position() + taskHeaderSize());
        }
    }
672170
public static <T> CombinedDownloadTask<T> single(DownloadTask<T> task) {
		Objects.requireNonNull(task);
		return new SingleCombinedTask<T>(task);
	}
735249
public void initializeBufferMetrics(Task task) {
		final MetricGroup buffers = addGroup("buffers");
		buffers.gauge("inputQueueLength", new InputBuffersGauge(task));
		buffers.gauge("outputQueueLength", new OutputBuffersGauge(task));
		buffers.gauge("inPoolUsage", new InputBufferPoolUsageGauge(task));
		buffers.gauge("outPoolUsage", new OutputBufferPoolUsageGauge(task));
	}
807440
@GuardedBy("evictionLock")
    void runTasksInChain(Task task) {
        while (task != null) {
            Task current = task;
            task = task.getNext();
            current.setNext(null);
            current.run();
        }
    }
604825
public Future<HazeltaskTask<GROUP>> addPendingTaskAsync(HazeltaskTask<GROUP> task) {
        return pendingTask.putAsync(task.getId(), task);
    }
1019422
public static void processTask(Task task) {
    logger.finest("Processing task " + task);
    try {
      switch (task.getType()) {
        case RUN_JOB:
          runJob((RunJobTask) task);
          break;
        case HANDLE_SLOT_FILLED:
          handleSlotFilled((HandleSlotFilledTask) task);
          break;
        case FINALIZE_JOB:
          finalizeJob((FinalizeJobTask) task);
          break;
        case FAN_OUT:
          handleFanoutTaskOrAbandonTask((FanoutTask) task);
          break;
        case CANCEL_JOB:
          cancelJob((CancelJobTask) task);
          break;
        case DELETE_PIPELINE:
          DeletePipelineTask deletePipelineTask = (DeletePipelineTask) task;
          try {
            backEnd.deletePipeline(
                deletePipelineTask.getRootJobKey(), deletePipelineTask.shouldForce(), false);
          } catch (Exception e) {
            logger.log(Level.WARNING, "DeletePipeline operation failed.", e);
          }
          break;
        case HANDLE_CHILD_EXCEPTION:
          handleChildException((HandleChildExceptionTask) task);
          break;
        case DELAYED_SLOT_FILL:
          handleDelayedSlotFill((DelayedSlotFillTask) task);
          break;
        default:
          throw new IllegalArgumentException("Unrecognized task type: " + task.getType());
      }
    } catch (AbandonTaskException ate) {
      // return 200;
    }
  }
752643
@Override
    public synchronized void deleteTask(Task task) throws TaskNotFoundException {
        if (!this.inprocess.contains(task)) {
            log.error("{} not found.", task);

            throw new TaskNotFoundException("task not found:" + task.toString());
        }

        this.inprocess.remove(task);
        this.completedCount++;
        log.info("{} complete", task);
    }
439015
public void registerTask(Task task) throws IOException {
		final ResultPartition[] producedPartitions = task.getProducedPartitions();

		synchronized (lock) {
			if (isShutdown) {
				throw new IllegalStateException("NetworkEnvironment is shut down");
			}

			for (final ResultPartition partition : producedPartitions) {
				setupPartition(partition);
			}

			// Setup the buffer pool for each buffer reader
			final SingleInputGate[] inputGates = task.getAllInputGates();
			for (SingleInputGate gate : inputGates) {
				setupInputGate(gate);
			}
		}
	}
145336
public void submit(Task<? extends TaskResult> task) {

        // Increment the counter which indicates the number of results to
        // expect. This must be done BEFORE actually submitting the task for
        // execution.
        remainingTasks.incrementAndGet();

        // Increment the statistics and put the task on the correct queue.
        stats.incrementStartedTasks(task.resultType);
        executors.get(task.resultType).submit(task);

        // Make sure that the task gets added to the results queue.
        resultsQueue.add(task);
        stats.updateMemoryInfo();
    }
1147597
public void enqueue(BaseDownloadTask task) {
        final DownloadTaskAdapter downloadTaskAdapter = (DownloadTaskAdapter) task;
        downloadTaskAdapter.assembleDownloadTask();
        FileDownloadList.getImpl().addIndependentTask(downloadTaskAdapter);
        serialQueue.enqueue(downloadTaskAdapter.getDownloadTask());
        listenerManager.addAutoRemoveListenersWhenTaskEnd(downloadTaskAdapter.getId());
        listenerManager.attachListener(downloadTaskAdapter.getDownloadTask(),
                downloadTaskAdapter.getCompatListener());
    }
720526
@Override
    public void put(Set<Task> tasks) {
        String msgBody = null;
        SendMessageBatchRequestEntry msgEntry = null;
        Set<SendMessageBatchRequestEntry> msgEntries = new HashSet<>();
        for (Task task : tasks) {
            msgBody = unmarshallTask(task);
            msgEntry = new SendMessageBatchRequestEntry()
                .withMessageBody(msgBody)
                .withId(msgEntries.size() + "");  // must set unique ID for each msg in the batch request
            msgEntries.add(msgEntry);

            // Can only send batch of max 10 messages in a SQS queue request
            if (msgEntries.size() == 10) {
                this.sendBatchMessages(msgEntries);
                msgEntries.clear();  // clear the already sent messages
            }
        }

        // After for loop check to see if there are msgs in msgEntries that
        // haven't been sent yet because the size never reached 10.
        if (!msgEntries.isEmpty()) {
            this.sendBatchMessages(msgEntries);
        }
    }
356715
public synchronized void notifyTaskCompletion(long jobId, int taskId, Object result) {
    Pair<Long, Integer> id = new Pair<>(jobId, taskId);
    TaskInfo.Builder taskInfo = mUnfinishedTasks.get(id);
    taskInfo.setStatus(Status.COMPLETED);
    try {
      taskInfo.setResult(ByteString.copyFrom(SerializationUtils.serialize(result)));
    } catch (IOException e) {
      // TODO(yupeng) better error handling
      LOG.warn("Failed to serialize {} : {}", result, e.getMessage());
      LOG.debug("Exception: ", e);
    } finally {
      finishTask(id);
      LOG.info("Task {} for job {} completed.", taskId, jobId);
    }
  }
398528
public synchronized void addTask(int taskId) {
    Preconditions.checkArgument(!mTaskIdToInfo.containsKey(taskId), "");
    mTaskIdToInfo.put(taskId, new TaskInfo().setJobId(mId).setTaskId(taskId)
        .setStatus(Status.CREATED).setErrorMessage("").setResult(null));
  }
1320409
public ResponseFromManager generateUpdateExecuteTask(ParallelTask task) {

        // add to map now; as can only pass final
        ParallelTaskManager.getInstance().addTaskToInProgressMap(
                task.getTaskId(), task);
        logger.info("Added task {} to the running inprogress map...",
                task.getTaskId());

        boolean useReplacementVarMap = false;
        boolean useReplacementVarMapNodeSpecific = false;
        Map<String, StrStrMap> replacementVarMapNodeSpecific = null;
        Map<String, String> replacementVarMap = null;

        ResponseFromManager batchResponseFromManager = null;

        switch (task.getRequestReplacementType()) {
        case UNIFORM_VAR_REPLACEMENT:
            useReplacementVarMap = true;
            useReplacementVarMapNodeSpecific = false;
            replacementVarMap = task.getReplacementVarMap();
            break;
        case TARGET_HOST_SPECIFIC_VAR_REPLACEMENT:
            useReplacementVarMap = false;
            useReplacementVarMapNodeSpecific = true;
            replacementVarMapNodeSpecific = task
                    .getReplacementVarMapNodeSpecific();
            break;
        case NO_REPLACEMENT:
            useReplacementVarMap = false;
            useReplacementVarMapNodeSpecific = false;
            break;
        default:
            logger.error("error request replacement type. default as no replacement");
        }// end switch

        // generate content in nodedata
        InternalDataProvider dp = InternalDataProvider.getInstance();
        dp.genNodeDataMap(task);

        VarReplacementProvider.getInstance()
                .updateRequestWithReplacement(task, useReplacementVarMap,
                        replacementVarMap, useReplacementVarMapNodeSpecific,
                        replacementVarMapNodeSpecific);

        batchResponseFromManager = 
                sendTaskToExecutionManager(task);

        removeTaskFromInProgressMap(task.getTaskId());
        logger.info(
                "Removed task {} from the running inprogress map... "
                        + ". This task should be garbage collected if there are no other pointers.",
                task.getTaskId());
        return batchResponseFromManager;

    }
254388
public void readTask(Task task) {
        Map<String, String> props = task.getProperties();
        setAccount(props.get(ACCOUNT_PROP));
        setStoreId(props.get(STORE_ID_PROP));
        setSpaceId(props.get(SPACE_ID_PROP));
        this.attempts = task.getAttempts();
    }
967698
public void add(Task task) {
    	synchronized(LOCK) {
    		//terminated task will be selected immediately before start
    		task.setListener(this);
        
    		this.task[wi] = task;        
        
    		wi++;
    	}
    }
254545
void createTaskEntry(TaskAttemptID taskid, String taskTracker, TaskInProgress tip) {
    LOG.info("Adding task (" + tip.getAttemptType(taskid) + ") " +
      "'"  + taskid + "' to tip " +
      tip.getTIPId() + ", for tracker '" + taskTracker + "'");

    // taskid --> tracker
    taskidToTrackerMap.put(taskid, taskTracker);

    // tracker --> taskid
    Set<TaskAttemptIDWithTip> taskset = trackerToTaskMap.get(taskTracker);
    if (taskset == null) {
      taskset = new HashSet<TaskAttemptIDWithTip>();
      trackerToTaskMap.put(taskTracker, taskset);
    }
    taskset.add(new TaskAttemptIDWithTip(taskid, tip));

    // taskid --> TIP
    taskidToTIPMap.put(taskid, tip);

  }