示例#1
0
  /** @since 2.0 */
  @Override
  public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {

    // A null timestamp indicates to seek the first event
    if (timestamp == null) {
      ITmfContext context = seekEvent((ITmfLocation) null);
      context.setRank(0);
      return context;
    }

    // Position the trace at the checkpoint
    ITmfContext context = fIndexer.seekIndex(timestamp);

    // And locate the requested event context
    ITmfLocation previousLocation = context.getLocation();
    long previousRank = context.getRank();
    ITmfEvent event = getNext(context);
    while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
      previousLocation = context.getLocation();
      previousRank = context.getRank();
      event = getNext(context);
    }
    if (event == null) {
      context.setLocation(null);
      context.setRank(ITmfContext.UNKNOWN_RANK);
    } else {
      context.dispose();
      context = seekEvent(previousLocation);
      context.setRank(previousRank);
    }
    return context;
  }
示例#2
0
 @Override
 public synchronized ITmfEvent getNext(final ITmfContext context) {
   // parseEvent() does not update the context
   final ITmfEvent event = fParser.parseEvent(context);
   if (event != null) {
     updateAttributes(context, event.getTimestamp());
     context.setLocation(getCurrentLocation());
     context.increaseRank();
     processEvent(event);
   }
   return event;
 }
示例#3
0
  @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;
  }
示例#4
0
  private synchronized void initializeStreamingMonitor() {

    if (fInitialized) {
      return;
    }
    fInitialized = true;

    if (getStreamingInterval() == 0) {
      final ITmfContext context = seekEvent(0);
      final ITmfEvent event = getNext(context);
      context.dispose();
      if (event == null) {
        return;
      }
      final TmfTimeRange timeRange =
          new TmfTimeRange(event.getTimestamp(), TmfTimestamp.BIG_CRUNCH);
      final TmfTraceRangeUpdatedSignal signal =
          new TmfTraceRangeUpdatedSignal(this, this, timeRange);

      // Broadcast in separate thread to prevent deadlock
      new Thread() {
        @Override
        public void run() {
          broadcast(signal);
        }
      }.start();
      return;
    }

    final Thread thread =
        new Thread("Streaming Monitor for experiment " + getName()) { // $NON-NLS-1$
          private ITmfTimestamp safeTimestamp = null;
          private ITmfTimestamp lastSafeTimestamp = null;
          private TmfTimeRange timeRange = null;

          @Override
          public void run() {
            while (!executorIsShutdown()) {
              if (!getIndexer().isIndexing()) {
                ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH;
                ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG;
                for (final ITmfTrace trace : fTraces) {
                  if (trace.getStartTime().compareTo(startTimestamp) < 0) {
                    startTimestamp = trace.getStartTime();
                  }
                  if (trace.getStreamingInterval() != 0
                      && trace.getEndTime().compareTo(endTimestamp) > 0) {
                    endTimestamp = trace.getEndTime();
                  }
                }
                if (safeTimestamp != null
                    && (lastSafeTimestamp == null
                        || safeTimestamp.compareTo(lastSafeTimestamp, false) > 0)) {
                  timeRange = new TmfTimeRange(startTimestamp, safeTimestamp);
                  lastSafeTimestamp = safeTimestamp;
                } else {
                  timeRange = null;
                }
                safeTimestamp = endTimestamp;
                if (timeRange != null) {
                  final TmfTraceRangeUpdatedSignal signal =
                      new TmfTraceRangeUpdatedSignal(
                          TmfExperiment.this, TmfExperiment.this, timeRange);
                  broadcast(signal);
                }
              }
              try {
                Thread.sleep(getStreamingInterval());
              } catch (final InterruptedException e) {
                e.printStackTrace();
              }
            }
          }
        };
    thread.start();
  }
示例#5
0
 /**
  * Returns the timestamp of the event at the requested index. If none, returns null.
  *
  * @param index the event index (rank)
  * @return the corresponding event timestamp
  * @since 2.0
  */
 public ITmfTimestamp getTimestamp(final int index) {
   final ITmfContext context = seekEvent(index);
   final ITmfEvent event = getNext(context);
   context.dispose();
   return (event != null) ? event.getTimestamp() : null;
 }