Wraps an iterable so that when iterated, a progress bar is shown to track the traversal progress.
<p>
Sample usage: {@code
for (T x : ProgressBar.wrap(collection, "Traversal")) { ... }
}
</p>
@param ts Underlying iterable
@param task Task name
765464
public static <T> Iterable<T> wrap(Iterable<T> ts, String task) {
        return new ProgressBarWrappedIterable<>(ts, task);
    }
958673
@SuppressWarnings("deprecation")
  public void failedTask(
    TaskInProgress tip,
    TaskAttemptID taskid,
    String reason,
    TaskStatus.Phase phase,
    boolean isFailed,
    String trackerName,
    TaskTrackerInfo ttStatus) {
    TaskStatus.State state =
      isFailed ? TaskStatus.State.FAILED: TaskStatus.State.KILLED;
    TaskStatus status = TaskStatus.createTaskStatus(tip.isMapTask(),
                                                    taskid,
                                                    0.0f,
                                                    1,
                                                    state,
                                                    reason,
                                                    reason,
                                                    trackerName, phase,
                                                    new Counters());
    synchronized (lockObject) {
      // update the actual start-time of the attempt
      TaskStatus oldStatus = tip.getTaskStatus(taskid);
      long startTime = oldStatus == null
      ? JobTracker.getClock().getTime()
          : oldStatus.getStartTime();
      if (startTime < 0) {
        startTime = JobTracker.getClock().getTime();
      }
      status.setStartTime(startTime);
      status.setFinishTime(JobTracker.getClock().getTime());
      boolean wasComplete = tip.isComplete();
      updateTaskStatus(tip, status, ttStatus);
      boolean isComplete = tip.isComplete();
      if (wasComplete && !isComplete) { // mark a successful tip as failed
        String taskType = getTaskType(tip);
        JobHistory.Task.logFailed(tip.getTIPId(), taskType,
            tip.getExecFinishTime(), reason, taskid);
      }
    }
  }
1042244
@Override
  public <V> Callable<V> wrap(Callable<V> callable) {
    if (isTracing()) {
      return new SpanContinuingTraceCallable<V>(this, this.traceKeys, this.spanNamer, callable);
    }
    return callable;
  }
1001702
function () {
    if (this._lock) return
    this._lock = true
    let task = this._tasks.shift()
    let tstType = this.error ? ['catch', 'end'] : ['then', 'end']
    while (task && !~tstType.indexOf(task.type)) {
      task = this._tasks.shift()
    }
    if (task) {
      let cb = (err, res) => {
        this.error = err
        this.result = res || this.result
        this._lock = false
        this._run()
      }
      let fn = task.fn
      if (task.type === 'end') { // .end
        fn(this.error, this.result)
      } else {
        try {
          if (task.type === 'catch') { // .catch
            fn(this.error, this.result, cb)
          } else { // .then
            fn(this.result, cb)
          }
        } catch (e) {
          cb(e)
        }
      }
    } else {
      this._lock = false
    }
  }
836095
protected Runnable wrapTask(Runnable task) {
    // Preserve the MDC context of the caller thread.
    Map contextMap = MDC.getCopyOfContextMap();
    if (contextMap != null) {
      return new MDCRunnableAdapter(task, contextMap);
    }
    return task;
  }
862375
def progress_task(name=None, t=INFO, max_value=100, *args, **kwargs):
    
    return task(name=name, t=t, init_progress=True, max_value=max_value,
                *args, **kwargs)
614836
public static <T> Iterator<T> wrap(Iterator<T> it, ProgressBarBuilder pbb) {
        return new ProgressBarWrappedIterator<>(it, pbb.build());
    }
363133
private void bindProgressBar(final ServiceTaskBase<?> task, final ProgressBar progressBar) {

        // Perform this binding into the JAT to respect widget and task API
        JRebirth.runIntoJAT("Bind ProgressBar to " + task.getServiceHandlerName(),
                            () -> {
                                // Avoid the progress bar to display 100% at start up
                                task.updateProgress(0, 0);
                                // Bind the progress bar
                                progressBar.progressProperty().bind(task.workDoneProperty().divide(task.totalWorkProperty()));
                            });

    }
