/**
* <b><u>TmfExperimentContext</u></b>
* <p>
- * Implement me. Please.
+ * The experiment keeps track of the next event from each of its traces so
+ * it can pick the next one in chronological order.
+ * <p>
+ * This implies that the "next" event from each trace has already been
+ * read and that we at least know its timestamp. This doesn't imply that a
+ * full parse of the event content was performed (read: LTTng works like
+ * this).
+ * <p>
+ * The last trace refers to the trace from which the last event was
+ * "consumed" at the experiment level.
*/
public class TmfExperimentContext extends TmfContext {
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ public static final int NO_TRACE = -1;
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
private ITmfTrace[] fTraces = new ITmfTrace[0];
private TmfContext[] fContexts;
private TmfEvent[] fEvents;
- private int lastIndex;
+ private int lastTraceRead;
// ------------------------------------------------------------------------
// Constructors
fEvents = new TmfEvent[fTraces.length];
ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
+ long[] ranks = new long[fTraces.length];
long rank = 0;
for (int i = 0; i < fTraces.length; i++) {
if (contexts[i] != null) {
locations[i] = contexts[i].getLocation();
+ ranks[i] = contexts[i].getRank();
rank += contexts[i].getRank();
}
}
- setLocation(new TmfExperimentLocation(locations));
+ setLocation(new TmfExperimentLocation(new TmfLocationArray(locations), ranks));
setRank(rank);
- lastIndex = -1;
+ lastTraceRead = NO_TRACE;
}
public TmfExperimentContext(ITmfTrace[] traces) {
public TmfExperimentContext(TmfExperimentContext other) {
this(other.fTraces, other.cloneContexts());
fEvents = other.fEvents;
- setLocation(other.getLocation().clone());
+ if (other.getLocation() != null)
+ setLocation(other.getLocation().clone());
setRank(other.getRank());
- setLastTrace(other.lastIndex);
+ setLastTrace(other.lastTraceRead);
}
private TmfContext[] cloneContexts() {
}
public int getLastTrace() {
- return lastIndex;
+ return lastTraceRead;
}
public void setLastTrace(int newIndex) {
- lastIndex = newIndex;
+ lastTraceRead = newIndex;
}
+ // ------------------------------------------------------------------------
+ // Object
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ for (int i = 0; i < fTraces.length; i++) {
+ result = 37 * result + fTraces[i].hashCode();
+ result = 37 * result + fContexts[i].hashCode();
+ }
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof TmfExperimentContext)) {
+ return false;
+ }
+ TmfExperimentContext o = (TmfExperimentContext) other;
+ boolean isEqual = true;
+ int i = 0;
+ while (isEqual && i < fTraces.length) {
+ isEqual &= fTraces[i].equals(o.fTraces[i]);
+ isEqual &= fContexts[i].equals(o.fContexts[i]);
+ i++;
+ }
+ return isEqual;
+ }
+
}