@Override public Trace getTrace() { TraceBuilder traceBuilder = getTraceBuilder(); if (traceBuilder != null) { return traceBuilder.build(); } else { return Trace.single(getShallowTrace(), "none", 0L); } }
@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()); } } }
protected boolean transitionRun(final TraceBuilder traceBuilder) { State state; State newState; do { state = _stateRef.get(); if (state.getType() != StateType.INIT) { return false; } newState = state.transitionRun(); } while (!_stateRef.compareAndSet(state, newState)); _traceBuilder = traceBuilder; traceBuilder.addShallowTrace(_shallowTraceBuilder); return true; }