tmf: Add dispose methods to the state and stats backends
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
CommitLineData
8c8bf09f 1/*******************************************************************************
09e86496 2 * Copyright (c) 2009, 2010, 2012 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
8c8bf09f
ASL
12 *******************************************************************************/
13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
6f4a1d2b 16import java.io.File;
8c8bf09f 17
828e5592 18import org.eclipse.core.resources.IResource;
9b749023 19import org.eclipse.core.runtime.IPath;
6c13869b 20import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
72f1e62a 21import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
4df4581d 22import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b
FC
23import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
24import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
b4f71e4a 25import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
6c13869b
FC
26import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
27import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
7898bb21 28import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
200789b3 29import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
1c0de632 30import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
8c8bf09f
ASL
31
32/**
09e86496
FC
33 * Abstract implementation of ITmfTrace.
34 * <p>
13cb5f43
FC
35 * Since the concept of 'location' is trace specific, the concrete classes have
36 * to provide the related methods, namely:
37 * <ul>
38 * <li> public ITmfLocation<?> getCurrentLocation()
39 * <li> public double getLocationRatio(ITmfLocation<?> location)
40 * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
41 * <li> public ITmfContext seekEvent(double ratio)
2848c377 42 * <li> public boolean validate(IProject project, String path)
13cb5f43
FC
43 * </ul>
44 * A concrete trace must provide its corresponding parser. A common way to
45 * accomplish this is by making the concrete class extend TmfTrace and
46 * implement ITmfEventParser.
47 * <p>
48 * The concrete class can either specify its own indexer or use the provided
49 * TmfCheckpointIndexer (default). In this case, the trace cache size will be
50 * used as checkpoint interval.
0bfb7d06 51 *
f7703ed6
FC
52 * @version 1.0
53 * @author Francois Chouinard
54 *
f7703ed6
FC
55 * @see ITmfEvent
56 * @see ITmfTraceIndexer
57 * @see ITmfEventParser
8c8bf09f 58 */
6256d8ad 59public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
62d1696a 60
e31e01e8 61 // ------------------------------------------------------------------------
8c8bf09f 62 // Attributes
e31e01e8 63 // ------------------------------------------------------------------------
8c8bf09f 64
09e86496
FC
65 // The resource used for persistent properties for this trace
66 private IResource fResource;
67
b0a282fb 68 // The trace path
12c155f5 69 private String fPath;
b0a282fb 70
0316808c
FC
71 // The trace cache page size
72 private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
62d1696a 73
0316808c
FC
74 // The number of events collected (so far)
75 private long fNbEvents = 0;
62d1696a
FC
76
77 // The time span of the event stream
a4115405
FC
78 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
79 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
62d1696a 80
0316808c
FC
81 // The trace streaming interval (0 = no streaming)
82 private long fStreamingInterval = 0;
085d898f 83
0316808c 84 // The trace indexer
6256d8ad 85 private ITmfTraceIndexer fIndexer;
20658947 86
0316808c 87 // The trace parser
6256d8ad 88 private ITmfEventParser fParser;
7e6347b0 89
200789b3
AM
90 // The trace's statistics
91 private ITmfStatistics fStatistics;
92
e31e01e8 93 // ------------------------------------------------------------------------
3791b5df 94 // Construction
e31e01e8 95 // ------------------------------------------------------------------------
8c8bf09f 96
62d1696a 97 /**
3791b5df 98 * The default, parameterless, constructor
62d1696a 99 */
3791b5df
FC
100 public TmfTrace() {
101 super();
05bd3318
FC
102 }
103
104 /**
13cb5f43 105 * The standard constructor (non-live trace). Applicable when the trace
0bfb7d06
MK
106 * implements its own parser and if at checkpoint-based index is OK.
107 *
20658947
FC
108 * @param resource the resource associated to the trace
109 * @param type the trace event type
110 * @param path the trace path
111 * @param cacheSize the trace cache size
2352aed9 112 * @throws TmfTraceException
20658947 113 */
6256d8ad 114 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException {
9e0640dc 115 this(resource, type, path, cacheSize, 0);
20658947
FC
116 }
117
118 /**
13cb5f43
FC
119 * The standard constructor (live trace). Applicable when the trace
120 * implements its own parser and if at checkpoint-based index is OK.
0bfb7d06 121 *
20658947 122 * @param resource the resource associated to the trace
3791b5df
FC
123 * @param type the trace event type
124 * @param path the trace path
20658947
FC
125 * @param cacheSize the trace cache size
126 * @param interval the trace streaming interval
2352aed9 127 * @throws TmfTraceException
05bd3318 128 */
6256d8ad 129 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
20658947 130 this(resource, type, path, cacheSize, interval, null);
05bd3318
FC
131 }
132
133 /**
13cb5f43
FC
134 * The 'non-default indexer' constructor. Allows to provide a trace
135 * specific indexer.
0bfb7d06 136 *
20658947 137 * @param resource the resource associated to the trace
3791b5df
FC
138 * @param type the trace event type
139 * @param path the trace path
20658947
FC
140 * @param cacheSize the trace cache size
141 * @param indexer the trace indexer
2352aed9 142 * @throws TmfTraceException
05bd3318 143 */
6256d8ad
AM
144 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
145 final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException {
0316808c 146 this(resource, type, path, cacheSize, interval, indexer, null);
13cb5f43
FC
147 }
148
149 /**
0bfb7d06
MK
150 * The full constructor where trace specific indexer/parser are provided.
151 *
13cb5f43
FC
152 * @param resource the resource associated to the trace
153 * @param type the trace event type
154 * @param path the trace path
155 * @param cacheSize the trace cache size
156 * @param indexer the trace indexer
157 * @param parser the trace event parser
2352aed9 158 * @throws TmfTraceException
13cb5f43 159 */
6256d8ad
AM
160 protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
161 final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException {
00641a97 162 super();
0316808c 163 fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
3791b5df 164 fStreamingInterval = interval;
7e6347b0 165 fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
13cb5f43 166 fParser = parser;
09e86496 167 initialize(resource, path, type);
8c8bf09f
ASL
168 }
169
3791b5df
FC
170 /**
171 * Copy constructor
0bfb7d06 172 *
3791b5df 173 * @param trace the original trace
063f0d27 174 * @throws TmfTraceException Should not happen usually
3791b5df 175 */
6256d8ad 176 public TmfTrace(final TmfTrace trace) throws TmfTraceException {
3791b5df 177 super();
0316808c 178 if (trace == null) {
3791b5df 179 throw new IllegalArgumentException();
0316808c 180 }
20658947
FC
181 fCacheSize = trace.getCacheSize();
182 fStreamingInterval = trace.getStreamingInterval();
7e6347b0 183 fIndexer = new TmfCheckpointIndexer(this);
13cb5f43
FC
184 fParser = trace.fParser;
185 initialize(trace.getResource(), trace.getPath(), trace.getEventType());
3791b5df
FC
186 }
187
7e6347b0
FC
188 // ------------------------------------------------------------------------
189 // ITmfTrace - Initializers
190 // ------------------------------------------------------------------------
191
192 /* (non-Javadoc)
193 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class)
194 */
195 @Override
6256d8ad 196 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
9dc3dee2 197 fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
7e6347b0 198 initialize(resource, path, type);
7e6347b0
FC
199 }
200
09e86496 201 /**
1703b536 202 * Initialize the trace common attributes and the base component.
0bfb7d06
MK
203 *
204 * @param resource the Eclipse resource (trace)
1703b536
FC
205 * @param path the trace path
206 * @param type the trace event type
0bfb7d06 207 *
0316808c 208 * @throws TmfTraceException
3791b5df 209 */
6256d8ad 210 protected void initialize(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
0316808c 211 if (path == null) {
b4f71e4a 212 throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
0316808c 213 }
3791b5df 214 fPath = path;
1703b536 215 fResource = resource;
25e48683 216 String traceName = (resource != null) ? resource.getName() : null;
1703b536
FC
217 // If no resource was provided, extract the display name the trace path
218 if (traceName == null) {
9b749023 219 final int sep = path.lastIndexOf(IPath.SEPARATOR);
1703b536
FC
220 traceName = (sep >= 0) ? path.substring(sep + 1) : path;
221 }
2352aed9
FC
222 if (fParser == null) {
223 if (this instanceof ITmfEventParser) {
6256d8ad 224 fParser = (ITmfEventParser) this;
2352aed9
FC
225 } else {
226 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
227 }
228 }
3791b5df 229 super.init(traceName, type);
200789b3
AM
230
231 buildStatistics();
3791b5df
FC
232 }
233
2352aed9
FC
234 /**
235 * Indicates if the path points to an existing file/directory
0bfb7d06 236 *
2352aed9
FC
237 * @param path the path to test
238 * @return true if the file/directory exists
3791b5df 239 */
2352aed9 240 protected boolean fileExists(final String path) {
085d898f 241 final File file = new File(path);
3791b5df
FC
242 return file.exists();
243 }
244
c7e1020d
FC
245 /**
246 * Index the trace
0bfb7d06 247 *
c7e1020d
FC
248 * @param waitForCompletion index synchronously (true) or not (false)
249 */
250 protected void indexTrace(boolean waitForCompletion) {
9e0640dc 251 getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
c7e1020d
FC
252 }
253
200789b3
AM
254 /**
255 * The default implementation of TmfTrace uses a TmfStatistics backend.
256 * Override this if you want to specify another type (or none at all).
257 *
258 * @since 2.0
259 */
260 protected void buildStatistics() throws TmfTraceException {
261 /*
262 * Initialize the statistics provider, but only if a Resource has been
263 * set (so we don't build it for experiments, for unit tests, etc.)
264 */
1c0de632 265 fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
200789b3
AM
266 }
267
b5ee6881
FC
268 /**
269 * Clears the trace
270 */
271 @Override
272 public synchronized void dispose() {
1a4205d9 273 /* Clean up the index if applicable */
77551cc2
FC
274 if (getIndexer() != null) {
275 getIndexer().dispose();
276 }
1a4205d9
AM
277
278 /* Clean up the statistics */
279 if (fStatistics != null) {
280 fStatistics.dispose();
281 }
b5ee6881
FC
282 super.dispose();
283 }
284
3791b5df 285 // ------------------------------------------------------------------------
09e86496 286 // ITmfTrace - Basic getters
e31e01e8 287 // ------------------------------------------------------------------------
8c8bf09f 288
09e86496 289 /* (non-Javadoc)
13cb5f43 290 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
25e48683
FC
291 */
292 @Override
6256d8ad
AM
293 public Class<ITmfEvent> getEventType() {
294 return (Class<ITmfEvent>) super.getType();
25e48683
FC
295 }
296
09e86496
FC
297 /* (non-Javadoc)
298 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
62d1696a 299 */
d4011df2 300 @Override
09e86496
FC
301 public IResource getResource() {
302 return fResource;
8c8bf09f
ASL
303 }
304
09e86496
FC
305 /* (non-Javadoc)
306 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
62d1696a 307 */
d4011df2 308 @Override
09e86496
FC
309 public String getPath() {
310 return fPath;
8c8bf09f
ASL
311 }
312
20658947
FC
313 /* (non-Javadoc)
314 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
315 */
316 @Override
317 public int getCacheSize() {
318 return fCacheSize;
319 }
320
321 /* (non-Javadoc)
322 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
323 */
324 @Override
325 public long getStreamingInterval() {
326 return fStreamingInterval;
327 }
328
0316808c
FC
329 /**
330 * @return the trace indexer
331 */
6256d8ad 332 protected ITmfTraceIndexer getIndexer() {
0316808c
FC
333 return fIndexer;
334 }
335
336 /**
337 * @return the trace parser
338 */
6256d8ad 339 protected ITmfEventParser getParser() {
0316808c
FC
340 return fParser;
341 }
342
200789b3
AM
343 /**
344 * @since 2.0
345 */
346 @Override
347 public ITmfStatistics getStatistics() {
348 return fStatistics;
349 }
350
7898bb21
AM
351 /**
352 * @since 2.0
353 */
354 @Override
355 public ITmfStateSystem getStateSystem() {
356 /*
357 * By default, no state system is used. Sub-classes can specify their
358 * own behaviour.
359 */
360 return null;
361 }
362
09e86496
FC
363 // ------------------------------------------------------------------------
364 // ITmfTrace - Trace characteristics getters
365 // ------------------------------------------------------------------------
366
367 /* (non-Javadoc)
368 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
b0a282fb 369 */
d4011df2 370 @Override
afc86f78 371 public synchronized long getNbEvents() {
3791b5df 372 return fNbEvents;
b0a282fb
FC
373 }
374
09e86496
FC
375 /* (non-Javadoc)
376 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange()
62d1696a 377 */
d4011df2 378 @Override
12c155f5 379 public TmfTimeRange getTimeRange() {
cb866e08 380 return new TmfTimeRange(fStartTime, fEndTime);
8c8bf09f
ASL
381 }
382
09e86496
FC
383 /* (non-Javadoc)
384 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime()
e31e01e8 385 */
d4011df2 386 @Override
4df4581d 387 public ITmfTimestamp getStartTime() {
4593bd5b 388 return fStartTime;
146a887c
FC
389 }
390
09e86496
FC
391 /* (non-Javadoc)
392 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime()
e31e01e8 393 */
d4011df2 394 @Override
4df4581d 395 public ITmfTimestamp getEndTime() {
4593bd5b 396 return fEndTime;
20658947
FC
397 }
398
399 // ------------------------------------------------------------------------
0316808c 400 // Convenience setters/getters
20658947
FC
401 // ------------------------------------------------------------------------
402
0316808c
FC
403 /**
404 * Set the trace cache size. Must be done at initialization time.
0bfb7d06 405 *
0316808c
FC
406 * @param cacheSize The trace cache size
407 */
408 protected void setCacheSize(final int cacheSize) {
409 fCacheSize = cacheSize;
410 }
411
412 /**
413 * Set the trace known number of events. This can be quite dynamic
414 * during indexing or for live traces.
0bfb7d06 415 *
0316808c
FC
416 * @param nbEvents The number of events
417 */
418 protected synchronized void setNbEvents(final long nbEvents) {
419 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
420 }
421
20658947
FC
422 /**
423 * Update the trace events time range
0bfb7d06 424 *
20658947
FC
425 * @param range the new time range
426 */
427 protected void setTimeRange(final TmfTimeRange range) {
4593bd5b
AM
428 fStartTime = range.getStartTime();
429 fEndTime = range.getEndTime();
20658947
FC
430 }
431
432 /**
433 * Update the trace chronologically first event timestamp
0bfb7d06 434 *
20658947
FC
435 * @param startTime the new first event timestamp
436 */
437 protected void setStartTime(final ITmfTimestamp startTime) {
4593bd5b 438 fStartTime = startTime;
20658947
FC
439 }
440
441 /**
442 * Update the trace chronologically last event timestamp
0bfb7d06 443 *
20658947
FC
444 * @param endTime the new last event timestamp
445 */
446 protected void setEndTime(final ITmfTimestamp endTime) {
4593bd5b 447 fEndTime = endTime;
20658947
FC
448 }
449
450 /**
0316808c 451 * Set the polling interval for live traces (default = 0 = no streaming).
0bfb7d06 452 *
20658947
FC
453 * @param interval the new trace streaming interval
454 */
455 protected void setStreamingInterval(final long interval) {
1703b536 456 fStreamingInterval = (interval > 0) ? interval : 0;
146a887c
FC
457 }
458
0316808c
FC
459 /**
460 * Set the trace indexer. Must be done at initialization time.
0bfb7d06 461 *
0316808c
FC
462 * @param indexer the trace indexer
463 */
6256d8ad 464 protected void setIndexer(final ITmfTraceIndexer indexer) {
0316808c
FC
465 fIndexer = indexer;
466 }
467
468 /**
469 * Set the trace parser. Must be done at initialization time.
0bfb7d06 470 *
0316808c
FC
471 * @param parser the new trace parser
472 */
6256d8ad 473 protected void setParser(final ITmfEventParser parser) {
0316808c
FC
474 fParser = parser;
475 }
476
09e86496 477 // ------------------------------------------------------------------------
7e6347b0 478 // ITmfTrace - SeekEvent operations (returning a trace context)
09e86496
FC
479 // ------------------------------------------------------------------------
480
481 /* (non-Javadoc)
7e6347b0 482 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
1b70b6dc
PT
483 */
484 @Override
7e6347b0 485 public synchronized ITmfContext seekEvent(final long rank) {
09e86496 486
7e6347b0 487 // A rank <= 0 indicates to seek the first event
2352aed9 488 if (rank <= 0) {
1e1bef82 489 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
490 context.setRank(0);
491 return context;
492 }
09e86496 493
09e86496 494 // Position the trace at the checkpoint
7e6347b0 495 final ITmfContext context = fIndexer.seekIndex(rank);
09e86496
FC
496
497 // And locate the requested event context
7e6347b0
FC
498 long pos = context.getRank();
499 if (pos < rank) {
c32744d6 500 ITmfEvent event = getNext(context);
0bfb7d06 501 while ((event != null) && (++pos < rank)) {
c32744d6 502 event = getNext(context);
7e6347b0 503 }
09e86496
FC
504 }
505 return context;
1b70b6dc
PT
506 }
507
09e86496 508 /* (non-Javadoc)
7e6347b0 509 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
09e86496
FC
510 */
511 @Override
7e6347b0 512 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
09e86496 513
7e6347b0 514 // A null timestamp indicates to seek the first event
2352aed9 515 if (timestamp == null) {
1e1bef82 516 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
517 context.setRank(0);
518 return context;
519 }
09e86496 520
1703b536 521 // Position the trace at the checkpoint
408e65d2 522 ITmfContext context = fIndexer.seekIndex(timestamp);
09e86496
FC
523
524 // And locate the requested event context
7e6347b0 525 final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
c32744d6 526 ITmfEvent event = getNext(nextEventContext);
7e6347b0 527 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
4c9f2944 528 context.dispose();
3cec7398 529 context = nextEventContext.clone();
c32744d6 530 event = getNext(nextEventContext);
09e86496 531 }
4c9f2944 532 nextEventContext.dispose();
0316808c
FC
533 if (event == null) {
534 context.setLocation(null);
535 context.setRank(ITmfContext.UNKNOWN_RANK);
536 }
09e86496
FC
537 return context;
538 }
0283f7ff 539
09e86496
FC
540 // ------------------------------------------------------------------------
541 // ITmfTrace - Read operations (returning an actual event)
542 // ------------------------------------------------------------------------
543
d337369a 544 /* (non-Javadoc)
b4f71e4a 545 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
abfad0aa 546 */
d4011df2 547 @Override
6256d8ad 548 public synchronized ITmfEvent getNext(final ITmfContext context) {
09e86496 549 // parseEvent() does not update the context
6256d8ad 550 final ITmfEvent event = fParser.parseEvent(context);
09e86496 551 if (event != null) {
d337369a 552 updateAttributes(context, event.getTimestamp());
09e86496
FC
553 context.setLocation(getCurrentLocation());
554 context.increaseRank();
555 processEvent(event);
556 }
557 return event;
558 }
559
560 /**
d337369a 561 * Hook for special event processing by the concrete class
7e6347b0 562 * (called by TmfTrace.getEvent())
0bfb7d06 563 *
d337369a 564 * @param event the event
09e86496
FC
565 */
566 protected void processEvent(final ITmfEvent event) {
d337369a 567 // Do nothing
09e86496
FC
568 }
569
d337369a
FC
570 /**
571 * Update the trace attributes
0bfb7d06 572 *
d337369a 573 * @param context the current trace context
2848c377 574 * @param timestamp the corresponding timestamp
d337369a
FC
575 */
576 protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
0bfb7d06 577 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
4593bd5b 578 fStartTime = timestamp;
09e86496 579 }
0bfb7d06 580 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
4593bd5b 581 fEndTime = timestamp;
09e86496
FC
582 }
583 if (context.hasValidRank()) {
d337369a 584 long rank = context.getRank();
09e86496
FC
585 if (fNbEvents <= rank) {
586 fNbEvents = rank + 1;
587 }
200789b3
AM
588 if (fIndexer != null) {
589 fIndexer.updateIndex(context, timestamp);
590 }
09e86496 591 }
abfad0aa
FC
592 }
593
3791b5df 594 // ------------------------------------------------------------------------
d337369a 595 // TmfDataProvider
3791b5df
FC
596 // ------------------------------------------------------------------------
597
d337369a
FC
598 /* (non-Javadoc)
599 * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest)
600 */
3791b5df 601 @Override
6256d8ad
AM
602 protected ITmfContext armRequest(final ITmfDataRequest request) {
603 if ((request instanceof ITmfEventRequest)
604 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
0bfb7d06 605 && (request.getIndex() == 0))
0316808c 606 {
6256d8ad
AM
607 final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
608 ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
3791b5df
FC
609 return context;
610
611 }
612 return seekEvent(request.getIndex());
613 }
614
3791b5df 615 // ------------------------------------------------------------------------
09e86496 616 // toString
3791b5df
FC
617 // ------------------------------------------------------------------------
618
d337369a
FC
619 /* (non-Javadoc)
620 * @see java.lang.Object#toString()
621 */
12c155f5 622 @Override
09e86496 623 @SuppressWarnings("nls")
afc86f78 624 public synchronized String toString() {
20658947
FC
625 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
626 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
627 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
12c155f5
FC
628 }
629
8c8bf09f 630}
This page took 0.085877 seconds and 5 git commands to generate.