Adds some work to the queue and the underlying task storage facility with a generic "running" status.

@param task task to add

@return true

@throws EntryExistsException if the task already exists
963373
public boolean add(final Task task) throws EntryExistsException
  {
    if (taskStorage.getTask(task.getId()).isPresent()) {
      throw new EntryExistsException(StringUtils.format("Task %s is already exists", task.getId()));
    }

    giant.lock();

    try {
      Preconditions.checkState(active, "Queue is not active!");
      Preconditions.checkNotNull(task, "task");
      Preconditions.checkState(tasks.size() < config.getMaxSize(), "Too many tasks (max = %,d)", config.getMaxSize());

      // If this throws with any sort of exception, including TaskExistsException, we don't want to
      // insert the task into our queue. So don't catch it.
      taskStorage.insert(task, TaskStatus.running(task.getId()));
      addTaskInternal(task);
      managementMayBeNecessary.signalAll();
      return true;
    }
    finally {
      giant.unlock();
    }
  }
26744
@Override
    synchronized void offer(TransactionTask task)
    {
        Iv2Trace.logTransactionTaskQueueOffer(task);
        m_backlog.addLast(task);
        taskQueueOffer();
    }
533164
@Override
    public void requeue(Task task) {
        int attempts = task.getAttempts();
        task.incrementAttempts();
        try {
            deleteTask(task);
        } catch (TaskNotFoundException e) {
            log.error("unable to delete " + task + " ignoring - requeuing anyway");
        }

        put(task);
        log.warn("requeued {} after {} failed attempts.", task, attempts);

    }
248937
public Future<?> submit(Task task) {
    LOG.info(String.format("Submitting task %s", task.getTaskId()));
    return this.taskExecutor.submit(new TrackingTask(task));
  }
921145
public <T extends Runnable> T executeAsync(T runnable) {
		synchronized (this.tasks) {
			this.tasks.add(runnable);
			// Notify that a task has been added
			this.tasks.notifyAll();

			if (this.tasks.size() == 1) {
				this.onTaskBecameNotEmpty();
			}

			this.onTaskAdded();
		}
		return runnable;
	}
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());
    }
1147743
void reExecutePeriodic(RunnableScheduledFuture<?> task) {
        if (canRunInCurrentRunState(true)) {
            super.getQueue().add(task);
            if (!canRunInCurrentRunState(true) && remove(task))
                task.cancel(false);
            else
                ensurePrestart();
        }
    }
22709
public synchronized void execute( AsyncTask task ) throws JMSException
	{		
		AsyncTaskProcessorThread thread = threadPool.borrow(); // Dispatch using new borrowed thread
		if (thread != null)
		{
			thread.setTask(task);
			thread.execute();
		}
		else
		{
			// All threads are busy ...
			
			if (task.isMergeable())
			{
				if (!taskSet.add(task))
					return; // Already queued
			}
			
			// Enqueue task
			taskQueue.add(task);
		}
	}
1178580
@Override
    String execute(final Task task) {
        if (Config.DEBUG) {
            Log.v(TAG, "execute() task=" + task);
        }
        checkExecutor();
        assert task != null;
        final ITaskRunnable runnable = TaskFactory.createRunnable(task);
        final String group = task.getGroup();
        final String name = task.getName();
        addToRunnableMap(name, runnable);
        addToGroupMap(name, group);

        runnable.setFuture(mExecutor.submit(runnable));
        return name;
    }
960867
public final void restartTask (final ITask task) throws ExecutionException {

        try {
            if (task != null) {
                if (task instanceof IOTask) {
                    executor.submit((IOTask) task);
                } else {
                    task.call();
                }
                taskBalancer.releaseConnection(outstandingTasks.get(task));
                outstandingTasks.remove(task);
            }
            LOGGER.debug("Restarted a Task out of the outstandingTasks Queue");
        } catch (Exception e) {
            throw new ExecutionException(e);
        }
    }
15677
public final void addPrerequisite(final Task<?> task) {
        Logger.v("Task[%s] add prerequisite: Task[%s]", this, task);

        synchronized (mTaskLock) {
            if (!mPrerequisites.contains(task)) {
                mPrerequisites.add(task);
                task.addDependency(this);
            }
        }
    }
