Exemplo n.º 1
0
  @Override
  public final void contextRun(
      final Context context, final Task<?> parent, final Collection<Task<?>> predecessors) {
    final TaskLogger taskLogger = context.getTaskLogger();
    final TraceBuilder traceBuilder = context.getTraceBuilder();
    if (transitionRun(traceBuilder)) {
      markTaskStarted();
      final Promise<T> promise;
      try {
        if (parent != null) {
          traceBuilder.addRelationship(
              Relationship.CHILD_OF, getShallowTraceBuilder(), parent.getShallowTraceBuilder());
        }
        for (Task<?> predecessor : predecessors) {
          traceBuilder.addRelationship(
              Relationship.SUCCESSOR_OF,
              getShallowTraceBuilder(),
              predecessor.getShallowTraceBuilder());
        }

        taskLogger.logTaskStart(this);
        try {
          final Context wrapperContext = new WrappedContext(context);
          promise = doContextRun(wrapperContext);
        } finally {
          transitionPending();
        }

        promise.addListener(
            resolvedPromise -> {
              if (resolvedPromise.isFailed()) {
                fail(resolvedPromise.getError(), taskLogger);
              } else {
                done(resolvedPromise.get(), taskLogger);
              }
            });
      } catch (Throwable t) {
        fail(t, taskLogger);
      }
    } else {
      // this is possible when task was cancelled or has been executed multiple times
      // e.g. task has multiple paths it can be executed with or has been completed by
      // a FusionTask
      if (parent != null) {
        traceBuilder.addRelationship(
            Relationship.POTENTIAL_CHILD_OF,
            getShallowTraceBuilder(),
            parent.getShallowTraceBuilder());
      }
      for (Task<?> predecessor : predecessors) {
        traceBuilder.addRelationship(
            Relationship.POSSIBLE_SUCCESSOR_OF,
            getShallowTraceBuilder(),
            predecessor.getShallowTraceBuilder());
      }
    }
  }
Exemplo n.º 2
0
 @Override
 public void run(final Task<?> task) {
   _after.run(task);
   getTraceBuilder()
       .addRelationship(
           Relationship.POTENTIAL_PARENT_OF,
           getShallowTraceBuilder(),
           task.getShallowTraceBuilder());
 }
Exemplo n.º 3
0
 @Override
 public Cancellable createTimer(final long time, final TimeUnit unit, final Task<?> task) {
   final Cancellable cancellable = _context.createTimer(time, unit, task);
   getTraceBuilder()
       .addRelationship(
           Relationship.POTENTIAL_PARENT_OF,
           getShallowTraceBuilder(),
           task.getShallowTraceBuilder());
   return cancellable;
 }
Exemplo n.º 4
0
 @Override
 public void runSideEffect(Task<?>... tasks) {
   _context.runSideEffect(tasks);
   for (Task<?> task : tasks) {
     getTraceBuilder()
         .addRelationship(
             Relationship.POTENTIAL_PARENT_OF,
             getShallowTraceBuilder(),
             task.getShallowTraceBuilder());
   }
 }
Exemplo n.º 5
0
 @Override
 public void run(Supplier<Task<?>> taskSupplier) {
   _after.run(
       () -> {
         Task<?> task = taskSupplier.get();
         if (task != null) {
           getTraceBuilder()
               .addRelationship(
                   Relationship.POTENTIAL_PARENT_OF,
                   getShallowTraceBuilder(),
                   task.getShallowTraceBuilder());
         }
         return task;
       });
 }