コード例 #1
0
ファイル: TmfExperiment.java プロジェクト: TheZorg/linuxtools
  @Override
  public synchronized ITmfEvent getNext(ITmfContext context) {

    // Validate the context
    if (!(context instanceof TmfExperimentContext)) {
      return null; // Throw an exception?
    }

    // Make sure that we have something to read from
    if (fTraces == null) {
      return null;
    }

    TmfExperimentContext expContext = (TmfExperimentContext) context;

    // If an event was consumed previously, first get the next one from that
    // trace
    final int lastTrace = expContext.getLastTrace();
    if (lastTrace != TmfExperimentContext.NO_TRACE) {
      final ITmfContext traceContext = expContext.getContext(lastTrace);
      expContext.setEvent(lastTrace, fTraces[lastTrace].getNext(traceContext));
      expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
    }

    // Scan the candidate events and identify the "next" trace to read from
    int trace = TmfExperimentContext.NO_TRACE;
    ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH;
    for (int i = 0; i < fTraces.length; i++) {
      final ITmfEvent event = expContext.getEvent(i);
      if (event != null && event.getTimestamp() != null) {
        final ITmfTimestamp otherTS = event.getTimestamp();
        if (otherTS.compareTo(timestamp, true) < 0) {
          trace = i;
          timestamp = otherTS;
        }
      }
    }

    ITmfEvent event = null;
    if (trace != TmfExperimentContext.NO_TRACE) {
      event = expContext.getEvent(trace);
      if (event != null) {
        updateAttributes(expContext, event.getTimestamp());
        expContext.increaseRank();
        expContext.setLastTrace(trace);
        final ITmfContext traceContext = expContext.getContext(trace);
        if (traceContext == null) {
          throw new IllegalStateException();
        }

        // Update the experiment location
        TmfLocationArray locationArray =
            new TmfLocationArray(
                ((TmfExperimentLocation) expContext.getLocation()).getLocationInfo(),
                trace,
                traceContext.getLocation(),
                traceContext.getRank());
        expContext.setLocation(new TmfExperimentLocation(locationArray));

        processEvent(event);
      }
    }

    return event;
  }