703900
public void trackTask(final ServiceTaskBase<?> task) {

        LOGGER.trace("track a Task");

        this.serviceTasks.add(task);

        task.setOnCancelled(this.workerHandler);
        task.setOnSucceeded(this.workerHandler);
        task.setOnFailed(this.workerHandler);
    }
1093851
public boolean scheduleExecutorTask(Runnable task)
  {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    synchronized (_executorLock) {
      _executorTaskCount++;

      if (_executorTaskCount <= _executorTaskMax || _executorTaskMax < 0) {
        boolean isPriority = false;
        boolean isQueue = true;
        boolean isWake = true;

        return scheduleImpl(task, loader, MAX_EXPIRE, isPriority, isQueue, isWake);
      }
      else {
        ExecutorQueueItem item = new ExecutorQueueItem(task, loader);

        if (_executorQueueTail != null)
          _executorQueueTail._next = item;
        else
          _executorQueueHead = item;

        _executorQueueTail = item;

        return false;
      }
    }
  }
473297
public function add(AbstractTask $task)
    {
        $task->setRuntime($this->runtime);
        $this->registeredTasks[$task->getName()] = $task;
    }
470767
@GuardedBy("evictionLock")
    void runTasks(Task[] tasks, int maxTaskIndex) {
        for (int i = 0; i <= maxTaskIndex; i++) {
            runTasksInChain(tasks[i]);
        }
    }
934493
def _append_task(t):
    
    task_queue = _get_task_queue()
    if t not in task_queue:
        log.debug('Appended new task to the queue: %s.', t)
        task_queue.append(t)
    else:
        log.debug('Did not append duplicate task to the queue: %s.', t)
    return None
1230503
public Task addRunningTask(TaskAttemptID taskid, 
                             String taskTracker,
                             boolean taskCleanup) {
    // 1 slot is enough for taskCleanup task
    int numSlotsNeeded = taskCleanup ? 1 : numSlotsRequired;
    // create the task
    Task t = null;
    if (isMapTask()) {
      LOG.debug("attempt " + numTaskFailures + " sending skippedRecords "
          + failedRanges.getIndicesCount());
      String splitClass = null;
      BytesWritable split;
      if (!jobSetup && !jobCleanup) {
        splitClass = rawSplit.getClassName();
        split = rawSplit.getBytes();
      } else {
        split = new BytesWritable();
      }
      t = new MapTask(jobFile, taskid, partition, splitClass, split, 
                      numSlotsNeeded, job.getUser());
    } else {
      t = new ReduceTask(jobFile, taskid, partition, numMaps, 
                         numSlotsNeeded, job.getUser());
    }
    if (jobCleanup) {
      t.setJobCleanupTask();
    }
    if (jobSetup) {
      t.setJobSetupTask();
    }
    if (taskCleanup) {
      t.setTaskCleanupTask();
      t.setState(taskStatuses.get(taskid).getRunState());
      cleanupTasks.put(taskid, taskTracker);
    }
    t.setConf(conf);
    LOG.debug("Launching task with skipRanges:"+failedRanges.getSkipRanges());
    t.setSkipRanges(failedRanges.getSkipRanges());
    t.setSkipping(skipping);
    if(failedRanges.isTestAttempt()) {
      t.setWriteSkipRecs(false);
    }

    if (activeTasks.size() >= 1) {
    	speculativeTaskId = taskid;
    } else {
    	speculativeTaskId = null;
    }
    activeTasks.put(taskid, taskTracker);
    tasks.add(taskid);

    // Ask JobTracker to note that the task exists
    // jobtracker.createTaskEntry(taskid, taskTracker, this);

    /*
      // code to find call paths to createTaskEntry
      StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
      boolean found = false;
      for (StackTraceElement s: stackTraceElements) {
      if (s.getMethodName().indexOf("heartbeat") != -1 ||
      s.getMethodName().indexOf("findTask") != -1 ||
      s.getMethodName().indexOf("createAndAddAttempt") != -1 ||
      s.getMethodName().indexOf("processTaskAttempt") != -1) {
      found = true;
      break;
      }
      }

      if (!found) {
      RuntimeException e = new RuntimeException ("calling addRunningTask from outside heartbeat");
      LOG.info(StringUtils.stringifyException(e));
      throw (e);
      }
    */

    // check and set the first attempt
    if (firstTaskId == null) {
      firstTaskId = taskid;
    }
    return t;
  }