tmf: Remove the concept of block size in event requests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
CommitLineData
8c8bf09f 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 Ericsson
0bfb7d06 3 *
8c8bf09f
ASL
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
0bfb7d06 8 *
8c8bf09f 9 * Contributors:
20658947
FC
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
ea271da6 12 * Patrick Tasse - Updated for removal of context clone
8c8bf09f
ASL
13 *******************************************************************************/
14
6c13869b 15package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 16
6f4a1d2b 17import java.io.File;
35c160d9
AM
18import java.util.Collections;
19import java.util.LinkedHashMap;
a51b2b9f 20import java.util.Map;
8c8bf09f 21
828e5592 22import org.eclipse.core.resources.IResource;
faa38350 23import org.eclipse.core.runtime.CoreException;
9b749023 24import org.eclipse.core.runtime.IPath;
42459d24
AM
25import org.eclipse.core.runtime.IStatus;
26import org.eclipse.core.runtime.Status;
6c13869b 27import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
72f1e62a 28import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
b4f71e4a 29import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
5419a136
AM
30import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
31import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
faa38350 32import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
fec1ac0b 33import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
faa38350
PT
34import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
35import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
7898bb21 36import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
200789b3 37import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
1c0de632 38import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
3bd46eef
AM
39import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
40import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
41import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
8c8bf09f
ASL
42
43/**
09e86496
FC
44 * Abstract implementation of ITmfTrace.
45 * <p>
13cb5f43
FC
46 * Since the concept of 'location' is trace specific, the concrete classes have
47 * to provide the related methods, namely:
48 * <ul>
49 * <li> public ITmfLocation<?> getCurrentLocation()
50 * <li> public double getLocationRatio(ITmfLocation<?> location)
51 * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
52 * <li> public ITmfContext seekEvent(double ratio)
da1a4b39 53 * <li> public IStatus validate(IProject project, String path)
13cb5f43
FC
54 * </ul>
55 * A concrete trace must provide its corresponding parser. A common way to
56 * accomplish this is by making the concrete class extend TmfTrace and
57 * implement ITmfEventParser.
58 * <p>
59 * The concrete class can either specify its own indexer or use the provided
60 * TmfCheckpointIndexer (default). In this case, the trace cache size will be
61 * used as checkpoint interval.
0bfb7d06 62 *
f7703ed6
FC
63 * @version 1.0
64 * @author Francois Chouinard
65 *
f7703ed6
FC
66 * @see ITmfEvent
67 * @see ITmfTraceIndexer
68 * @see ITmfEventParser
8c8bf09f 69 */
6256d8ad 70public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
62d1696a 71
e31e01e8 72 // ------------------------------------------------------------------------
8c8bf09f 73 // Attributes
e31e01e8 74 // ------------------------------------------------------------------------
8c8bf09f 75
09e86496
FC
76 // The resource used for persistent properties for this trace
77 private IResource fResource;
78
b0a282fb 79 // The trace path
12c155f5 80 private String fPath;
b0a282fb 81
0316808c
FC
82 // The trace cache page size
83 private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
62d1696a 84
0316808c
FC
85 // The number of events collected (so far)
86 private long fNbEvents = 0;
62d1696a
FC
87
88 // The time span of the event stream
9cbe7899 89 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
a4115405 90 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
62d1696a 91
0316808c
FC
92 // The trace streaming interval (0 = no streaming)
93 private long fStreamingInterval = 0;
085d898f 94
0316808c 95 // The trace indexer
6256d8ad 96 private ITmfTraceIndexer fIndexer;
20658947 97
0316808c 98 // The trace parser
6256d8ad 99 private ITmfEventParser fParser;
7e6347b0 100
200789b3
AM
101 // The trace's statistics
102 private ITmfStatistics fStatistics;
103
a51b2b9f
AM
104 /**
105 * The collection of state systems that are registered with this trace. Each
106 * sub-class can decide to add its (one or many) state system to this map
107 * during their {@link #buildStateSystem()}.
108 *
109 * @since 2.0
110 */
111 protected final Map<String, ITmfStateSystem> fStateSystems =
35c160d9 112 new LinkedHashMap<String, ITmfStateSystem>();
a51b2b9f 113
e31e01e8 114 // ------------------------------------------------------------------------
3791b5df 115 // Construction
e31e01e8 116 // ------------------------------------------------------------------------
8c8bf09f 117
62d1696a 118 /**
3791b5df 119 * The default, parameterless, constructor
62d1696a 120 */
3791b5df
FC
121 public TmfTrace() {
122 super();
05bd3318
FC
123 }
124
125 /**
8cf330ae 126 * Full constructor.
0bfb7d06 127 *
8cf330ae
AM
128 * @param resource
129 * The resource associated to the trace
130 * @param type
131 * The type of events that will be read from this trace
132 * @param path
133 * The path to the trace on the filesystem
134 * @param cacheSize
135 * The trace cache size. Pass '-1' to use the default specified
136 * in {@link ITmfTrace#DEFAULT_TRACE_CACHE_SIZE}
137 * @param interval
138 * The trace streaming interval. You can use '0' for post-mortem
139 * traces.
140 * @param indexer
141 * The trace indexer. You can pass 'null' to use a default
142 * checkpoint indexer.
143 * @param parser
144 * The trace event parser. Use 'null' if (and only if) the trace
145 * object itself is also the ITmfEventParser to be used.
146 * @throws TmfTraceException
147 * If something failed during the opening
20658947 148 */
8cf330ae
AM
149 protected TmfTrace(final IResource resource,
150 final Class<? extends ITmfEvent> type,
151 final String path,
152 final int cacheSize,
153 final long interval,
154 final ITmfTraceIndexer indexer,
155 final ITmfEventParser parser)
156 throws TmfTraceException {
00641a97 157 super();
0316808c 158 fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
3791b5df 159 fStreamingInterval = interval;
7e6347b0 160 fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
13cb5f43 161 fParser = parser;
09e86496 162 initialize(resource, path, type);
8c8bf09f
ASL
163 }
164
3791b5df
FC
165 /**
166 * Copy constructor
0bfb7d06 167 *
3791b5df 168 * @param trace the original trace
063f0d27 169 * @throws TmfTraceException Should not happen usually
3791b5df 170 */
6256d8ad 171 public TmfTrace(final TmfTrace trace) throws TmfTraceException {
3791b5df 172 super();
0316808c 173 if (trace == null) {
3791b5df 174 throw new IllegalArgumentException();
0316808c 175 }
20658947
FC
176 fCacheSize = trace.getCacheSize();
177 fStreamingInterval = trace.getStreamingInterval();
7e6347b0 178 fIndexer = new TmfCheckpointIndexer(this);
13cb5f43
FC
179 fParser = trace.fParser;
180 initialize(trace.getResource(), trace.getPath(), trace.getEventType());
3791b5df
FC
181 }
182
7e6347b0
FC
183 // ------------------------------------------------------------------------
184 // ITmfTrace - Initializers
185 // ------------------------------------------------------------------------
186
7e6347b0 187 @Override
6256d8ad 188 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
9dc3dee2 189 fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
7e6347b0 190 initialize(resource, path, type);
7e6347b0
FC
191 }
192
09e86496 193 /**
1703b536 194 * Initialize the trace common attributes and the base component.
0bfb7d06
MK
195 *
196 * @param resource the Eclipse resource (trace)
1703b536
FC
197 * @param path the trace path
198 * @param type the trace event type
0bfb7d06 199 *
6f4e8ec0 200 * @throws TmfTraceException If something failed during the initialization
3791b5df 201 */
248af329
AM
202 protected void initialize(final IResource resource,
203 final String path,
204 final Class<? extends ITmfEvent> type)
205 throws TmfTraceException {
0316808c 206 if (path == null) {
b4f71e4a 207 throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
0316808c 208 }
3791b5df 209 fPath = path;
1703b536 210 fResource = resource;
25e48683 211 String traceName = (resource != null) ? resource.getName() : null;
1703b536
FC
212 // If no resource was provided, extract the display name the trace path
213 if (traceName == null) {
9b749023 214 final int sep = path.lastIndexOf(IPath.SEPARATOR);
1703b536
FC
215 traceName = (sep >= 0) ? path.substring(sep + 1) : path;
216 }
2352aed9
FC
217 if (fParser == null) {
218 if (this instanceof ITmfEventParser) {
6256d8ad 219 fParser = (ITmfEventParser) this;
2352aed9
FC
220 } else {
221 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
222 }
223 }
3791b5df 224 super.init(traceName, type);
fec1ac0b
BH
225 // register as VIP after super.init() because TmfComponent registers to signal manager there
226 TmfSignalManager.registerVIP(this);
3791b5df
FC
227 }
228
2352aed9
FC
229 /**
230 * Indicates if the path points to an existing file/directory
0bfb7d06 231 *
2352aed9
FC
232 * @param path the path to test
233 * @return true if the file/directory exists
3791b5df 234 */
2352aed9 235 protected boolean fileExists(final String path) {
085d898f 236 final File file = new File(path);
3791b5df
FC
237 return file.exists();
238 }
239
c7e1020d 240 /**
51e75066 241 * @since 2.0
c7e1020d 242 */
51e75066
AM
243 @Override
244 public void indexTrace(boolean waitForCompletion) {
9e0640dc 245 getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
c7e1020d
FC
246 }
247
200789b3 248 /**
6f4e8ec0 249 * The default implementation of TmfTrace uses a TmfStatistics back-end.
200789b3
AM
250 * Override this if you want to specify another type (or none at all).
251 *
6f4e8ec0
AM
252 * @throws TmfTraceException
253 * If there was a problem setting up the statistics
200789b3
AM
254 * @since 2.0
255 */
256 protected void buildStatistics() throws TmfTraceException {
257 /*
258 * Initialize the statistics provider, but only if a Resource has been
259 * set (so we don't build it for experiments, for unit tests, etc.)
260 */
1c0de632 261 fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
200789b3
AM
262 }
263
faa38350
PT
264 /**
265 * Build the state system(s) associated with this trace type.
266 *
267 * Suppressing the warning, because the 'throws' will usually happen in
268 * sub-classes.
269 *
42459d24
AM
270 * @return An IStatus indicating if the state system could be build
271 * successfully or not.
272 * @since 3.0
faa38350 273 */
42459d24 274 protected IStatus buildStateSystem() {
faa38350
PT
275 /*
276 * Nothing is done in the base implementation, please specify
a51b2b9f 277 * how/if to register a new state system in derived classes.
faa38350 278 */
42459d24 279 return Status.OK_STATUS;
faa38350
PT
280 }
281
b5ee6881
FC
282 /**
283 * Clears the trace
284 */
285 @Override
286 public synchronized void dispose() {
1a4205d9 287 /* Clean up the index if applicable */
77551cc2
FC
288 if (getIndexer() != null) {
289 getIndexer().dispose();
290 }
1a4205d9
AM
291
292 /* Clean up the statistics */
293 if (fStatistics != null) {
294 fStatistics.dispose();
295 }
a51b2b9f
AM
296
297 /* Clean up the state systems */
298 for (ITmfStateSystem ss : fStateSystems.values()) {
299 ss.dispose();
300 }
301
b5ee6881
FC
302 super.dispose();
303 }
304
3791b5df 305 // ------------------------------------------------------------------------
09e86496 306 // ITmfTrace - Basic getters
e31e01e8 307 // ------------------------------------------------------------------------
8c8bf09f 308
25e48683 309 @Override
6256d8ad
AM
310 public Class<ITmfEvent> getEventType() {
311 return (Class<ITmfEvent>) super.getType();
25e48683
FC
312 }
313
d4011df2 314 @Override
09e86496
FC
315 public IResource getResource() {
316 return fResource;
8c8bf09f
ASL
317 }
318
d4011df2 319 @Override
09e86496
FC
320 public String getPath() {
321 return fPath;
8c8bf09f
ASL
322 }
323
20658947
FC
324 @Override
325 public int getCacheSize() {
326 return fCacheSize;
327 }
328
20658947
FC
329 @Override
330 public long getStreamingInterval() {
331 return fStreamingInterval;
332 }
333
0316808c
FC
334 /**
335 * @return the trace indexer
336 */
6256d8ad 337 protected ITmfTraceIndexer getIndexer() {
0316808c
FC
338 return fIndexer;
339 }
340
341 /**
342 * @return the trace parser
343 */
6256d8ad 344 protected ITmfEventParser getParser() {
0316808c
FC
345 return fParser;
346 }
347
200789b3
AM
348 /**
349 * @since 2.0
350 */
351 @Override
352 public ITmfStatistics getStatistics() {
353 return fStatistics;
354 }
355
7898bb21
AM
356 /**
357 * @since 2.0
358 */
359 @Override
35c160d9
AM
360 public final Map<String, ITmfStateSystem> getStateSystems() {
361 return Collections.unmodifiableMap(fStateSystems);
7898bb21
AM
362 }
363
6c5e0863
AM
364 /**
365 * @since 2.0
366 */
367 @Override
368 public final void registerStateSystem(String id, ITmfStateSystem ss) {
369 fStateSystems.put(id, ss);
370 }
371
09e86496
FC
372 // ------------------------------------------------------------------------
373 // ITmfTrace - Trace characteristics getters
374 // ------------------------------------------------------------------------
375
d4011df2 376 @Override
5419a136 377 public synchronized long getNbEvents() {
3791b5df 378 return fNbEvents;
b0a282fb
FC
379 }
380
3bd46eef
AM
381 /**
382 * @since 2.0
62d1696a 383 */
d4011df2 384 @Override
12c155f5 385 public TmfTimeRange getTimeRange() {
cb866e08 386 return new TmfTimeRange(fStartTime, fEndTime);
8c8bf09f
ASL
387 }
388
3bd46eef
AM
389 /**
390 * @since 2.0
e31e01e8 391 */
d4011df2 392 @Override
4df4581d 393 public ITmfTimestamp getStartTime() {
4593bd5b 394 return fStartTime;
146a887c
FC
395 }
396
3bd46eef
AM
397 /**
398 * @since 2.0
e31e01e8 399 */
d4011df2 400 @Override
4df4581d 401 public ITmfTimestamp getEndTime() {
4593bd5b 402 return fEndTime;
20658947
FC
403 }
404
d7ee91bb 405 /**
d7ee91bb
PT
406 * @since 2.0
407 */
66262ad8
BH
408 @Override
409 public ITmfTimestamp getInitialRangeOffset() {
d7ee91bb
PT
410 final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
411 return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
412 }
413
bb52f9bc
GB
414 /**
415 * @since 3.0
416 */
417 @Override
418 public String getHostId() {
419 return this.getName();
420 }
421
20658947 422 // ------------------------------------------------------------------------
d7ee91bb 423 // Convenience setters
20658947
FC
424 // ------------------------------------------------------------------------
425
0316808c
FC
426 /**
427 * Set the trace cache size. Must be done at initialization time.
0bfb7d06 428 *
0316808c
FC
429 * @param cacheSize The trace cache size
430 */
431 protected void setCacheSize(final int cacheSize) {
432 fCacheSize = cacheSize;
433 }
434
435 /**
436 * Set the trace known number of events. This can be quite dynamic
437 * during indexing or for live traces.
0bfb7d06 438 *
0316808c
FC
439 * @param nbEvents The number of events
440 */
441 protected synchronized void setNbEvents(final long nbEvents) {
442 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
443 }
444
20658947
FC
445 /**
446 * Update the trace events time range
0bfb7d06 447 *
20658947 448 * @param range the new time range
3bd46eef 449 * @since 2.0
20658947
FC
450 */
451 protected void setTimeRange(final TmfTimeRange range) {
4593bd5b
AM
452 fStartTime = range.getStartTime();
453 fEndTime = range.getEndTime();
20658947
FC
454 }
455
456 /**
457 * Update the trace chronologically first event timestamp
0bfb7d06 458 *
20658947 459 * @param startTime the new first event timestamp
3bd46eef 460 * @since 2.0
20658947
FC
461 */
462 protected void setStartTime(final ITmfTimestamp startTime) {
4593bd5b 463 fStartTime = startTime;
20658947
FC
464 }
465
466 /**
467 * Update the trace chronologically last event timestamp
0bfb7d06 468 *
20658947 469 * @param endTime the new last event timestamp
3bd46eef 470 * @since 2.0
20658947
FC
471 */
472 protected void setEndTime(final ITmfTimestamp endTime) {
4593bd5b 473 fEndTime = endTime;
20658947
FC
474 }
475
476 /**
0316808c 477 * Set the polling interval for live traces (default = 0 = no streaming).
0bfb7d06 478 *
20658947
FC
479 * @param interval the new trace streaming interval
480 */
481 protected void setStreamingInterval(final long interval) {
1703b536 482 fStreamingInterval = (interval > 0) ? interval : 0;
146a887c
FC
483 }
484
0316808c
FC
485 /**
486 * Set the trace indexer. Must be done at initialization time.
0bfb7d06 487 *
0316808c
FC
488 * @param indexer the trace indexer
489 */
6256d8ad 490 protected void setIndexer(final ITmfTraceIndexer indexer) {
0316808c
FC
491 fIndexer = indexer;
492 }
493
494 /**
495 * Set the trace parser. Must be done at initialization time.
0bfb7d06 496 *
0316808c
FC
497 * @param parser the new trace parser
498 */
6256d8ad 499 protected void setParser(final ITmfEventParser parser) {
0316808c
FC
500 fParser = parser;
501 }
502
09e86496 503 // ------------------------------------------------------------------------
7e6347b0 504 // ITmfTrace - SeekEvent operations (returning a trace context)
09e86496
FC
505 // ------------------------------------------------------------------------
506
1b70b6dc 507 @Override
7e6347b0 508 public synchronized ITmfContext seekEvent(final long rank) {
09e86496 509
7e6347b0 510 // A rank <= 0 indicates to seek the first event
2352aed9 511 if (rank <= 0) {
1e1bef82 512 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
513 context.setRank(0);
514 return context;
515 }
09e86496 516
09e86496 517 // Position the trace at the checkpoint
7e6347b0 518 final ITmfContext context = fIndexer.seekIndex(rank);
09e86496
FC
519
520 // And locate the requested event context
7e6347b0
FC
521 long pos = context.getRank();
522 if (pos < rank) {
c32744d6 523 ITmfEvent event = getNext(context);
0bfb7d06 524 while ((event != null) && (++pos < rank)) {
c32744d6 525 event = getNext(context);
7e6347b0 526 }
09e86496
FC
527 }
528 return context;
1b70b6dc
PT
529 }
530
3bd46eef
AM
531 /**
532 * @since 2.0
09e86496
FC
533 */
534 @Override
7e6347b0 535 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
09e86496 536
7e6347b0 537 // A null timestamp indicates to seek the first event
2352aed9 538 if (timestamp == null) {
1e1bef82 539 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
540 context.setRank(0);
541 return context;
542 }
09e86496 543
1703b536 544 // Position the trace at the checkpoint
408e65d2 545 ITmfContext context = fIndexer.seekIndex(timestamp);
09e86496
FC
546
547 // And locate the requested event context
ea271da6
PT
548 ITmfLocation previousLocation = context.getLocation();
549 long previousRank = context.getRank();
550 ITmfEvent event = getNext(context);
7e6347b0 551 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
ea271da6
PT
552 previousLocation = context.getLocation();
553 previousRank = context.getRank();
554 event = getNext(context);
09e86496 555 }
0316808c
FC
556 if (event == null) {
557 context.setLocation(null);
558 context.setRank(ITmfContext.UNKNOWN_RANK);
ea271da6
PT
559 } else {
560 context.dispose();
561 context = seekEvent(previousLocation);
562 context.setRank(previousRank);
0316808c 563 }
09e86496
FC
564 return context;
565 }
0283f7ff 566
09e86496
FC
567 // ------------------------------------------------------------------------
568 // ITmfTrace - Read operations (returning an actual event)
569 // ------------------------------------------------------------------------
570
d4011df2 571 @Override
6256d8ad 572 public synchronized ITmfEvent getNext(final ITmfContext context) {
09e86496 573 // parseEvent() does not update the context
6256d8ad 574 final ITmfEvent event = fParser.parseEvent(context);
09e86496 575 if (event != null) {
d337369a 576 updateAttributes(context, event.getTimestamp());
09e86496
FC
577 context.setLocation(getCurrentLocation());
578 context.increaseRank();
579 processEvent(event);
580 }
581 return event;
582 }
583
584 /**
d337369a 585 * Hook for special event processing by the concrete class
7e6347b0 586 * (called by TmfTrace.getEvent())
0bfb7d06 587 *
d337369a 588 * @param event the event
09e86496
FC
589 */
590 protected void processEvent(final ITmfEvent event) {
d337369a 591 // Do nothing
09e86496
FC
592 }
593
d337369a
FC
594 /**
595 * Update the trace attributes
0bfb7d06 596 *
d337369a 597 * @param context the current trace context
2848c377 598 * @param timestamp the corresponding timestamp
3bd46eef 599 * @since 2.0
d337369a
FC
600 */
601 protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
0bfb7d06 602 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
4593bd5b 603 fStartTime = timestamp;
09e86496 604 }
0bfb7d06 605 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
4593bd5b 606 fEndTime = timestamp;
09e86496
FC
607 }
608 if (context.hasValidRank()) {
d337369a 609 long rank = context.getRank();
09e86496
FC
610 if (fNbEvents <= rank) {
611 fNbEvents = rank + 1;
612 }
200789b3
AM
613 if (fIndexer != null) {
614 fIndexer.updateIndex(context, timestamp);
615 }
09e86496 616 }
abfad0aa
FC
617 }
618
3791b5df 619 // ------------------------------------------------------------------------
d337369a 620 // TmfDataProvider
3791b5df
FC
621 // ------------------------------------------------------------------------
622
77c4a6df
AM
623 /**
624 * @since 2.0
d337369a 625 */
3791b5df 626 @Override
5419a136 627 public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
faa38350
PT
628 if (executorIsShutdown()) {
629 return null;
630 }
5419a136
AM
631 if ((request instanceof ITmfEventRequest)
632 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
633 && (request.getIndex() == 0))
634 {
635 final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
636 ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
8584dc20 637 return context;
8584dc20 638
5419a136
AM
639 }
640 return seekEvent(request.getIndex());
3791b5df
FC
641 }
642
faa38350
PT
643 // ------------------------------------------------------------------------
644 // Signal handlers
645 // ------------------------------------------------------------------------
646
647 /**
648 * Handler for the Trace Opened signal
649 *
650 * @param signal
651 * The incoming signal
652 * @since 2.0
653 */
654 @TmfSignalHandler
655 public void traceOpened(TmfTraceOpenedSignal signal) {
b9a5bf8f
AM
656 boolean signalIsForUs = false;
657 for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
658 if (trace == this) {
659 signalIsForUs = true;
fe0c44c4 660 break;
faa38350
PT
661 }
662 }
faa38350 663
b9a5bf8f 664 if (!signalIsForUs) {
fe0c44c4
AM
665 return;
666 }
667
668 /*
b9a5bf8f 669 * The signal is either for this trace, or for an experiment containing
fe0c44c4
AM
670 * this trace.
671 */
672 try {
673 buildStatistics();
674 buildStateSystem();
675 } catch (TmfTraceException e) {
676 e.printStackTrace();
677 }
678
679 /* Refresh the project, so it can pick up new files that got created. */
680 try {
681 if (fResource != null) {
682 fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
faa38350 683 }
fe0c44c4
AM
684 } catch (CoreException e) {
685 e.printStackTrace();
faa38350 686 }
fe0c44c4 687
faa38350 688 if (signal.getTrace() == this) {
f8fc4a3a 689 /* Additionally, the signal is directly for this trace. */
faa38350
PT
690 if (getNbEvents() == 0) {
691 return;
692 }
693
f8fc4a3a
PT
694 /* For a streaming trace, the range updated signal should be sent
695 * by the subclass when a new safe time is determined.
696 */
697 if (getStreamingInterval() > 0) {
698 return;
699 }
700
faa38350
PT
701 final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
702 final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
703
704 // Broadcast in separate thread to prevent deadlock
705 new Thread() {
706 @Override
707 public void run() {
708 broadcast(rangeUpdatedsignal);
709 }
710 }.start();
711 return;
712 }
713 }
714
715 /**
716 * Signal handler for the TmfTraceRangeUpdatedSignal signal
717 *
718 * @param signal The incoming signal
719 * @since 2.0
720 */
721 @TmfSignalHandler
722 public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
723 if (signal.getTrace() == this) {
724 getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
725 }
726 }
727
3791b5df 728 // ------------------------------------------------------------------------
09e86496 729 // toString
3791b5df
FC
730 // ------------------------------------------------------------------------
731
12c155f5 732 @Override
09e86496 733 @SuppressWarnings("nls")
5419a136 734 public synchronized String toString() {
20658947
FC
735 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
736 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
737 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
12c155f5
FC
738 }
739
8c8bf09f 740}
This page took 0.100023 seconds and 5 git commands to generate.