Bug 315605: [LTTng] Document exact version of liblttvtraceread that works
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / experiment / TmfExperiment.java
CommitLineData
8c8bf09f
ASL
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.experiment;
14
9f584e4c 15import java.util.Collections;
8c8bf09f
ASL
16import java.util.Vector;
17
fc6ccf6f 18import org.eclipse.linuxtools.tmf.component.TmfEventProvider;
8c8bf09f
ASL
19import org.eclipse.linuxtools.tmf.event.TmfEvent;
20import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
21import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
2fb2eb37
FC
22import org.eclipse.linuxtools.tmf.request.ITmfDataRequest;
23import org.eclipse.linuxtools.tmf.request.ITmfEventRequest;
550d787e
FC
24import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
25import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
ff4ed569
FC
26import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal;
27import org.eclipse.linuxtools.tmf.signal.TmfExperimentUpdatedSignal;
8c8bf09f 28import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
550d787e 29import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
ff4ed569 30import org.eclipse.linuxtools.tmf.signal.TmfTraceUpdatedSignal;
9f584e4c
FC
31import org.eclipse.linuxtools.tmf.trace.ITmfContext;
32import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
8c8bf09f 33import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
9f584e4c
FC
34import org.eclipse.linuxtools.tmf.trace.TmfCheckpoint;
35import org.eclipse.linuxtools.tmf.trace.TmfContext;
8c8bf09f
ASL
36
37/**
38 * <b><u>TmfExperiment</u></b>
39 * <p>
40 * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
41 * that are part of a tracing experiment.
42 * <p>
43 */
fc6ccf6f 44public class TmfExperiment<T extends TmfEvent> extends TmfEventProvider<T> implements ITmfTrace {
8c8bf09f
ASL
45
46 // ------------------------------------------------------------------------
47 // Attributes
48 // ------------------------------------------------------------------------
49
50 // The currently selected experiment
cbd4ad82 51 private static TmfExperiment<?> fCurrentExperiment = null;
e31e01e8 52
550d787e 53 // The set of traces that constitute the experiment
9f584e4c 54 private ITmfTrace[] fTraces;
8c8bf09f
ASL
55
56 // The total number of events
9f584e4c 57 private long fNbEvents;
8c8bf09f
ASL
58
59 // The experiment time range
60 private TmfTimeRange fTimeRange;
61
62 // The experiment reference timestamp (default: BigBang)
63 private TmfTimestamp fEpoch;
64
9f584e4c
FC
65 // The experiment index
66 private Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
67
8c8bf09f
ASL
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71
72 /**
73 * @param type
74 * @param id
75 * @param traces
76 * @param epoch
77 * @param indexPageSize
78 */
79 public TmfExperiment(Class<T> type, String id, ITmfTrace[] traces, TmfTimestamp epoch, int indexPageSize) {
cb866e08
FC
80 this(type, id, traces, TmfTimestamp.Zero, DEFAULT_INDEX_PAGE_SIZE, false);
81 }
82
83 public TmfExperiment(Class<T> type, String id, ITmfTrace[] traces, TmfTimestamp epoch, int indexPageSize, boolean waitForCompletion) {
ce785d7d 84 super(id, type);
8c8bf09f 85
9f584e4c 86 fTraces = traces;
8c8bf09f
ASL
87 fEpoch = epoch;
88 fIndexPageSize = indexPageSize;
550d787e 89 fClone = createTraceCopy();
8c8bf09f 90
cb866e08
FC
91 if (waitForCompletion) indexExperiment(true);
92
8c8bf09f 93 updateTimeRange();
550d787e 94 }
8c8bf09f
ASL
95
96 /**
97 * @param type
98 * @param id
99 * @param traces
100 */
101 public TmfExperiment(Class<T> type, String id, ITmfTrace[] traces) {
102 this(type, id, traces, TmfTimestamp.Zero, DEFAULT_INDEX_PAGE_SIZE);
103 }
104
105 /**
106 * @param type
107 * @param id
108 * @param traces
109 * @param indexPageSize
110 */
111 public TmfExperiment(Class<T> type, String id, ITmfTrace[] traces, int indexPageSize) {
112 this(type, id, traces, TmfTimestamp.Zero, indexPageSize);
113 }
377f1ad8 114
ce785d7d 115 public TmfExperiment(TmfExperiment<T> other) {
550d787e 116 super(other.getName() + "(clone)", other.fType);
377f1ad8 117
ce785d7d
FC
118 fEpoch = other.fEpoch;
119 fIndexPageSize = other.fIndexPageSize;
377f1ad8 120
ce785d7d
FC
121 fTraces = new ITmfTrace[other.fTraces.length];
122 for (int trace = 0; trace < other.fTraces.length; trace++) {
123 fTraces[trace] = other.fTraces[trace].createTraceCopy();
377f1ad8
WB
124 }
125
ce785d7d
FC
126 fNbEvents = other.fNbEvents;
127 fTimeRange = other.fTimeRange;
550d787e 128 fClone = null;
377f1ad8
WB
129 }
130
131 public TmfExperiment<T> createTraceCopy() {
550d787e
FC
132 TmfExperiment<T> experiment = new TmfExperiment<T>(this);
133 TmfSignalManager.deregister(experiment);
134 return experiment;
377f1ad8
WB
135 }
136
8c8bf09f 137 /**
ff4ed569 138 * Clears the experiment
8c8bf09f
ASL
139 */
140 @Override
2fb2eb37 141 public void dispose() {
550d787e
FC
142 if (fTraces != null) {
143 for (ITmfTrace trace : fTraces) {
144 trace.dispose();
145 }
146 fTraces = null;
147 }
148 if (fCheckpoints != null) {
149 fCheckpoints.clear();
ff4ed569 150 }
2fb2eb37 151 super.dispose();
8c8bf09f
ASL
152 }
153
cbd4ad82
FC
154 private static void setCurrentExperiment(TmfExperiment<?> experiment) {
155 fCurrentExperiment = experiment;
156 }
157
9f584e4c 158 // ------------------------------------------------------------------------
cbd4ad82 159 // ITmfTrace
9f584e4c
FC
160 // ------------------------------------------------------------------------
161
162 public String getPath() {
163 return null;
164 }
165
9f584e4c
FC
166 public long getNbEvents() {
167 return fNbEvents;
168 }
169
54d55ced
FC
170 public int getCacheSize() {
171 return fIndexPageSize;
172 }
173
9f584e4c
FC
174 public TmfTimeRange getTimeRange() {
175 return fTimeRange;
176 }
177
178 public TmfTimestamp getStartTime() {
179 return fTimeRange.getStartTime();
180 }
181
182 public TmfTimestamp getEndTime() {
183 return fTimeRange.getEndTime();
184 }
185
54d55ced
FC
186 public Vector<TmfCheckpoint> getCheckpoints() {
187 return fCheckpoints;
188 }
189
8c8bf09f 190 // ------------------------------------------------------------------------
e31e01e8 191 // Accessors
8c8bf09f
ASL
192 // ------------------------------------------------------------------------
193
e31e01e8
FC
194 public static TmfExperiment<?> getCurrentExperiment() {
195 return fCurrentExperiment;
8c8bf09f
ASL
196 }
197
8c8bf09f
ASL
198 public TmfTimestamp getEpoch() {
199 return fEpoch;
200 }
201
9f584e4c
FC
202 public ITmfTrace[] getTraces() {
203 return fTraces;
8c8bf09f
ASL
204 }
205
206 /**
207 * Returns the rank of the first event with the requested timestamp.
208 * If none, returns the index of the next event (if any).
209 *
85fb0e54 210 * @param timestamp
8c8bf09f
ASL
211 * @return
212 */
85fb0e54
FC
213 public long getRank(TmfTimestamp timestamp) {
214 TmfExperimentContext context = seekEvent(timestamp);
8c8bf09f
ASL
215 return context.getRank();
216 }
217
218 /**
219 * Returns the timestamp of the event at the requested index.
220 * If none, returns null.
221 *
222 * @param index
223 * @return
224 */
225 public TmfTimestamp getTimestamp(int index) {
85fb0e54 226 TmfExperimentContext context = seekEvent(index);
7f407ead 227 TmfEvent event = getNextEvent(context);
85fb0e54 228 return (event != null) ? event.getTimestamp() : null;
8c8bf09f
ASL
229 }
230
231 // ------------------------------------------------------------------------
232 // Operators
233 // ------------------------------------------------------------------------
234
235 /**
236 * Update the total number of events
237 */
238 private void updateNbEvents() {
239 int nbEvents = 0;
240 for (ITmfTrace trace : fTraces) {
241 nbEvents += trace.getNbEvents();
242 }
243 fNbEvents = nbEvents;
244 }
245
246 /**
247 * Update the global time range
248 */
249 private void updateTimeRange() {
250 TmfTimestamp startTime = fTimeRange != null ? fTimeRange.getStartTime() : TmfTimestamp.BigCrunch;
251 TmfTimestamp endTime = fTimeRange != null ? fTimeRange.getEndTime() : TmfTimestamp.BigBang;
252
253 for (ITmfTrace trace : fTraces) {
550d787e
FC
254 TmfTimestamp traceStartTime = trace.getStartTime();
255 if (traceStartTime.compareTo(startTime, true) < 0)
256 startTime = traceStartTime;
257 TmfTimestamp traceEndTime = trace.getEndTime();
258 if (traceEndTime.compareTo(endTime, true) > 0)
259 endTime = traceEndTime;
8c8bf09f 260 }
36548af3 261 fTimeRange = new TmfTimeRange(startTime, endTime);
8c8bf09f
ASL
262 }
263
264 // ------------------------------------------------------------------------
265 // TmfProvider
266 // ------------------------------------------------------------------------
267
268 @Override
2fb2eb37 269 public ITmfContext armRequest(ITmfDataRequest<T> request) {
2fb2eb37
FC
270 TmfTimestamp timestamp = (request instanceof ITmfEventRequest<?>) ?
271 ((ITmfEventRequest<T>) request).getRange().getStartTime() : null;
9f584e4c
FC
272 TmfExperimentContext context = (timestamp != null) ?
273 seekEvent(timestamp) : seekEvent(request.getIndex());
8c8bf09f
ASL
274 return context;
275 }
276
277 @SuppressWarnings("unchecked")
278 @Override
279 public T getNext(ITmfContext context) {
280 if (context instanceof TmfExperimentContext) {
281 return (T) getNextEvent((TmfExperimentContext) context);
282 }
283 return null;
284 }
285
550d787e 286 // ------------------------------------------------------------------------
9f584e4c
FC
287 // ITmfTrace trace positioning
288 // ------------------------------------------------------------------------
289
290 // Returns a brand new context based on the location provided
8f50c396 291 // and initializes the event queues
452ad365 292 public TmfExperimentContext seekLocation(ITmfLocation<?> location) {
8f50c396
FC
293
294 // Validate the location
295 if (location != null && !(location instanceof TmfExperimentLocation)) {
296 return null; // Throw an exception?
9f584e4c 297 }
8f50c396
FC
298
299 // Instantiate the location
300 TmfExperimentLocation expLocation = (location == null)
301 ? new TmfExperimentLocation(new ITmfLocation<?>[fTraces.length], new long[fTraces.length])
302 : (TmfExperimentLocation) location.clone();
303
304 // Create and populate the context's traces contexts
305 TmfExperimentContext context = new TmfExperimentContext(fTraces, new TmfContext[fTraces.length]);
306 long rank = 0;
307 for (int i = 0; i < fTraces.length; i++) {
308 // Get the relevant trace attributes
309 ITmfLocation<?> traceLocation = expLocation.getLocation()[i];
310 long traceRank = expLocation.getRanks()[i];
311
312 // Set the corresponding sub-context
313 context.getContexts()[i] = fTraces[i].seekLocation(traceLocation);
314 context.getContexts()[i].setRank(traceRank);
315 rank += traceRank;
316
317 // Set the trace location and read the corresponding event
318 expLocation.getLocation()[i] = context.getContexts()[i].getLocation();
319 context.getEvents()[i] = fTraces[i].getNextEvent(context.getContexts()[i]);
320 }
321
322 // Finalize context
323 context.setLocation(expLocation);
324 context.setRank(rank);
325 context.setLastTrace(TmfExperimentContext.NO_TRACE);
326 return context;
9f584e4c
FC
327 }
328
54d55ced
FC
329 /* (non-Javadoc)
330 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
331 */
9f584e4c 332 public TmfExperimentContext seekEvent(TmfTimestamp timestamp) {
8c8bf09f 333
9f584e4c
FC
334 if (timestamp == null) {
335 timestamp = TmfTimestamp.BigBang;
336 }
337
338 // First, find the right checkpoint
339 int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
340
341 // In the very likely case that the checkpoint was not found, bsearch
342 // returns its negated would-be location (not an offset...). From that
343 // index, we can then position the stream and get the event.
344 if (index < 0) {
345 index = Math.max(0, -(index + 2));
346 }
347
348 // Position the experiment at the checkpoint
452ad365 349 ITmfLocation<?> location;
9f584e4c
FC
350 synchronized (fCheckpoints) {
351 if (fCheckpoints.size() > 0) {
352 if (index >= fCheckpoints.size()) {
353 index = fCheckpoints.size() - 1;
354 }
355 location = fCheckpoints.elementAt(index).getLocation();
356 }
357 else {
358 location = null;
359 }
360 }
361
85fb0e54 362 TmfExperimentContext context = seekLocation(location);
cbd4ad82 363 context.setRank((long) index * fIndexPageSize);
9f584e4c 364
54d55ced
FC
365 // And locate the event
366 TmfExperimentContext nextEventContext = new TmfExperimentContext(context);
367 TmfEvent event = getNextEvent(nextEventContext);
9f584e4c 368 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
8f50c396 369 context = new TmfExperimentContext(nextEventContext);
54d55ced 370 event = getNextEvent(nextEventContext);
9f584e4c 371 }
8f50c396 372 context.setLastTrace(TmfExperimentContext.NO_TRACE);
9f584e4c 373
85fb0e54 374 return context;
9f584e4c 375 }
8c8bf09f 376
54d55ced
FC
377 /* (non-Javadoc)
378 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
379 */
9f584e4c
FC
380 public TmfExperimentContext seekEvent(long rank) {
381
54d55ced
FC
382 // Position the stream at the previous checkpoint
383 int index = (int) rank / fIndexPageSize;
384 ITmfLocation<?> location;
385 synchronized (fCheckpoints) {
386 if (fCheckpoints.size() == 0) {
387 location = null;
388 }
389 else {
390 if (index >= fCheckpoints.size()) {
391 index = fCheckpoints.size() - 1;
392 }
393 location = fCheckpoints.elementAt(index).getLocation();
394 }
395 }
e31e01e8 396
54d55ced 397 TmfExperimentContext context = seekLocation(location);
cbd4ad82 398 long pos = (long) index * fIndexPageSize;
54d55ced
FC
399 context.setRank(pos);
400
401 // And locate the event
402 TmfExperimentContext nextEventContext = new TmfExperimentContext(context);
403 TmfEvent event = getNextEvent(nextEventContext);
404 while (event != null && pos++ < rank) {
405 event = getNextEvent(nextEventContext);
406 context = new TmfExperimentContext(nextEventContext);
407 if (event != null) context.updateRank(-1);
408 }
8f50c396 409 context.setLastTrace(TmfExperimentContext.NO_TRACE);
9f584e4c 410
54d55ced 411 return context;
8c8bf09f
ASL
412 }
413
414 /**
415 * Scan the next events from all traces and return the next one
416 * in chronological order.
417 *
418 * @param context
419 * @return
420 */
9f584e4c 421 public synchronized TmfEvent getNextEvent(TmfContext context) {
54d55ced 422
8f50c396
FC
423 // Validate the context
424 if (!(context instanceof TmfExperimentContext)) {
425 return null; // Throw an exception?
426 }
54d55ced 427
8f50c396
FC
428 TmfExperimentContext expContext = (TmfExperimentContext) context;
429
430 // If an event was consumed previously, get the next one from that trace
431 int lastTrace = expContext.getLastTrace();
432 if (lastTrace != TmfExperimentContext.NO_TRACE) {
433 TmfContext traceContext = expContext.getContexts()[lastTrace];
434 expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext);
435 }
436
437 // Scan the candidate events and identify the "next" trace to read from
438 int trace = TmfExperimentContext.NO_TRACE;
439 TmfTimestamp timestamp = TmfTimestamp.BigCrunch;
440 for (int i = 0; i < expContext.getTraces().length; i++) {
441 TmfEvent event = expContext.getEvents()[i];
442 if (event != null && event.getTimestamp() != null) {
443 TmfTimestamp otherTS = event.getTimestamp();
444 if (otherTS.compareTo(timestamp, true) < 0) {
445 trace = i;
446 timestamp = otherTS;
8c8bf09f
ASL
447 }
448 }
449 }
8f50c396
FC
450
451 // Update the experiment context and set the "next" event
452 TmfEvent event = null;
453 if (trace >= 0) {
550d787e 454 long savedRank = expContext.getRank();
cb866e08 455 updateIndex(expContext, savedRank, timestamp);
8f50c396
FC
456 expContext.setLastTrace(trace);
457 expContext.updateRank(1);
458 TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
459 TmfContext traceContext = expContext.getContexts()[trace];
460 expLocation.getLocation()[trace] = traceContext.getLocation().clone();
461 expLocation.getRanks()[trace] = traceContext.getRank();
462 event = expContext.getEvents()[trace];
cb866e08 463// updateIndex(expContext, savedRank, timestamp);
8f50c396
FC
464 }
465
466 return event;
8c8bf09f
ASL
467 }
468
550d787e
FC
469 public synchronized void updateIndex(ITmfContext context, long rank, TmfTimestamp timestamp) {
470 // Build the index as we go along
471 if (context.isValidRank() && (rank % fIndexPageSize) == 0) {
472 // Determine the table position
473 long position = context.getRank() / fIndexPageSize;
474 // Add new entry at proper location (if empty)
475 if (fCheckpoints.size() == position) {
476 ITmfLocation<?> location = context.getLocation().clone();
477 fCheckpoints.add(new TmfCheckpoint(timestamp, location));
478// System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString());
479 }
480 }
481 }
482
54d55ced
FC
483 /* (non-Javadoc)
484 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools.tmf.trace.TmfContext)
485 */
9f584e4c 486 public TmfEvent parseEvent(TmfContext context) {
54d55ced 487
85fb0e54
FC
488 if (context instanceof TmfExperimentContext) {
489 TmfExperimentContext expContext = (TmfExperimentContext) context;
54d55ced
FC
490 int lastTrace = expContext.getLastTrace();
491 if (lastTrace != -1) {
492 TmfContext traceContext = expContext.getContexts()[lastTrace];
8f50c396 493 expContext.getEvents()[lastTrace] = expContext.getTraces()[lastTrace].getNextEvent(traceContext);
54d55ced
FC
494 expContext.updateRank(1);
495 TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
496 expLocation.getLocation()[lastTrace] = traceContext.getLocation().clone();
497 }
498
85fb0e54
FC
499 int trace = -1;
500 TmfTimestamp timestamp = TmfTimestamp.BigCrunch;
501 for (int i = 0; i < expContext.getTraces().length; i++) {
502 if (expContext.getEvents()[i] != null) {
503 if (expContext.getEvents()[i].getTimestamp() != null) {
504 TmfTimestamp otherTS = expContext.getEvents()[i].getTimestamp();
505 if (otherTS.compareTo(timestamp, true) < 0) {
506 trace = i;
507 timestamp = otherTS;
508 }
509 }
510 }
511 }
512 if (trace >= 0) {
8f50c396 513 expContext.setLastTrace(TmfExperimentContext.NO_TRACE);
85fb0e54
FC
514 return expContext.getEvents()[trace];
515 }
516 }
54d55ced
FC
517
518 return null;
8c8bf09f
ASL
519 }
520
521 /* (non-Javadoc)
522 * @see java.lang.Object#toString()
523 */
524 @Override
525 public String toString() {
ce785d7d 526 return "[TmfExperiment (" + getName() + ")]";
8c8bf09f
ASL
527 }
528
529 // ------------------------------------------------------------------------
530 // Indexing
531 // ------------------------------------------------------------------------
532
533 /*
534 * The experiment holds the globally ordered events of its set of traces.
535 * It is expected to provide access to each individual event by index i.e.
9f584e4c 536 * it must be possible to request the Nth event of the experiment.
8c8bf09f
ASL
537 *
538 * The purpose of the index is to keep the information needed to rapidly
539 * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
540 * event).
541 */
542
543 // The index page size
544 private static final int DEFAULT_INDEX_PAGE_SIZE = 1000;
550d787e 545 private final int fIndexPageSize;
e31e01e8 546
550d787e 547 @SuppressWarnings("unchecked")
cb866e08 548 private void indexExperiment(boolean waitForCompletion) {
550d787e 549
cb866e08 550// final TmfExperiment<?> experiment = getCurrentExperiment();
550d787e
FC
551 fCheckpoints.clear();
552
553 ITmfEventRequest<TmfEvent> request = new TmfEventRequest<TmfEvent>(TmfEvent.class, TmfTimeRange.Eternity, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.LONG) {
554
cb866e08 555// long indexingStart = System.nanoTime();
550d787e
FC
556
557 TmfTimestamp startTime = null;
558 TmfTimestamp lastTime = null;
cb866e08 559// int nbEvents = 0;
550d787e
FC
560
561 @Override
562 public void handleData() {
563 TmfEvent[] events = getData();
564 if (events.length > 0) {
cb866e08 565// nbEvents++;
550d787e
FC
566 TmfTimestamp ts = events[0].getTimestamp();
567 if (startTime == null)
568 startTime = new TmfTimestamp(ts);
569 lastTime = new TmfTimestamp(ts);
570
cb866e08 571 if ((fNbRead % DEFAULT_INDEX_PAGE_SIZE) == 0) {
550d787e
FC
572 updateExperiment();
573 }
574 }
9aae0442 575 }
e31e01e8 576
550d787e
FC
577 @Override
578 public void handleSuccess() {
cb866e08
FC
579// long indexingEnd = System.nanoTime();
580
581 updateExperiment();
582
583// System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" + (indexingEnd*1.0 - indexingStart) / 1000000000);
584// System.out.println(getName() + ": nbEvents=" + fNbEvents + "(" + ((indexingEnd-indexingStart)/nbEvents)+ " ns/evt)");
585
586// for (int i = 0; i < fCheckpoints.size(); i++) {
587// TmfCheckpoint checkpoint = fCheckpoints.get(i);
588// System.out.println("fCheckpoints[" + i + "] " + checkpoint.getTimestamp() + ", " + checkpoint.getLocation().toString());
589// }
e31e01e8
FC
590 }
591
550d787e 592 private void updateExperiment() {
cb866e08
FC
593// if (experiment == fCurrentExperiment) {
594// experiment.fTimeRange = new TmfTimeRange(startTime, new TmfTimestamp(lastTime));
595// experiment.fNbEvents = nbEvents;
596// experiment.fCheckpoints = ((TmfExperiment<T>) fClone).fCheckpoints;
597// notifyListeners();
598// }
599
600 fTimeRange = new TmfTimeRange(startTime, new TmfTimestamp(lastTime));
601 fNbEvents = fNbRead;
602 fCheckpoints = ((TmfExperiment<T>) fClone).fCheckpoints;
603 notifyListeners();
550d787e
FC
604 }
605 };
e31e01e8 606
550d787e 607 sendRequest((ITmfDataRequest<T>) request);
cb866e08
FC
608 if (waitForCompletion)
609 try {
610 request.waitForCompletion();
611 } catch (InterruptedException e) {
612 e.printStackTrace();
613 }
550d787e
FC
614 }
615
616 protected void notifyListeners() {
617 broadcast(new TmfExperimentUpdatedSignal(this, this, null));
9f584e4c
FC
618 }
619
8c8bf09f
ASL
620 // ------------------------------------------------------------------------
621 // Signal handlers
622 // ------------------------------------------------------------------------
623
624 @TmfSignalHandler
951d134a 625 public void experimentSelected(TmfExperimentSelectedSignal<T> signal) {
ff4ed569
FC
626 TmfExperiment<?> experiment = signal.getExperiment();
627 if (experiment == this) {
628 setCurrentExperiment(experiment);
cb866e08 629 indexExperiment(false);
ff4ed569
FC
630 }
631 else {
632 dispose();
633 }
8c8bf09f
ASL
634 }
635
636 @TmfSignalHandler
637 public void experimentUpdated(TmfExperimentUpdatedSignal signal) {
8c8bf09f
ASL
638 }
639
640 @TmfSignalHandler
641 public void traceUpdated(TmfTraceUpdatedSignal signal) {
642 // TODO: Incremental index update
643 synchronized(this) {
644 updateNbEvents();
645 updateTimeRange();
646 }
647 broadcast(new TmfExperimentUpdatedSignal(this, this, signal.getTrace()));
648 }
649
cb866e08
FC
650 @Override
651 public void queueResult(T data) throws InterruptedException {
652 super.queueResult(data);
653 }
654
8c8bf09f 655}
This page took 0.065415 seconds and 5 git commands to generate.