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