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 @SuppressWarnings("nls")
30 public class TmfTraceStub
extends TmfTrace
<TmfEvent
> {
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
37 private RandomAccessFile fTrace
;
39 // The associated event parser
40 private ITmfEventParser fParser
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
48 * @throws FileNotFoundException
50 public TmfTraceStub(String filename
) throws FileNotFoundException
{
51 this(filename
, DEFAULT_INDEX_PAGE_SIZE
, false);
57 * @throws FileNotFoundException
59 public TmfTraceStub(String filename
, int cacheSize
) throws FileNotFoundException
{
60 this(filename
, cacheSize
, false);
65 * @param waitForCompletion
66 * @throws FileNotFoundException
68 public TmfTraceStub(String filename
, boolean waitForCompletion
) throws FileNotFoundException
{
69 this(filename
, DEFAULT_INDEX_PAGE_SIZE
, waitForCompletion
);
75 * @param waitForCompletion
76 * @throws FileNotFoundException
78 public TmfTraceStub(String filename
, int cacheSize
, boolean waitForCompletion
) throws FileNotFoundException
{
79 super(filename
, TmfEvent
.class, filename
, cacheSize
);
80 fTrace
= new RandomAccessFile(filename
, "r");
81 fParser
= new TmfEventParserStub();
87 public TmfTraceStub
clone() {
88 TmfTraceStub clone
= null;
90 clone
= (TmfTraceStub
) super.clone();
91 clone
.fTrace
= new RandomAccessFile(getPath(), "r");
92 clone
.fParser
= new TmfEventParserStub();
93 } catch (CloneNotSupportedException e
) {
94 } catch (FileNotFoundException e
) {
100 public ITmfTrace
createTraceCopy() {
101 ITmfTrace returnedValue
= null;
102 returnedValue
= clone();
103 return returnedValue
;
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
110 public RandomAccessFile
getStream() {
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
119 @SuppressWarnings("unchecked")
120 public TmfContext
seekLocation(ITmfLocation
<?
> location
) {
122 synchronized(fTrace
) {
123 // Position the trace at the requested location and
124 // returns the corresponding context
127 if (location
!= null) {
128 loc
= ((TmfLocation
<Long
>) location
).getLocation();
129 rank
= ITmfContext
.UNKNOWN_RANK
;
131 if (loc
!= fTrace
.getFilePointer()) {
134 TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
137 } catch (IOException e
) {
145 public TmfContext
seekLocation(double ratio
) {
147 ITmfLocation
<?
> location
= new TmfLocation
<Long
>(new Long((long) (ratio
* fTrace
.length())));
148 TmfContext context
= seekLocation(location
);
149 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
151 } catch (IOException e
) {
158 public double getLocationRatio(ITmfLocation
<?
> location
) {
160 if (location
.getLocation() instanceof Long
) {
161 return (double) ((Long
) location
.getLocation()) / fTrace
.length();
163 } catch (IOException e
) {
170 public TmfLocation
<Long
> getCurrentLocation() {
172 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
173 } catch (IOException e
) {
180 public TmfEvent
parseEvent(TmfContext context
) {
182 // parseNextEvent will update the context
183 TmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
186 catch (IOException e
) {
193 public void setTimeRange(TmfTimeRange range
) {
194 super.setTimeRange(range
);
198 public void setStartTime(TmfTimestamp startTime
) {
199 super.setStartTime(startTime
);
203 public void setEndTime(TmfTimestamp endTime
) {
204 super.setEndTime(endTime
);