+ @Override
+ public ITmfStateInterval querySingleState(long t, int attributeQuark)
+ throws AttributeNotFoundException, TimeRangeException,
+ StateSystemDisposedException {
+ if (isDisposed) {
+ throw new StateSystemDisposedException();
+ }
+
+ ITmfStateInterval ret;
+ if (transState.hasInfoAboutStateOf(t, attributeQuark)) {
+ ret = transState.getOngoingInterval(attributeQuark);
+ } else {
+ ret = backend.doSingularQuery(t, attributeQuark);
+ }
+
+ /*
+ * Return a fake interval if we could not find anything in the history.
+ * We do NOT want to return 'null' here.
+ */
+ if (ret == null) {
+ //logMissingInterval(attributeQuark, t);
+ return new TmfStateInterval(t, this.getCurrentEndTime(),
+ attributeQuark, TmfStateValue.nullValue());
+ }
+ return ret;
+ }
+
+ @Override
+ public ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
+ throws StateValueTypeException, AttributeNotFoundException,
+ TimeRangeException, StateSystemDisposedException {
+ Integer curStackDepth = querySingleState(t, stackAttributeQuark).getStateValue().unboxInt();
+
+ if (curStackDepth == -1) {
+ /* There is nothing stored in this stack at this moment */
+ return null;
+ } else if (curStackDepth < -1 || curStackDepth == 0) {
+ /*
+ * This attribute is an integer attribute, but it doesn't seem like
+ * it's used as a stack-attribute...
+ */
+ throw new StateValueTypeException();
+ }
+
+ int subAttribQuark = getQuarkRelative(stackAttributeQuark, curStackDepth.toString());
+ ITmfStateInterval ret = querySingleState(t, subAttribQuark);
+ return ret;
+ }
+
+ @Override
+ public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+ long t1, long t2) throws TimeRangeException,
+ AttributeNotFoundException, StateSystemDisposedException {
+ if (isDisposed) {
+ throw new StateSystemDisposedException();
+ }
+
+ List<ITmfStateInterval> intervals;
+ ITmfStateInterval currentInterval;
+ long ts, tEnd;
+
+ /* Make sure the time range makes sense */
+ if (t2 <= t1) {
+ throw new TimeRangeException();
+ }
+
+ /* Set the actual, valid end time of the range query */
+ if (t2 > this.getCurrentEndTime()) {
+ tEnd = this.getCurrentEndTime();
+ } else {
+ tEnd = t2;
+ }
+
+ /* Get the initial state at time T1 */
+ intervals = new ArrayList<ITmfStateInterval>();
+ currentInterval = querySingleState(t1, attributeQuark);
+ intervals.add(currentInterval);
+
+ /* Get the following state changes */
+ ts = currentInterval.getEndTime();
+ while (ts != -1 && ts < tEnd) {
+ ts++; /* To "jump over" to the next state in the history */
+ currentInterval = querySingleState(ts, attributeQuark);
+ intervals.add(currentInterval);
+ ts = currentInterval.getEndTime();
+ }
+ return intervals;
+ }
+
+ @Override
+ public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+ long t1, long t2, long resolution, IProgressMonitor monitor)
+ throws TimeRangeException, AttributeNotFoundException,
+ StateSystemDisposedException {
+ if (isDisposed) {
+ throw new StateSystemDisposedException();
+ }
+
+ List<ITmfStateInterval> intervals;
+ ITmfStateInterval currentInterval;
+ long ts, tEnd;
+
+ IProgressMonitor mon = monitor;
+ if (mon == null) {
+ mon = new NullProgressMonitor();
+ }
+
+ /* Make sure the time range makes sense */
+ if (t2 < t1 || resolution <= 0) {
+ throw new TimeRangeException();
+ }
+
+ /* Set the actual, valid end time of the range query */
+ if (t2 > this.getCurrentEndTime()) {
+ tEnd = this.getCurrentEndTime();
+ } else {
+ tEnd = t2;
+ }
+
+ /* Get the initial state at time T1 */
+ intervals = new ArrayList<ITmfStateInterval>();
+ currentInterval = querySingleState(t1, attributeQuark);
+ intervals.add(currentInterval);
+
+ /*
+ * Iterate over the "resolution points". We skip unneeded queries in the
+ * case the current interval is longer than the resolution.
+ */
+ for (ts = t1; (currentInterval.getEndTime() != -1) && (ts < tEnd);
+ ts += resolution) {
+ if (mon.isCanceled()) {
+ return intervals;
+ }
+ if (ts <= currentInterval.getEndTime()) {
+ continue;
+ }
+ currentInterval = querySingleState(ts, attributeQuark);
+ intervals.add(currentInterval);
+ }
+
+ /* Add the interval at t2, if it wasn't included already. */
+ if (currentInterval.getEndTime() < tEnd) {
+ currentInterval = querySingleState(tEnd, attributeQuark);
+ intervals.add(currentInterval);
+ }
+ return intervals;
+ }
+
+ //--------------------------------------------------------------------------
+ // Debug methods
+ //--------------------------------------------------------------------------
+
+ static void logMissingInterval(int attribute, long timestamp) {
+ Activator.logInfo("No data found in history for attribute " + //$NON-NLS-1$
+ attribute + " at time " + timestamp + //$NON-NLS-1$
+ ", returning dummy interval"); //$NON-NLS-1$