1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.trace
;
15 import java
.io
.FileNotFoundException
;
16 import java
.io
.IOException
;
17 import java
.io
.RandomAccessFile
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.parser
.ITmfEventParser
;
25 * <b><u>TmfTraceStub</u></b>
27 * Dummy test trace. Use in conjunction with TmfEventParserStub.
29 public class TmfTraceStub
extends TmfTrace
<TmfEvent
> {
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
36 private RandomAccessFile fTrace
;
38 // The associated event parser
39 private ITmfEventParser fParser
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
47 * @throws FileNotFoundException
49 public TmfTraceStub(String filename
) throws FileNotFoundException
{
50 super("TmfTraceStub", TmfEvent
.class, filename
);
51 fTrace
= new RandomAccessFile(filename
, "r");
52 fParser
= new TmfEventParserStub();
58 * @throws FileNotFoundException
60 public TmfTraceStub(String filename
, int cacheSize
) throws FileNotFoundException
{
61 this(filename
, cacheSize
, false);
66 * @param waitForCompletion
67 * @throws FileNotFoundException
69 public TmfTraceStub(String filename
, boolean waitForCompletion
) throws FileNotFoundException
{
70 this(filename
, DEFAULT_CACHE_SIZE
, waitForCompletion
);
76 * @param waitForCompletion
77 * @throws FileNotFoundException
79 public TmfTraceStub(String filename
, int cacheSize
, boolean waitForCompletion
) throws FileNotFoundException
{
80 super(filename
, TmfEvent
.class, filename
, cacheSize
);
81 fTrace
= new RandomAccessFile(filename
, "r");
82 fParser
= new TmfEventParserStub();
88 // public TmfTraceStub(TmfTraceStub other) {
89 // this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
95 public TmfTraceStub
clone() {
96 TmfTraceStub clone
= null;
98 clone
= (TmfTraceStub
) super.clone();
99 clone
.fTrace
= new RandomAccessFile(getName(), "r");
100 clone
.fParser
= new TmfEventParserStub();
101 } catch (CloneNotSupportedException e
) {
102 } catch (FileNotFoundException e
) {
107 public ITmfTrace
createTraceCopy() {
108 ITmfTrace returnedValue
= null;
110 returnedValue
= new TmfTraceStub(this.getName());
112 catch (FileNotFoundException e
) {
113 // e.printStackTrace();
115 return returnedValue
;
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
122 public RandomAccessFile
getStream() {
126 // ------------------------------------------------------------------------
128 // ------------------------------------------------------------------------
131 @SuppressWarnings("unchecked")
132 public TmfContext
seekLocation(ITmfLocation
<?
> location
) {
134 synchronized(fTrace
) {
135 // Position the trace at the requested location and
136 // returns the corresponding context
139 if (location
!= null) {
140 loc
= ((TmfLocation
<Long
>) location
).getLocation();
141 rank
= ITmfContext
.UNKNOWN_RANK
;
143 if (loc
!= fTrace
.getFilePointer()) {
146 TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
149 } catch (IOException e
) {
156 public TmfLocation
<Long
> getCurrentLocation() {
158 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
159 } catch (IOException e
) {
166 public TmfEvent
parseEvent(TmfContext context
) {
168 // paserNextEvent updates the context
169 TmfEvent event
= fParser
.parseNextEvent(this, context
);
172 catch (IOException e
) {
179 public void setTimeRange(TmfTimeRange range
) {
180 super.setTimeRange(range
);
184 public void setStartTime(TmfTimestamp startTime
) {
185 super.setStartTime(startTime
);
189 public void setEndTime(TmfTimestamp endTime
) {
190 super.setEndTime(endTime
);