tmf: Fix regression in event requests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.trace;
15
16 import java.io.File;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IPath;
24 import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
25 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
26 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
27 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
28 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
29 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
30 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
31 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
32 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
33 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
34 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
35 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
36 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
37 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
38 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
39 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
40
41 /**
42 * Abstract implementation of ITmfTrace.
43 * <p>
44 * Since the concept of 'location' is trace specific, the concrete classes have
45 * to provide the related methods, namely:
46 * <ul>
47 * <li> public ITmfLocation<?> getCurrentLocation()
48 * <li> public double getLocationRatio(ITmfLocation<?> location)
49 * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
50 * <li> public ITmfContext seekEvent(double ratio)
51 * <li> public boolean validate(IProject project, String path)
52 * </ul>
53 * A concrete trace must provide its corresponding parser. A common way to
54 * accomplish this is by making the concrete class extend TmfTrace and
55 * implement ITmfEventParser.
56 * <p>
57 * The concrete class can either specify its own indexer or use the provided
58 * TmfCheckpointIndexer (default). In this case, the trace cache size will be
59 * used as checkpoint interval.
60 *
61 * @version 1.0
62 * @author Francois Chouinard
63 *
64 * @see ITmfEvent
65 * @see ITmfTraceIndexer
66 * @see ITmfEventParser
67 */
68 public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
69
70 // ------------------------------------------------------------------------
71 // Attributes
72 // ------------------------------------------------------------------------
73
74 // The resource used for persistent properties for this trace
75 private IResource fResource;
76
77 // The trace path
78 private String fPath;
79
80 // The trace cache page size
81 private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
82
83 // The number of events collected (so far)
84 private long fNbEvents = 0;
85
86 // The time span of the event stream
87 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
88 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
89
90 // The trace streaming interval (0 = no streaming)
91 private long fStreamingInterval = 0;
92
93 // The trace indexer
94 private ITmfTraceIndexer fIndexer;
95
96 // The trace parser
97 private ITmfEventParser fParser;
98
99 // The trace's statistics
100 private ITmfStatistics fStatistics;
101
102 // The current selected time
103 private ITmfTimestamp fCurrentTime = TmfTimestamp.ZERO;
104
105 // The current selected range
106 private TmfTimeRange fCurrentRange = TmfTimeRange.NULL_RANGE;
107
108 /**
109 * The collection of state systems that are registered with this trace. Each
110 * sub-class can decide to add its (one or many) state system to this map
111 * during their {@link #buildStateSystem()}.
112 *
113 * @since 2.0
114 */
115 protected final Map<String, ITmfStateSystem> fStateSystems =
116 new HashMap<String, ITmfStateSystem>();
117
118 // ------------------------------------------------------------------------
119 // Construction
120 // ------------------------------------------------------------------------
121
122 /**
123 * The default, parameterless, constructor
124 */
125 public TmfTrace() {
126 super();
127 }
128
129 /**
130 * The standard constructor (non-live trace). Applicable when the trace
131 * implements its own parser and if at checkpoint-based index is OK.
132 *
133 * @param resource the resource associated to the trace
134 * @param type the trace event type
135 * @param path the trace path
136 * @param cacheSize the trace cache size
137 * @throws TmfTraceException If something failed during the opening
138 */
139 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException {
140 this(resource, type, path, cacheSize, 0);
141 }
142
143 /**
144 * The standard constructor (live trace). Applicable when the trace
145 * implements its own parser and if at checkpoint-based index is OK.
146 *
147 * @param resource the resource associated to the trace
148 * @param type the trace event type
149 * @param path the trace path
150 * @param cacheSize the trace cache size
151 * @param interval the trace streaming interval
152 * @throws TmfTraceException If something failed during the opening
153 */
154 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
155 this(resource, type, path, cacheSize, interval, null);
156 }
157
158 /**
159 * The 'non-default indexer' constructor. Allows to provide a trace
160 * specific indexer.
161 *
162 * @param resource the resource associated to the trace
163 * @param type the trace event type
164 * @param path the trace path
165 * @param cacheSize the trace cache size
166 * @param interval the trace streaming interval
167 * @param indexer the trace indexer
168 * @throws TmfTraceException If something failed during the opening
169 */
170 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
171 final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException {
172 this(resource, type, path, cacheSize, interval, indexer, null);
173 }
174
175 /**
176 * The full constructor where trace specific indexer/parser are provided.
177 *
178 * @param resource the resource associated to the trace
179 * @param type the trace event type
180 * @param path the trace path
181 * @param cacheSize the trace cache size
182 * @param interval the trace streaming interval
183 * @param indexer the trace indexer
184 * @param parser the trace event parser
185 * @throws TmfTraceException If something failed during the opening
186 */
187 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
188 final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException {
189 super();
190 fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
191 fStreamingInterval = interval;
192 fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
193 fParser = parser;
194 initialize(resource, path, type);
195 }
196
197 /**
198 * Copy constructor
199 *
200 * @param trace the original trace
201 * @throws TmfTraceException Should not happen usually
202 */
203 public TmfTrace(final TmfTrace trace) throws TmfTraceException {
204 super();
205 if (trace == null) {
206 throw new IllegalArgumentException();
207 }
208 fCacheSize = trace.getCacheSize();
209 fStreamingInterval = trace.getStreamingInterval();
210 fIndexer = new TmfCheckpointIndexer(this);
211 fParser = trace.fParser;
212 initialize(trace.getResource(), trace.getPath(), trace.getEventType());
213 }
214
215 // ------------------------------------------------------------------------
216 // ITmfTrace - Initializers
217 // ------------------------------------------------------------------------
218
219 /* (non-Javadoc)
220 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class)
221 */
222 @Override
223 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
224 fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
225 initialize(resource, path, type);
226 }
227
228 /**
229 * Initialize the trace common attributes and the base component.
230 *
231 * @param resource the Eclipse resource (trace)
232 * @param path the trace path
233 * @param type the trace event type
234 *
235 * @throws TmfTraceException If something failed during the initialization
236 */
237 protected void initialize(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
238 if (path == null) {
239 throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
240 }
241 fPath = path;
242 fResource = resource;
243 String traceName = (resource != null) ? resource.getName() : null;
244 // If no resource was provided, extract the display name the trace path
245 if (traceName == null) {
246 final int sep = path.lastIndexOf(IPath.SEPARATOR);
247 traceName = (sep >= 0) ? path.substring(sep + 1) : path;
248 }
249 if (fParser == null) {
250 if (this instanceof ITmfEventParser) {
251 fParser = (ITmfEventParser) this;
252 } else {
253 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
254 }
255 }
256 super.init(traceName, type);
257 }
258
259 /**
260 * Indicates if the path points to an existing file/directory
261 *
262 * @param path the path to test
263 * @return true if the file/directory exists
264 */
265 protected boolean fileExists(final String path) {
266 final File file = new File(path);
267 return file.exists();
268 }
269
270 /**
271 * Index the trace
272 *
273 * @param waitForCompletion index synchronously (true) or not (false)
274 */
275 protected void indexTrace(boolean waitForCompletion) {
276 getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
277 }
278
279 /**
280 * The default implementation of TmfTrace uses a TmfStatistics back-end.
281 * Override this if you want to specify another type (or none at all).
282 *
283 * @throws TmfTraceException
284 * If there was a problem setting up the statistics
285 * @since 2.0
286 */
287 protected void buildStatistics() throws TmfTraceException {
288 /*
289 * Initialize the statistics provider, but only if a Resource has been
290 * set (so we don't build it for experiments, for unit tests, etc.)
291 */
292 fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
293 }
294
295 /**
296 * Build the state system(s) associated with this trace type.
297 *
298 * Suppressing the warning, because the 'throws' will usually happen in
299 * sub-classes.
300 *
301 * @throws TmfTraceException
302 * If there is a problem during the build
303 * @since 2.0
304 */
305 @SuppressWarnings("unused")
306 protected void buildStateSystem() throws TmfTraceException {
307 /*
308 * Nothing is done in the base implementation, please specify
309 * how/if to register a new state system in derived classes.
310 */
311 return;
312 }
313
314 /**
315 * Clears the trace
316 */
317 @Override
318 public synchronized void dispose() {
319 /* Clean up the index if applicable */
320 if (getIndexer() != null) {
321 getIndexer().dispose();
322 }
323
324 /* Clean up the statistics */
325 if (fStatistics != null) {
326 fStatistics.dispose();
327 }
328
329 /* Clean up the state systems */
330 for (ITmfStateSystem ss : fStateSystems.values()) {
331 ss.dispose();
332 }
333
334 super.dispose();
335 }
336
337 // ------------------------------------------------------------------------
338 // ITmfTrace - Basic getters
339 // ------------------------------------------------------------------------
340
341 /* (non-Javadoc)
342 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
343 */
344 @Override
345 public Class<ITmfEvent> getEventType() {
346 return (Class<ITmfEvent>) super.getType();
347 }
348
349 /* (non-Javadoc)
350 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
351 */
352 @Override
353 public IResource getResource() {
354 return fResource;
355 }
356
357 /* (non-Javadoc)
358 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
359 */
360 @Override
361 public String getPath() {
362 return fPath;
363 }
364
365 /* (non-Javadoc)
366 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
367 */
368 @Override
369 public int getCacheSize() {
370 return fCacheSize;
371 }
372
373 /* (non-Javadoc)
374 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
375 */
376 @Override
377 public long getStreamingInterval() {
378 return fStreamingInterval;
379 }
380
381 /**
382 * @return the trace indexer
383 */
384 protected ITmfTraceIndexer getIndexer() {
385 return fIndexer;
386 }
387
388 /**
389 * @return the trace parser
390 */
391 protected ITmfEventParser getParser() {
392 return fParser;
393 }
394
395 /**
396 * @since 2.0
397 */
398 @Override
399 public ITmfStatistics getStatistics() {
400 return fStatistics;
401 }
402
403 /**
404 * @since 2.0
405 */
406 @Override
407 public final ITmfStateSystem getStateSystem(String id) {
408 return fStateSystems.get(id);
409 }
410
411 /**
412 * @since 2.0
413 */
414 @Override
415 public final Collection<String> listStateSystems() {
416 return fStateSystems.keySet();
417 }
418
419 // ------------------------------------------------------------------------
420 // ITmfTrace - Trace characteristics getters
421 // ------------------------------------------------------------------------
422
423 /* (non-Javadoc)
424 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
425 */
426 @Override
427 public synchronized long getNbEvents() {
428 return fNbEvents;
429 }
430
431 /* (non-Javadoc)
432 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange()
433 */
434 @Override
435 public TmfTimeRange getTimeRange() {
436 return new TmfTimeRange(fStartTime, fEndTime);
437 }
438
439 /* (non-Javadoc)
440 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime()
441 */
442 @Override
443 public ITmfTimestamp getStartTime() {
444 return fStartTime;
445 }
446
447 /* (non-Javadoc)
448 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime()
449 */
450 @Override
451 public ITmfTimestamp getEndTime() {
452 return fEndTime;
453 }
454
455 /* (non-Javadoc)
456 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentTime()
457 */
458 /**
459 * @since 2.0
460 */
461 @Override
462 public ITmfTimestamp getCurrentTime() {
463 return fCurrentTime;
464 }
465
466 /* (non-Javadoc)
467 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentRange()
468 */
469 /**
470 * @since 2.0
471 */
472 @Override
473 public TmfTimeRange getCurrentRange() {
474 return fCurrentRange;
475 }
476
477 /*
478 * (non-Javadoc)
479 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getInitialRangeOffset()
480 */
481 /**
482 * @since 2.0
483 */
484 @Override
485 public ITmfTimestamp getInitialRangeOffset() {
486 final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
487 return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
488 }
489
490 // ------------------------------------------------------------------------
491 // Convenience setters
492 // ------------------------------------------------------------------------
493
494 /**
495 * Set the trace cache size. Must be done at initialization time.
496 *
497 * @param cacheSize The trace cache size
498 */
499 protected void setCacheSize(final int cacheSize) {
500 fCacheSize = cacheSize;
501 }
502
503 /**
504 * Set the trace known number of events. This can be quite dynamic
505 * during indexing or for live traces.
506 *
507 * @param nbEvents The number of events
508 */
509 protected synchronized void setNbEvents(final long nbEvents) {
510 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
511 }
512
513 /**
514 * Update the trace events time range
515 *
516 * @param range the new time range
517 */
518 protected void setTimeRange(final TmfTimeRange range) {
519 fStartTime = range.getStartTime();
520 fEndTime = range.getEndTime();
521 }
522
523 /**
524 * Update the trace chronologically first event timestamp
525 *
526 * @param startTime the new first event timestamp
527 */
528 protected void setStartTime(final ITmfTimestamp startTime) {
529 fStartTime = startTime;
530 }
531
532 /**
533 * Update the trace chronologically last event timestamp
534 *
535 * @param endTime the new last event timestamp
536 */
537 protected void setEndTime(final ITmfTimestamp endTime) {
538 fEndTime = endTime;
539 }
540
541 /**
542 * Set the polling interval for live traces (default = 0 = no streaming).
543 *
544 * @param interval the new trace streaming interval
545 */
546 protected void setStreamingInterval(final long interval) {
547 fStreamingInterval = (interval > 0) ? interval : 0;
548 }
549
550 /**
551 * Set the trace indexer. Must be done at initialization time.
552 *
553 * @param indexer the trace indexer
554 */
555 protected void setIndexer(final ITmfTraceIndexer indexer) {
556 fIndexer = indexer;
557 }
558
559 /**
560 * Set the trace parser. Must be done at initialization time.
561 *
562 * @param parser the new trace parser
563 */
564 protected void setParser(final ITmfEventParser parser) {
565 fParser = parser;
566 }
567
568 // ------------------------------------------------------------------------
569 // ITmfTrace - SeekEvent operations (returning a trace context)
570 // ------------------------------------------------------------------------
571
572 /* (non-Javadoc)
573 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
574 */
575 @Override
576 public synchronized ITmfContext seekEvent(final long rank) {
577
578 // A rank <= 0 indicates to seek the first event
579 if (rank <= 0) {
580 ITmfContext context = seekEvent((ITmfLocation) null);
581 context.setRank(0);
582 return context;
583 }
584
585 // Position the trace at the checkpoint
586 final ITmfContext context = fIndexer.seekIndex(rank);
587
588 // And locate the requested event context
589 long pos = context.getRank();
590 if (pos < rank) {
591 ITmfEvent event = getNext(context);
592 while ((event != null) && (++pos < rank)) {
593 event = getNext(context);
594 }
595 }
596 return context;
597 }
598
599 /* (non-Javadoc)
600 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
601 */
602 @Override
603 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
604
605 // A null timestamp indicates to seek the first event
606 if (timestamp == null) {
607 ITmfContext context = seekEvent((ITmfLocation) null);
608 context.setRank(0);
609 return context;
610 }
611
612 // Position the trace at the checkpoint
613 ITmfContext context = fIndexer.seekIndex(timestamp);
614
615 // And locate the requested event context
616 final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
617 ITmfEvent event = getNext(nextEventContext);
618 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
619 context.dispose();
620 context = nextEventContext.clone();
621 event = getNext(nextEventContext);
622 }
623 nextEventContext.dispose();
624 if (event == null) {
625 context.setLocation(null);
626 context.setRank(ITmfContext.UNKNOWN_RANK);
627 }
628 return context;
629 }
630
631 // ------------------------------------------------------------------------
632 // ITmfTrace - Read operations (returning an actual event)
633 // ------------------------------------------------------------------------
634
635 /* (non-Javadoc)
636 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
637 */
638 @Override
639 public synchronized ITmfEvent getNext(final ITmfContext context) {
640 // parseEvent() does not update the context
641 final ITmfEvent event = fParser.parseEvent(context);
642 if (event != null) {
643 updateAttributes(context, event.getTimestamp());
644 context.setLocation(getCurrentLocation());
645 context.increaseRank();
646 processEvent(event);
647 }
648 return event;
649 }
650
651 /**
652 * Hook for special event processing by the concrete class
653 * (called by TmfTrace.getEvent())
654 *
655 * @param event the event
656 */
657 protected void processEvent(final ITmfEvent event) {
658 // Do nothing
659 }
660
661 /**
662 * Update the trace attributes
663 *
664 * @param context the current trace context
665 * @param timestamp the corresponding timestamp
666 */
667 protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
668 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
669 fStartTime = timestamp;
670 }
671 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
672 fEndTime = timestamp;
673 }
674 if (fCurrentRange == TmfTimeRange.NULL_RANGE) {
675 fCurrentTime = timestamp;
676 ITmfTimestamp initialOffset = getInitialRangeOffset();
677 long endValue = timestamp.getValue() + initialOffset.normalize(0, timestamp.getScale()).getValue();
678 ITmfTimestamp endTimestamp = new TmfTimestamp(endValue, timestamp.getScale());
679 fCurrentRange = new TmfTimeRange(timestamp, endTimestamp);
680 }
681 if (context.hasValidRank()) {
682 long rank = context.getRank();
683 if (fNbEvents <= rank) {
684 fNbEvents = rank + 1;
685 }
686 if (fIndexer != null) {
687 fIndexer.updateIndex(context, timestamp);
688 }
689 }
690 }
691
692 // ------------------------------------------------------------------------
693 // TmfDataProvider
694 // ------------------------------------------------------------------------
695
696 /**
697 * @since 2.0
698 */
699 @Override
700 public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
701 if (executorIsShutdown()) {
702 return null;
703 }
704 if ((request instanceof ITmfEventRequest)
705 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
706 && (request.getIndex() == 0))
707 {
708 final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
709 ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
710 return context;
711
712 }
713 return seekEvent(request.getIndex());
714 }
715
716 // ------------------------------------------------------------------------
717 // Signal handlers
718 // ------------------------------------------------------------------------
719
720 /**
721 * Handler for the Trace Opened signal
722 *
723 * @param signal
724 * The incoming signal
725 * @since 2.0
726 */
727 @TmfSignalHandler
728 public void traceOpened(TmfTraceOpenedSignal signal) {
729 ITmfTrace trace = signal.getTrace();
730 if (signal.getTrace() instanceof TmfExperiment) {
731 TmfExperiment experiment = (TmfExperiment) signal.getTrace();
732 for (ITmfTrace expTrace : experiment.getTraces()) {
733 if (expTrace == this) {
734 trace = expTrace;
735 break;
736 }
737 }
738 }
739 if (trace == this) {
740 /* the signal is for this trace or for an experiment containing this trace */
741 try {
742 buildStatistics();
743 } catch (TmfTraceException e) {
744 e.printStackTrace();
745 }
746 try {
747 buildStateSystem();
748 } catch (TmfTraceException e) {
749 e.printStackTrace();
750 }
751
752 /* Refresh the project, so it can pick up new files that got created. */
753 try {
754 if (fResource != null) {
755 fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
756 }
757 } catch (CoreException e) {
758 e.printStackTrace();
759 }
760 }
761 if (signal.getTrace() == this) {
762 /* the signal is for this trace or experiment */
763 if (getNbEvents() == 0) {
764 return;
765 }
766
767 final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
768 final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
769
770 // Broadcast in separate thread to prevent deadlock
771 new Thread() {
772 @Override
773 public void run() {
774 broadcast(rangeUpdatedsignal);
775 }
776 }.start();
777 return;
778 }
779 }
780
781 /**
782 * Signal handler for the TmfTraceRangeUpdatedSignal signal
783 *
784 * @param signal The incoming signal
785 * @since 2.0
786 */
787 @TmfSignalHandler
788 public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
789 if (signal.getTrace() == this) {
790 getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
791 }
792 }
793
794 /**
795 * Signal handler for the TmfTimeSynchSignal signal
796 *
797 * @param signal The incoming signal
798 * @since 2.0
799 */
800 @TmfSignalHandler
801 public void synchToTime(final TmfTimeSynchSignal signal) {
802 if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
803 fCurrentTime = signal.getCurrentTime();
804 }
805 }
806
807 /**
808 * Signal handler for the TmfRangeSynchSignal signal
809 *
810 * @param signal The incoming signal
811 * @since 2.0
812 */
813 @TmfSignalHandler
814 public void synchToRange(final TmfRangeSynchSignal signal) {
815 if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
816 fCurrentTime = signal.getCurrentTime();
817 }
818 if (signal.getCurrentRange().getIntersection(getTimeRange()) != null) {
819 fCurrentRange = signal.getCurrentRange().getIntersection(getTimeRange());
820 }
821 }
822
823 // ------------------------------------------------------------------------
824 // toString
825 // ------------------------------------------------------------------------
826
827 /* (non-Javadoc)
828 * @see java.lang.Object#toString()
829 */
830 @Override
831 @SuppressWarnings("nls")
832 public synchronized String toString() {
833 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
834 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
835 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
836 }
837
838 }
This page took 0.072071 seconds and 5 git commands to generate.