Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
0316808c | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
ce2388e0 | 3 | * |
8c8bf09f ASL |
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 | |
ce2388e0 | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
9e0640dc | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
a1091415 | 16 | import org.eclipse.core.resources.IFile; |
12c155f5 | 17 | import org.eclipse.core.resources.IProject; |
828e5592 | 18 | import org.eclipse.core.resources.IResource; |
9e0640dc FC |
19 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext; |
20 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; | |
21 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray; | |
72f1e62a | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 23 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
24 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
25 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
0316808c | 26 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
49e2f79a FC |
27 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; |
28 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; | |
1b70b6dc | 29 | import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal; |
6c13869b FC |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal; |
31 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentRangeUpdatedSignal; | |
32 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal; | |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentUpdatedSignal; | |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
c32744d6 | 35 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; |
8c8bf09f ASL |
36 | |
37 | /** | |
9e0640dc | 38 | * TmfExperiment presents a time-ordered, unified view of a set of ITmfTrace:s |
cbdacf03 | 39 | * that are part of a tracing experiment. |
4b7b3670 FC |
40 | * |
41 | * @version 1.0 | |
42 | * @author Francois Chouinard | |
8c8bf09f | 43 | */ |
0316808c | 44 | public class TmfExperiment<T extends ITmfEvent> extends TmfTrace<T> implements ITmfEventParser<T> { |
8c8bf09f | 45 | |
c32744d6 FC |
46 | // ------------------------------------------------------------------------ |
47 | // Constants | |
48 | // ------------------------------------------------------------------------ | |
49 | ||
9e0640dc FC |
50 | /** |
51 | * The default index page size | |
52 | */ | |
53 | public static final int DEFAULT_INDEX_PAGE_SIZE = 5000; | |
c32744d6 | 54 | |
8c8bf09f ASL |
55 | // ------------------------------------------------------------------------ |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
9e0640dc FC |
59 | /** |
60 | * The currently selected experiment (null if none) | |
61 | */ | |
c32744d6 | 62 | protected static TmfExperiment<?> fCurrentExperiment = null; |
e31e01e8 | 63 | |
9e0640dc FC |
64 | /** |
65 | * The set of traces that constitute the experiment | |
66 | */ | |
c32744d6 | 67 | protected ITmfTrace<T>[] fTraces; |
8c8bf09f | 68 | |
9e0640dc FC |
69 | /** |
70 | * The set of traces that constitute the experiment | |
71 | */ | |
72 | private boolean fInitialized = false; | |
a1091415 | 73 | |
9e0640dc FC |
74 | /** |
75 | * The experiment bookmarks file | |
76 | */ | |
77 | private IFile fBookmarksFile; | |
828e5592 | 78 | |
49e2f79a FC |
79 | |
80 | // Saved experiment context (optimization) | |
81 | private TmfExperimentContext fExperimentContext; | |
82 | ||
8c8bf09f | 83 | // ------------------------------------------------------------------------ |
9e0640dc | 84 | // Construction |
8c8bf09f ASL |
85 | // ------------------------------------------------------------------------ |
86 | ||
9e0640dc FC |
87 | /** |
88 | * @param type | |
89 | * @param id | |
90 | * @param traces | |
91 | * @throws TmfTraceException | |
92 | */ | |
93 | public TmfExperiment(final Class<T> type, final String id, final ITmfTrace<T>[] traces) { | |
94 | this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE); | |
96c6806f PT |
95 | } |
96 | ||
8c8bf09f ASL |
97 | /** |
98 | * @param type | |
99 | * @param id | |
100 | * @param traces | |
8c8bf09f | 101 | * @param indexPageSize |
0316808c | 102 | * @throws TmfTraceException |
8c8bf09f | 103 | */ |
0316808c | 104 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
9e0640dc | 105 | public TmfExperiment(final Class<T> type, final String path, final ITmfTrace<T>[] traces, final int indexPageSize) { |
0316808c FC |
106 | setCacheSize(indexPageSize); |
107 | setStreamingInterval(0); | |
07671572 | 108 | setIndexer(new TmfCheckpointIndexer(this, indexPageSize)); |
0316808c FC |
109 | setParser(this); |
110 | try { | |
111 | super.initialize(null, path, type); | |
112 | } catch (TmfTraceException e) { | |
113 | e.printStackTrace(); | |
114 | } | |
8c8bf09f | 115 | |
a79913eb | 116 | fTraces = traces; |
a87cc4ef | 117 | setTimeRange(TmfTimeRange.NULL_RANGE); |
8c8bf09f | 118 | } |
a79913eb | 119 | |
8c8bf09f | 120 | /** |
ff4ed569 | 121 | * Clears the experiment |
8c8bf09f ASL |
122 | */ |
123 | @Override | |
12c155f5 | 124 | @SuppressWarnings("rawtypes") |
a79913eb FC |
125 | public synchronized void dispose() { |
126 | ||
cbdacf03 | 127 | final TmfExperimentDisposedSignal<T> signal = new TmfExperimentDisposedSignal<T>(this, this); |
a79913eb | 128 | broadcast(signal); |
9e0640dc FC |
129 | |
130 | if (fCurrentExperiment == this) { | |
09d11238 | 131 | fCurrentExperiment = null; |
9e0640dc | 132 | } |
a79913eb | 133 | |
b5ee6881 FC |
134 | // Clean up the index |
135 | getIndexer().dispose(); | |
136 | ||
a79913eb | 137 | if (fTraces != null) { |
cbdacf03 | 138 | for (final ITmfTrace trace : fTraces) |
a79913eb | 139 | trace.dispose(); |
a79913eb FC |
140 | fTraces = null; |
141 | } | |
2fb2eb37 | 142 | super.dispose(); |
8c8bf09f ASL |
143 | } |
144 | ||
9e0640dc FC |
145 | // ------------------------------------------------------------------------ |
146 | // ITmfTrace - Initializers | |
147 | // ------------------------------------------------------------------------ | |
148 | ||
149 | /* (non-Javadoc) | |
150 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String) | |
151 | */ | |
152 | @Override | |
153 | public boolean validate(final IProject project, final String path) { | |
154 | return true; | |
155 | } | |
156 | ||
157 | /* (non-Javadoc) | |
158 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class) | |
159 | */ | |
160 | @Override | |
161 | public void initTrace(final IResource resource, final String path, final Class<T> type) { | |
162 | } | |
163 | ||
8c8bf09f | 164 | // ------------------------------------------------------------------------ |
e31e01e8 | 165 | // Accessors |
8c8bf09f ASL |
166 | // ------------------------------------------------------------------------ |
167 | ||
9e0640dc FC |
168 | /** |
169 | * Selects the current, framework-wide, experiment | |
170 | * | |
171 | * @param experiment das experiment | |
172 | */ | |
cbdacf03 | 173 | public static void setCurrentExperiment(final TmfExperiment<?> experiment) { |
9e0640dc | 174 | if (fCurrentExperiment != null && fCurrentExperiment != experiment) { |
09d11238 | 175 | fCurrentExperiment.dispose(); |
9e0640dc | 176 | } |
a79913eb | 177 | fCurrentExperiment = experiment; |
f6b14ce2 FC |
178 | } |
179 | ||
9e0640dc FC |
180 | /** |
181 | * @return das experiment | |
182 | */ | |
e31e01e8 | 183 | public static TmfExperiment<?> getCurrentExperiment() { |
a79913eb | 184 | return fCurrentExperiment; |
8c8bf09f ASL |
185 | } |
186 | ||
9e0640dc FC |
187 | /** |
188 | * Get the list of traces. Handle with care... | |
189 | * | |
190 | * @return the experiment traces | |
191 | */ | |
12c155f5 | 192 | public ITmfTrace<T>[] getTraces() { |
a79913eb | 193 | return fTraces; |
8c8bf09f ASL |
194 | } |
195 | ||
8c8bf09f | 196 | /** |
cbdacf03 FC |
197 | * Returns the timestamp of the event at the requested index. If none, |
198 | * returns null. | |
a79913eb | 199 | * |
0d9a6d76 FC |
200 | * @param index the event index (rank) |
201 | * @return the corresponding event timestamp | |
8c8bf09f | 202 | */ |
cbdacf03 | 203 | public ITmfTimestamp getTimestamp(final int index) { |
0316808c | 204 | final ITmfContext context = seekEvent(index); |
c32744d6 | 205 | final ITmfEvent event = getNext(context); |
a79913eb | 206 | return (event != null) ? event.getTimestamp() : null; |
8c8bf09f ASL |
207 | } |
208 | ||
9e0640dc FC |
209 | /** |
210 | * Set the file to be used for bookmarks on this experiment | |
211 | * | |
212 | * @param file the bookmarks file | |
213 | */ | |
214 | public void setBookmarksFile(final IFile file) { | |
215 | fBookmarksFile = file; | |
216 | } | |
07671572 | 217 | |
9e0640dc FC |
218 | /** |
219 | * Get the file used for bookmarks on this experiment | |
220 | * | |
221 | * @return the bookmarks file or null if none is set | |
222 | */ | |
223 | public IFile getBookmarksFile() { | |
224 | return fBookmarksFile; | |
a79913eb FC |
225 | } |
226 | ||
49e2f79a FC |
227 | // ------------------------------------------------------------------------ |
228 | // Request management | |
229 | // ------------------------------------------------------------------------ | |
230 | ||
231 | @Override | |
232 | protected ITmfContext armRequest(final ITmfDataRequest<T> request) { | |
233 | if (request instanceof ITmfEventRequest<?> | |
234 | && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime()) | |
235 | && request.getIndex() == 0) | |
236 | { | |
237 | final ITmfContext context = seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime()); | |
238 | ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank()); | |
239 | return context; | |
240 | ||
241 | } | |
242 | ||
243 | // Check if we are already at the right index | |
244 | if ((fExperimentContext != null) && fExperimentContext.getRank() == request.getIndex()) { | |
245 | return fExperimentContext; | |
246 | } | |
247 | ||
248 | return seekEvent(request.getIndex()); | |
249 | } | |
250 | ||
a79913eb | 251 | // ------------------------------------------------------------------------ |
9f584e4c FC |
252 | // ITmfTrace trace positioning |
253 | // ------------------------------------------------------------------------ | |
254 | ||
9e0640dc FC |
255 | /* (non-Javadoc) |
256 | * | |
257 | * Returns a brand new context based on the location provided and | |
258 | * initializes the event queues | |
259 | * | |
260 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) | |
261 | */ | |
a79913eb | 262 | @Override |
9e0640dc | 263 | public synchronized ITmfContext seekEvent(final ITmfLocation<?> location) { |
a79913eb | 264 | // Validate the location |
9e0640dc | 265 | if (location != null && !(location instanceof TmfExperimentLocation)) { |
a79913eb | 266 | return null; // Throw an exception? |
9e0640dc FC |
267 | } |
268 | // Make sure we have something to read from | |
269 | if (fTraces == null) { | |
a79913eb | 270 | return null; |
9e0640dc | 271 | } |
8f50c396 | 272 | |
a79913eb | 273 | // Instantiate the location |
9e0640dc FC |
274 | final TmfExperimentLocation expLocation = (location == null) |
275 | ? new TmfExperimentLocation(new TmfLocationArray(new ITmfLocation<?>[fTraces.length])) | |
276 | : (TmfExperimentLocation) location.clone(); | |
8f50c396 | 277 | |
a79913eb | 278 | // Create and populate the context's traces contexts |
0316808c | 279 | final TmfExperimentContext context = new TmfExperimentContext(new ITmfContext[fTraces.length]); |
9b635e61 | 280 | |
a79913eb FC |
281 | for (int i = 0; i < fTraces.length; i++) { |
282 | // Get the relevant trace attributes | |
0316808c | 283 | final ITmfLocation<?> traceLocation = expLocation.getLocation().getLocations()[i]; |
7e6347b0 | 284 | context.getContexts()[i] = fTraces[i].seekEvent(traceLocation); |
0316808c | 285 | expLocation.getLocation().getLocations()[i] = context.getContexts()[i].getLocation().clone(); |
c32744d6 | 286 | context.getEvents()[i] = fTraces[i].getNext(context.getContexts()[i]); |
a79913eb | 287 | } |
8f50c396 | 288 | |
a79913eb FC |
289 | // Finalize context |
290 | context.setLocation(expLocation); | |
291 | context.setLastTrace(TmfExperimentContext.NO_TRACE); | |
0316808c | 292 | context.setRank(ITmfContext.UNKNOWN_RANK); |
49e2f79a FC |
293 | |
294 | fExperimentContext = context; | |
295 | ||
9e0640dc | 296 | return (ITmfContext) context; |
a79913eb | 297 | } |
9f584e4c | 298 | |
9e0640dc FC |
299 | /* (non-Javadoc) |
300 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(double) | |
301 | */ | |
c76c54bb | 302 | @Override |
0316808c FC |
303 | public ITmfContext seekEvent(final double ratio) { |
304 | final ITmfContext context = seekEvent((long) (ratio * getNbEvents())); | |
c76c54bb FC |
305 | return context; |
306 | } | |
307 | ||
9e0640dc FC |
308 | /* (non-Javadoc) |
309 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getLocationRatio(org.eclipse.linuxtools.tmf.core.trace.ITmfLocation) | |
310 | */ | |
a79913eb | 311 | @Override |
cbdacf03 | 312 | public double getLocationRatio(final ITmfLocation<?> location) { |
9e0640dc | 313 | if (location instanceof TmfExperimentLocation) { |
7e6347b0 | 314 | return (double) seekEvent(location).getRank() / getNbEvents(); |
9e0640dc FC |
315 | } |
316 | return 0.0; | |
c76c54bb FC |
317 | } |
318 | ||
9e0640dc FC |
319 | /* (non-Javadoc) |
320 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation() | |
321 | */ | |
a79913eb FC |
322 | @Override |
323 | public ITmfLocation<?> getCurrentLocation() { | |
a87cc4ef FC |
324 | ITmfLocation<?>[] locations = new ITmfLocation<?>[fTraces.length]; |
325 | for (int i = 0; i < fTraces.length; i++) { | |
326 | locations[i] = fTraces[i].getCurrentLocation(); | |
327 | } | |
328 | return new TmfExperimentLocation(new TmfLocationArray(locations)); | |
a79913eb | 329 | } |
c76c54bb | 330 | |
9e0640dc FC |
331 | // ------------------------------------------------------------------------ |
332 | // ITmfTrace trace positioning | |
333 | // ------------------------------------------------------------------------ | |
334 | ||
07671572 | 335 | /* (non-Javadoc) |
9e0640dc | 336 | * @see org.eclipse.linuxtools.tmf.core.trace.TmfTrace#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
07671572 FC |
337 | */ |
338 | @Override | |
c32744d6 | 339 | public synchronized T getNext(final ITmfContext context) { |
a0a4901e | 340 | final ITmfContext previousContext = (TmfExperimentContext) context.clone(); |
c32744d6 | 341 | final T event = parseEvent(context); |
07671572 | 342 | if (event != null) { |
a0a4901e | 343 | updateAttributes(previousContext, event.getTimestamp()); |
07671572 | 344 | |
49e2f79a FC |
345 | fExperimentContext = (TmfExperimentContext) context; |
346 | int trace = fExperimentContext.getLastTrace(); | |
07671572 | 347 | if (trace != TmfExperimentContext.NO_TRACE) { |
49e2f79a FC |
348 | TmfExperimentLocation location = (TmfExperimentLocation) fExperimentContext.getLocation(); |
349 | location.getLocation().getLocations()[trace] = fExperimentContext.getContexts()[trace].getLocation(); | |
07671572 FC |
350 | } |
351 | ||
352 | context.increaseRank(); | |
353 | processEvent(event); | |
354 | } | |
355 | return event; | |
356 | } | |
a79913eb | 357 | |
ce2388e0 | 358 | /* (non-Javadoc) |
9e0640dc | 359 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser#parseEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
a79913eb | 360 | */ |
0316808c FC |
361 | @SuppressWarnings("unchecked") |
362 | @Override | |
a87cc4ef | 363 | public T parseEvent(ITmfContext context) { |
a79913eb FC |
364 | |
365 | // Validate the context | |
9e0640dc | 366 | if (!(context instanceof TmfExperimentContext)) { |
a79913eb | 367 | return null; // Throw an exception? |
9e0640dc | 368 | } |
a79913eb | 369 | |
a87cc4ef | 370 | TmfExperimentContext expContext = (TmfExperimentContext) context; |
a79913eb | 371 | |
a87cc4ef | 372 | // If an event was consumed previously, first get the next one from that trace |
cbdacf03 | 373 | final int lastTrace = expContext.getLastTrace(); |
a79913eb | 374 | if (lastTrace != TmfExperimentContext.NO_TRACE) { |
cbdacf03 | 375 | final ITmfContext traceContext = expContext.getContexts()[lastTrace]; |
c32744d6 | 376 | expContext.getEvents()[lastTrace] = fTraces[lastTrace].getNext(traceContext); |
a79913eb | 377 | expContext.setLastTrace(TmfExperimentContext.NO_TRACE); |
a79913eb FC |
378 | } |
379 | ||
380 | // Scan the candidate events and identify the "next" trace to read from | |
381 | int trace = TmfExperimentContext.NO_TRACE; | |
a4115405 | 382 | ITmfTimestamp timestamp = TmfTimestamp.BIG_CRUNCH; |
0316808c | 383 | for (int i = 0; i < fTraces.length; i++) { |
cbdacf03 | 384 | final ITmfEvent event = expContext.getEvents()[i]; |
a79913eb | 385 | if (event != null && event.getTimestamp() != null) { |
cbdacf03 | 386 | final ITmfTimestamp otherTS = event.getTimestamp(); |
a79913eb FC |
387 | if (otherTS.compareTo(timestamp, true) < 0) { |
388 | trace = i; | |
389 | timestamp = otherTS; | |
390 | } | |
391 | } | |
392 | } | |
a87cc4ef FC |
393 | |
394 | T event = null; | |
07671572 | 395 | if (trace != TmfExperimentContext.NO_TRACE) { |
a87cc4ef | 396 | event = (T) expContext.getEvents()[trace]; |
07671572 | 397 | } |
a87cc4ef | 398 | |
a87cc4ef FC |
399 | expContext.setLastTrace(trace); |
400 | return event; | |
a79913eb FC |
401 | } |
402 | ||
bcbea6a6 | 403 | /* (non-Javadoc) |
a79913eb FC |
404 | * @see java.lang.Object#toString() |
405 | */ | |
406 | @Override | |
3b38ea61 | 407 | @SuppressWarnings("nls") |
a79913eb FC |
408 | public String toString() { |
409 | return "[TmfExperiment (" + getName() + ")]"; | |
410 | } | |
8c8bf09f ASL |
411 | |
412 | // ------------------------------------------------------------------------ | |
9e0640dc | 413 | // Streaming support |
8c8bf09f ASL |
414 | // ------------------------------------------------------------------------ |
415 | ||
1b70b6dc | 416 | private synchronized void initializeStreamingMonitor() { |
9e0640dc FC |
417 | |
418 | if (fInitialized) { | |
828e5592 | 419 | return; |
9e0640dc | 420 | } |
828e5592 PT |
421 | fInitialized = true; |
422 | ||
1b70b6dc | 423 | if (getStreamingInterval() == 0) { |
0316808c | 424 | final ITmfContext context = seekEvent(0); |
cbdacf03 FC |
425 | final ITmfEvent event = getNext(context); |
426 | if (event == null) | |
1b70b6dc | 427 | return; |
cbdacf03 | 428 | final TmfTimeRange timeRange = new TmfTimeRange(event.getTimestamp().clone(), TmfTimestamp.BIG_CRUNCH); |
828e5592 PT |
429 | final TmfExperimentRangeUpdatedSignal signal = new TmfExperimentRangeUpdatedSignal(this, this, timeRange); |
430 | ||
431 | // Broadcast in separate thread to prevent deadlock | |
432 | new Thread() { | |
433 | @Override | |
434 | public void run() { | |
435 | broadcast(signal); | |
436 | } | |
437 | }.start(); | |
1b70b6dc PT |
438 | return; |
439 | } | |
440 | ||
9e0640dc | 441 | final Thread thread = new Thread("Streaming Monitor for experiment " + getName()) { //$NON-NLS-1$ |
bcbea6a6 FC |
442 | private ITmfTimestamp safeTimestamp = null; |
443 | private TmfTimeRange timeRange = null; | |
1b70b6dc PT |
444 | |
445 | @Override | |
446 | public void run() { | |
447 | while (!fExecutor.isShutdown()) { | |
9e0640dc | 448 | if (!getIndexer().isIndexing()) { |
a4115405 FC |
449 | ITmfTimestamp startTimestamp = TmfTimestamp.BIG_CRUNCH; |
450 | ITmfTimestamp endTimestamp = TmfTimestamp.BIG_BANG; | |
cbdacf03 FC |
451 | for (final ITmfTrace<T> trace : fTraces) { |
452 | if (trace.getStartTime().compareTo(startTimestamp) < 0) | |
1b70b6dc | 453 | startTimestamp = trace.getStartTime(); |
cbdacf03 | 454 | if (trace.getStreamingInterval() != 0 && trace.getEndTime().compareTo(endTimestamp) > 0) |
1b70b6dc | 455 | endTimestamp = trace.getEndTime(); |
1b70b6dc | 456 | } |
cbdacf03 | 457 | if (safeTimestamp != null && safeTimestamp.compareTo(getTimeRange().getEndTime(), false) > 0) |
1b70b6dc | 458 | timeRange = new TmfTimeRange(startTimestamp, safeTimestamp); |
cbdacf03 | 459 | else |
1b70b6dc | 460 | timeRange = null; |
1b70b6dc PT |
461 | safeTimestamp = endTimestamp; |
462 | if (timeRange != null) { | |
cbdacf03 | 463 | final TmfExperimentRangeUpdatedSignal signal = |
1b70b6dc PT |
464 | new TmfExperimentRangeUpdatedSignal(TmfExperiment.this, TmfExperiment.this, timeRange); |
465 | broadcast(signal); | |
466 | } | |
467 | } | |
468 | try { | |
469 | Thread.sleep(getStreamingInterval()); | |
cbdacf03 | 470 | } catch (final InterruptedException e) { |
1b70b6dc PT |
471 | e.printStackTrace(); |
472 | } | |
473 | } | |
474 | } | |
475 | }; | |
476 | thread.start(); | |
477 | } | |
478 | ||
9e0640dc | 479 | /* (non-Javadoc) |
1b70b6dc PT |
480 | * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval() |
481 | */ | |
482 | @Override | |
483 | public long getStreamingInterval() { | |
484 | long interval = 0; | |
cbdacf03 | 485 | for (final ITmfTrace<T> trace : fTraces) |
1b70b6dc | 486 | interval = Math.max(interval, trace.getStreamingInterval()); |
1b70b6dc PT |
487 | return interval; |
488 | } | |
489 | ||
8c8bf09f ASL |
490 | // ------------------------------------------------------------------------ |
491 | // Signal handlers | |
492 | // ------------------------------------------------------------------------ | |
493 | ||
9e0640dc | 494 | private Integer fEndSynchReference; |
c32744d6 | 495 | |
9e0640dc FC |
496 | /** |
497 | * Signal handler for the TmfExperimentSelectedSignal signal | |
498 | * | |
499 | * @param signal | |
500 | */ | |
8c8bf09f | 501 | @TmfSignalHandler |
cbdacf03 FC |
502 | public void experimentSelected(final TmfExperimentSelectedSignal<T> signal) { |
503 | final TmfExperiment<?> experiment = signal.getExperiment(); | |
a79913eb FC |
504 | if (experiment == this) { |
505 | setCurrentExperiment(experiment); | |
6e85c58d | 506 | fEndSynchReference = Integer.valueOf(signal.getReference()); |
a79913eb | 507 | } |
8c8bf09f ASL |
508 | } |
509 | ||
9e0640dc FC |
510 | /** |
511 | * Signal handler for the TmfEndSynchSignal signal | |
512 | * | |
513 | * @param signal | |
514 | */ | |
1b70b6dc | 515 | @TmfSignalHandler |
cbdacf03 | 516 | public void endSync(final TmfEndSynchSignal signal) { |
1b70b6dc PT |
517 | if (fEndSynchReference != null && fEndSynchReference.intValue() == signal.getReference()) { |
518 | fEndSynchReference = null; | |
519 | initializeStreamingMonitor(); | |
520 | } | |
1b70b6dc PT |
521 | } |
522 | ||
828e5592 | 523 | /** |
9e0640dc | 524 | * Signal handler for the TmfTraceUpdatedSignal signal |
cbdacf03 | 525 | * |
9e0640dc | 526 | * @param signal |
828e5592 | 527 | */ |
9e0640dc FC |
528 | @TmfSignalHandler |
529 | public void traceUpdated(final TmfTraceUpdatedSignal signal) { | |
530 | if (signal.getTrace() == this) { | |
531 | broadcast(new TmfExperimentUpdatedSignal(this, this)); | |
532 | } | |
a1091415 PT |
533 | } |
534 | ||
535 | /** | |
9e0640dc | 536 | * Signal handler for the TmfExperimentRangeUpdatedSignal signal |
cbdacf03 | 537 | * |
9e0640dc | 538 | * @param signal |
a1091415 | 539 | */ |
9e0640dc FC |
540 | @TmfSignalHandler |
541 | public void experimentRangeUpdated(final TmfExperimentRangeUpdatedSignal signal) { | |
542 | if (signal.getExperiment() == this) { | |
543 | getIndexer().buildIndex(getNbEvents(), signal.getRange(), false); | |
544 | } | |
a1091415 PT |
545 | } |
546 | ||
4dc47e28 | 547 | } |