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