예제 #1
0
파일: BaseTask.java 프로젝트: angxu/parseq
 protected void traceFailure(final Throwable reason) {
   if (Exceptions.isEarlyFinish(reason)) {
     _shallowTraceBuilder.setResultType(ResultType.EARLY_FINISH);
   } else {
     _shallowTraceBuilder.setResultType(ResultType.ERROR);
     _shallowTraceBuilder.setValue(Exceptions.failureToString(reason));
   }
 }
예제 #2
0
파일: BaseTask.java 프로젝트: angxu/parseq
 /**
  * Constructs a base task with a name.
  *
  * @param name the name for this task.
  */
 public BaseTask(final String name) {
   super(Promises.<T>settable());
   _name = truncate(name);
   final State state = State.INIT;
   _shallowTraceBuilder = new ShallowTraceBuilder(_id);
   _shallowTraceBuilder.setName(getName());
   _shallowTraceBuilder.setResultType(ResultType.UNFINISHED);
   _stateRef = new AtomicReference<State>(state);
 }
예제 #3
0
파일: BaseTask.java 프로젝트: angxu/parseq
 private void traceDone(final T value) {
   _shallowTraceBuilder.setResultType(ResultType.SUCCESS);
   final Function<T, String> traceValueProvider = _traceValueProvider;
   if (traceValueProvider != null) {
     try {
       _shallowTraceBuilder.setValue(traceValueProvider.apply(value));
     } catch (Exception e) {
       _shallowTraceBuilder.setValue(Exceptions.failureToString(e));
     }
   }
 }
예제 #4
0
  private static void parseTraces(
      final JsonNode rootNode, final TraceRelationshipBuilder<Integer> builder) throws IOException {
    for (JsonNode traceNode : getField(rootNode, JsonTraceCodec.TRACES)) {
      final int traceId = getIntField(traceNode, JsonTraceCodec.TRACE_ID);
      final String name = getTextField(traceNode, JsonTraceCodec.TRACE_NAME);
      final ResultType resultType =
          ResultType.valueOf(getTextField(traceNode, JsonTraceCodec.TRACE_RESULT_TYPE));
      final ShallowTraceBuilder shallowBuilder = new ShallowTraceBuilder(name, resultType);

      if (traceNode.get(JsonTraceCodec.TRACE_HIDDEN) != null)
        shallowBuilder.setHidden(getBooleanField(traceNode, JsonTraceCodec.TRACE_HIDDEN));

      if (traceNode.get(JsonTraceCodec.TRACE_SYSTEM_HIDDEN) != null)
        shallowBuilder.setSystemHidden(
            getBooleanField(traceNode, JsonTraceCodec.TRACE_SYSTEM_HIDDEN));

      if (traceNode.get(JsonTraceCodec.TRACE_VALUE) != null)
        shallowBuilder.setValue(getTextField(traceNode, JsonTraceCodec.TRACE_VALUE));

      if (traceNode.get(JsonTraceCodec.TRACE_START_NANOS) != null)
        shallowBuilder.setStartNanos(getLongField(traceNode, JsonTraceCodec.TRACE_START_NANOS));

      if (traceNode.get(JsonTraceCodec.TRACE_END_NANOS) != null)
        shallowBuilder.setEndNanos(getLongField(traceNode, JsonTraceCodec.TRACE_END_NANOS));

      if (traceNode.get(JsonTraceCodec.TRACE_ATTRIBUTES) != null) {
        for (JsonNode node : getField(traceNode, JsonTraceCodec.TRACE_ATTRIBUTES)) {
          String key = getTextField(node, JsonTraceCodec.TRACE_ATTRIBUTE_KEY);
          String value = getTextField(node, JsonTraceCodec.TRACE_ATTRIBUTE_VALUE);
          shallowBuilder.addAttribute(key, value);
        }
      }

      builder.addTrace(traceId, shallowBuilder.build());
    }
  }
예제 #5
0
파일: BaseTask.java 프로젝트: angxu/parseq
 protected void markTaskPending() {
   _shallowTraceBuilder.setPendingNanos(System.nanoTime());
 }
예제 #6
0
파일: BaseTask.java 프로젝트: angxu/parseq
 protected void markTaskStarted() {
   _shallowTraceBuilder.setStartNanos(System.nanoTime());
 }
예제 #7
0
파일: BaseTask.java 프로젝트: angxu/parseq
 @Override
 public ShallowTrace getShallowTrace() {
   return _shallowTraceBuilder.build();
 }
예제 #8
0
  private static Map<Long, ShallowTrace> parseTraces(final JsonNode rootNode) throws IOException {
    Map<Long, ShallowTrace> traceMap = new HashMap<>();
    for (JsonNode traceNode : getField(rootNode, JsonTraceCodec.TRACES)) {
      final long traceId = getLongField(traceNode, JsonTraceCodec.TRACE_ID);
      final ShallowTraceBuilder shallowBuilder = new ShallowTraceBuilder(traceId);

      final String name = getTextField(traceNode, JsonTraceCodec.TRACE_NAME);
      shallowBuilder.setName(name);

      if (traceNode.get(JsonTraceCodec.TRACE_HIDDEN) != null)
        shallowBuilder.setHidden(getBooleanField(traceNode, JsonTraceCodec.TRACE_HIDDEN));

      if (traceNode.get(JsonTraceCodec.TRACE_SYSTEM_HIDDEN) != null)
        shallowBuilder.setSystemHidden(
            getBooleanField(traceNode, JsonTraceCodec.TRACE_SYSTEM_HIDDEN));

      if (traceNode.get(JsonTraceCodec.TRACE_VALUE) != null)
        shallowBuilder.setValue(getTextField(traceNode, JsonTraceCodec.TRACE_VALUE));

      if (traceNode.get(JsonTraceCodec.TRACE_START_NANOS) != null)
        shallowBuilder.setStartNanos(getLongField(traceNode, JsonTraceCodec.TRACE_START_NANOS));

      if (traceNode.get(JsonTraceCodec.TRACE_PENDING_NANOS) != null)
        shallowBuilder.setPendingNanos(getLongField(traceNode, JsonTraceCodec.TRACE_PENDING_NANOS));

      if (traceNode.get(JsonTraceCodec.TRACE_END_NANOS) != null)
        shallowBuilder.setEndNanos(getLongField(traceNode, JsonTraceCodec.TRACE_END_NANOS));

      if (traceNode.get(JsonTraceCodec.TRACE_ATTRIBUTES) != null) {
        for (JsonNode node : getField(traceNode, JsonTraceCodec.TRACE_ATTRIBUTES)) {
          String key = getTextField(node, JsonTraceCodec.TRACE_ATTRIBUTE_KEY);
          String value = getTextField(node, JsonTraceCodec.TRACE_ATTRIBUTE_VALUE);
          shallowBuilder.addAttribute(key, value);
        }
      }

      final ResultType resultType =
          ResultType.valueOf(getTextField(traceNode, JsonTraceCodec.TRACE_RESULT_TYPE));
      shallowBuilder.setResultType(resultType);

      traceMap.put(traceId, shallowBuilder.build());
    }
    return traceMap;
  }