示例#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());
      }
    }
  }
示例#2
0
    @Override
    public void onResolved(final Promise<T> promise) {
      if (_executionReportBuilder != null) {
        _executionReportBuilder.setParseqTrace(_associatedTask.getTrace());
      }

      RequestExecutionReport executionReport = getRequestExecutionReport(_executionReportBuilder);

      if (promise.isFailed()) {
        _callback.onError(
            promise.getError() instanceof RestLiServiceException
                ? promise.getError()
                : new RestLiServiceException(
                    HttpStatus.S_500_INTERNAL_SERVER_ERROR, promise.getError()),
            executionReport);
      } else {
        _callback.onSuccess(promise.get(), executionReport);
      }
    }