190885
public static ProgressFeedback runWithProgress( final String strNotice, final IRunnableWithProgress task )
  {
    return runWithProgress( strNotice, task, false, false );
  }
798493
private java.util.Map<JobHistory.Keys, String> getLastSuccessfulTaskAttempt(JobHistory.Task task) {
    
    Map<String, JobHistory.TaskAttempt> taskAttempts = task.getTaskAttempts();
    int size = taskAttempts.size();
    java.util.Iterator<Map.Entry<String, JobHistory.TaskAttempt>> kv = taskAttempts.entrySet().iterator();
    for (int i=0; i<size; i++) {
      // CHECK_IT: Only one SUCCESSFUL TASK ATTEMPT
      Map.Entry<String, JobHistory.TaskAttempt> tae = kv.next();
      JobHistory.TaskAttempt attempt = tae.getValue();
      if (attempt.getValues().get(JobHistory.Keys.TASK_STATUS).equals("SUCCESS")) {
        return attempt.getValues();
      }
    }
    
    return null;
  }
133297
@MainThread
    private void handleTaskFinished(Task task) {
        if (task.method.type != EventMethod.Type.SUBSCRIBE) {
            // We are not interested in finished callbacks, only finished subscriber calls
            return;
        }

        if (task.method.isSingleThread) {
            Utils.log(task, "Single-thread method is no longer in use");
            task.method.isInUse = false;
        }

        Event event = task.event;

        if (!activeEvents.contains(event)) {
            Utils.logE(event.getKey(), "Cannot finish already finished event");
            return;
        }

        ((EventBase) event).handlersCount--;

        if (((EventBase) event).handlersCount == 0) {
            // No more running handlers
            activeEvents.remove(event);
            scheduleStatusUpdates(event, EventStatus.FINISHED);
            executeTasks(false);
        }
    }
327800
public void run(Collection<Runnable> tasks) {
        // Create a semphore that the wrapped runnables will execute
        int numTasks = tasks.size();
        CountDownLatch latch = new CountDownLatch(numTasks);
        for (Runnable r : tasks) {
            if (r == null)
                throw new NullPointerException("Cannot run null tasks");
            workQueue.offer(new CountingRunnable(r, latch));
        }
        try {
            // Wait until all the tasks have finished
            latch.await();
        }
        catch (InterruptedException ie) {
            throw new IllegalStateException("Not all tasks finished", ie);
        }
    }
70257
public static <T> Iterable<T> wrap(final Iterable<T> base) {
        return new Iterable<T>() {
            public Iterator<T> iterator() {
                final Iterator<T> itr = base.iterator();
                return new Iterator<T>() {
                    public boolean hasNext() {
                        return itr.hasNext();
                    }

                    public T next() {
                        return itr.next();
                    }

                    public void remove() {
                        itr.remove();
                    }
                };
            }
        };
    }
1142656
function(task, context, args) {
            // can used to default task
            if (!_.isFunction(task)) {
                args = task;
                task = null;
                context = null;
            }

            if (!_.isArray(args)) args = [args];

            var d = Q.defer();
            this.tasks.push({
                "task": task,
                "args": args || [],
                "context": context,
                "result": d
            });
            if (this.empty == true) {
                this.startNext();
            }
            return d.promise;
        }
387561
private void failTask(final ExecutionAttemptID executionAttemptID, final Throwable cause) {
		final Task task = taskSlotTable.getTask(executionAttemptID);

		if (task != null) {
			try {
				task.failExternally(cause);
			} catch (Throwable t) {
				log.error("Could not fail task {}.", executionAttemptID, t);
			}
		} else {
			log.debug("Cannot find task to fail for execution {}.", executionAttemptID);
		}
	}
807659
void addTaskToChain(Task[] tasks, Task task, int index) {
        task.setNext(tasks[index]);
        tasks[index] = task;
    }
1347051
public static <S extends Closeable> void closeOnComplete(S stream, StreamTask<S> task) {
        closeOnComplete(stream, task, DEFAULT_ERROR_HANDLER);
    }