tmf: Expose TmfExperiment.getTraces() up to ITmfTrace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 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.Collections;
19 import java.util.LinkedHashMap;
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.exceptions.TmfTraceException;
28 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
29 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
30 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
31 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
32 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
33 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
34 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
35 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
36 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
37 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
38 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
39 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
40 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
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 LinkedHashMap<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 /**
343 * @since 2.0
344 */
345 @Override
346 public ITmfTrace[] getTraces() {
347 return new ITmfTrace[] { this };
348 }
349
350 /* (non-Javadoc)
351 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
352 */
353 @Override
354 public Class<ITmfEvent> getEventType() {
355 return (Class<ITmfEvent>) super.getType();
356 }
357
358 /* (non-Javadoc)
359 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
360 */
361 @Override
362 public IResource getResource() {
363 return fResource;
364 }
365
366 /* (non-Javadoc)
367 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
368 */
369 @Override
370 public String getPath() {
371 return fPath;
372 }
373
374 /* (non-Javadoc)
375 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
376 */
377 @Override
378 public int getCacheSize() {
379 return fCacheSize;
380 }
381
382 /* (non-Javadoc)
383 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
384 */
385 @Override
386 public long getStreamingInterval() {
387 return fStreamingInterval;
388 }
389
390 /**
391 * @return the trace indexer
392 */
393 protected ITmfTraceIndexer getIndexer() {
394 return fIndexer;
395 }
396
397 /**
398 * @return the trace parser
399 */
400 protected ITmfEventParser getParser() {
401 return fParser;
402 }
403
404 /**
405 * @since 2.0
406 */
407 @Override
408 public ITmfStatistics getStatistics() {
409 return fStatistics;
410 }
411
412 /**
413 * @since 2.0
414 */
415 @Override
416 public final Map<String, ITmfStateSystem> getStateSystems() {
417 return Collections.unmodifiableMap(fStateSystems);
418 }
419
420 /**
421 * @since 2.0
422 */
423 @Override
424 public final void registerStateSystem(String id, ITmfStateSystem ss) {
425 fStateSystems.put(id, ss);
426 }
427
428 // ------------------------------------------------------------------------
429 // ITmfTrace - Trace characteristics getters
430 // ------------------------------------------------------------------------
431
432 @Override
433 public synchronized long getNbEvents() {
434 return fNbEvents;
435 }
436
437 /**
438 * @since 2.0
439 */
440 @Override
441 public TmfTimeRange getTimeRange() {
442 return new TmfTimeRange(fStartTime, fEndTime);
443 }
444
445 /**
446 * @since 2.0
447 */
448 @Override
449 public ITmfTimestamp getStartTime() {
450 return fStartTime;
451 }
452
453 /**
454 * @since 2.0
455 */
456 @Override
457 public ITmfTimestamp getEndTime() {
458 return fEndTime;
459 }
460
461 /**
462 * @since 2.0
463 */
464 @Override
465 public ITmfTimestamp getCurrentTime() {
466 return fCurrentTime;
467 }
468
469 /**
470 * @since 2.0
471 */
472 @Override
473 public TmfTimeRange getCurrentRange() {
474 return fCurrentRange;
475 }
476
477 /**
478 * @since 2.0
479 */
480 @Override
481 public ITmfTimestamp getInitialRangeOffset() {
482 final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
483 return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
484 }
485
486 // ------------------------------------------------------------------------
487 // Convenience setters
488 // ------------------------------------------------------------------------
489
490 /**
491 * Set the trace cache size. Must be done at initialization time.
492 *
493 * @param cacheSize The trace cache size
494 */
495 protected void setCacheSize(final int cacheSize) {
496 fCacheSize = cacheSize;
497 }
498
499 /**
500 * Set the trace known number of events. This can be quite dynamic
501 * during indexing or for live traces.
502 *
503 * @param nbEvents The number of events
504 */
505 protected synchronized void setNbEvents(final long nbEvents) {
506 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
507 }
508
509 /**
510 * Update the trace events time range
511 *
512 * @param range the new time range
513 * @since 2.0
514 */
515 protected void setTimeRange(final TmfTimeRange range) {
516 fStartTime = range.getStartTime();
517 fEndTime = range.getEndTime();
518 }
519
520 /**
521 * Update the trace chronologically first event timestamp
522 *
523 * @param startTime the new first event timestamp
524 * @since 2.0
525 */
526 protected void setStartTime(final ITmfTimestamp startTime) {
527 fStartTime = startTime;
528 }
529
530 /**
531 * Update the trace chronologically last event timestamp
532 *
533 * @param endTime the new last event timestamp
534 * @since 2.0
535 */
536 protected void setEndTime(final ITmfTimestamp endTime) {
537 fEndTime = endTime;
538 }
539
540 /**
541 * Set the polling interval for live traces (default = 0 = no streaming).
542 *
543 * @param interval the new trace streaming interval
544 */
545 protected void setStreamingInterval(final long interval) {
546 fStreamingInterval = (interval > 0) ? interval : 0;
547 }
548
549 /**
550 * Set the trace indexer. Must be done at initialization time.
551 *
552 * @param indexer the trace indexer
553 */
554 protected void setIndexer(final ITmfTraceIndexer indexer) {
555 fIndexer = indexer;
556 }
557
558 /**
559 * Set the trace parser. Must be done at initialization time.
560 *
561 * @param parser the new trace parser
562 */
563 protected void setParser(final ITmfEventParser parser) {
564 fParser = parser;
565 }
566
567 // ------------------------------------------------------------------------
568 // ITmfTrace - SeekEvent operations (returning a trace context)
569 // ------------------------------------------------------------------------
570
571 @Override
572 public synchronized ITmfContext seekEvent(final long rank) {
573
574 // A rank <= 0 indicates to seek the first event
575 if (rank <= 0) {
576 ITmfContext context = seekEvent((ITmfLocation) null);
577 context.setRank(0);
578 return context;
579 }
580
581 // Position the trace at the checkpoint
582 final ITmfContext context = fIndexer.seekIndex(rank);
583
584 // And locate the requested event context
585 long pos = context.getRank();
586 if (pos < rank) {
587 ITmfEvent event = getNext(context);
588 while ((event != null) && (++pos < rank)) {
589 event = getNext(context);
590 }
591 }
592 return context;
593 }
594
595 /**
596 * @since 2.0
597 */
598 @Override
599 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
600
601 // A null timestamp indicates to seek the first event
602 if (timestamp == null) {
603 ITmfContext context = seekEvent((ITmfLocation) null);
604 context.setRank(0);
605 return context;
606 }
607
608 // Position the trace at the checkpoint
609 ITmfContext context = fIndexer.seekIndex(timestamp);
610
611 // And locate the requested event context
612 ITmfLocation previousLocation = context.getLocation();
613 long previousRank = context.getRank();
614 ITmfEvent event = getNext(context);
615 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
616 previousLocation = context.getLocation();
617 previousRank = context.getRank();
618 event = getNext(context);
619 }
620 if (event == null) {
621 context.setLocation(null);
622 context.setRank(ITmfContext.UNKNOWN_RANK);
623 } else {
624 context.dispose();
625 context = seekEvent(previousLocation);
626 context.setRank(previousRank);
627 }
628 return context;
629 }
630
631 // ------------------------------------------------------------------------
632 // ITmfTrace - Read operations (returning an actual event)
633 // ------------------------------------------------------------------------
634
635 @Override
636 public synchronized ITmfEvent getNext(final ITmfContext context) {
637 // parseEvent() does not update the context
638 final ITmfEvent event = fParser.parseEvent(context);
639 if (event != null) {
640 updateAttributes(context, event.getTimestamp());
641 context.setLocation(getCurrentLocation());
642 context.increaseRank();
643 processEvent(event);
644 }
645 return event;
646 }
647
648 /**
649 * Hook for special event processing by the concrete class
650 * (called by TmfTrace.getEvent())
651 *
652 * @param event the event
653 */
654 protected void processEvent(final ITmfEvent event) {
655 // Do nothing
656 }
657
658 /**
659 * Update the trace attributes
660 *
661 * @param context the current trace context
662 * @param timestamp the corresponding timestamp
663 * @since 2.0
664 */
665 protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
666 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
667 fStartTime = timestamp;
668 }
669 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
670 fEndTime = timestamp;
671 }
672 if (fCurrentRange == TmfTimeRange.NULL_RANGE) {
673 fCurrentTime = timestamp;
674 ITmfTimestamp initialOffset = getInitialRangeOffset();
675 long endValue = timestamp.getValue() + initialOffset.normalize(0, timestamp.getScale()).getValue();
676 ITmfTimestamp endTimestamp = new TmfTimestamp(endValue, timestamp.getScale());
677 fCurrentRange = new TmfTimeRange(timestamp, endTimestamp);
678 }
679 if (context.hasValidRank()) {
680 long rank = context.getRank();
681 if (fNbEvents <= rank) {
682 fNbEvents = rank + 1;
683 }
684 if (fIndexer != null) {
685 fIndexer.updateIndex(context, timestamp);
686 }
687 }
688 }
689
690 // ------------------------------------------------------------------------
691 // TmfDataProvider
692 // ------------------------------------------------------------------------
693
694 /**
695 * @since 2.0
696 */
697 @Override
698 public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
699 if (executorIsShutdown()) {
700 return null;
701 }
702 if ((request instanceof ITmfEventRequest)
703 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
704 && (request.getIndex() == 0))
705 {
706 final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
707 ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
708 return context;
709
710 }
711 return seekEvent(request.getIndex());
712 }
713
714 // ------------------------------------------------------------------------
715 // Signal handlers
716 // ------------------------------------------------------------------------
717
718 /**
719 * Handler for the Trace Opened signal
720 *
721 * @param signal
722 * The incoming signal
723 * @since 2.0
724 */
725 @TmfSignalHandler
726 public void traceOpened(TmfTraceOpenedSignal signal) {
727 ITmfTrace trace = null;
728 for (ITmfTrace expTrace : signal.getTrace().getTraces()) {
729 if (expTrace == this) {
730 trace = expTrace;
731 break;
732 }
733 }
734
735 if (trace == null) {
736 /* This signal is not for us */
737 return;
738 }
739
740 /*
741 * The signal is for this trace, or for an experiment containing
742 * this trace.
743 */
744 try {
745 buildStatistics();
746 buildStateSystem();
747 } catch (TmfTraceException e) {
748 e.printStackTrace();
749 }
750
751 /* Refresh the project, so it can pick up new files that got created. */
752 try {
753 if (fResource != null) {
754 fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
755 }
756 } catch (CoreException e) {
757 e.printStackTrace();
758 }
759
760 if (signal.getTrace() == this) {
761 /* Additionally, the signal is directly for this trace or experiment. */
762 if (getNbEvents() == 0) {
763 return;
764 }
765
766 final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
767 final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
768
769 // Broadcast in separate thread to prevent deadlock
770 new Thread() {
771 @Override
772 public void run() {
773 broadcast(rangeUpdatedsignal);
774 }
775 }.start();
776 return;
777 }
778 }
779
780 /**
781 * Signal handler for the TmfTraceRangeUpdatedSignal signal
782 *
783 * @param signal The incoming signal
784 * @since 2.0
785 */
786 @TmfSignalHandler
787 public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
788 if (signal.getTrace() == this) {
789 getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
790 }
791 }
792
793 /**
794 * Signal handler for the TmfTimeSynchSignal signal
795 *
796 * @param signal The incoming signal
797 * @since 2.0
798 */
799 @TmfSignalHandler
800 public void synchToTime(final TmfTimeSynchSignal signal) {
801 if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
802 fCurrentTime = signal.getCurrentTime();
803 }
804 }
805
806 /**
807 * Signal handler for the TmfRangeSynchSignal signal
808 *
809 * @param signal The incoming signal
810 * @since 2.0
811 */
812 @TmfSignalHandler
813 public void synchToRange(final TmfRangeSynchSignal signal) {
814 if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
815 fCurrentTime = signal.getCurrentTime();
816 }
817 if (signal.getCurrentRange().getIntersection(getTimeRange()) != null) {
818 fCurrentRange = signal.getCurrentRange().getIntersection(getTimeRange());
819 }
820 }
821
822 // ------------------------------------------------------------------------
823 // toString
824 // ------------------------------------------------------------------------
825
826 @Override
827 @SuppressWarnings("nls")
828 public synchronized String toString() {
829 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
830 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
831 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
832 }
833
834 }
This page took 0.048532 seconds and 5 git commands to generate.