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
) {
144 public TmfLocation
<Long
> getCurrentLocation() {
146 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
147 } catch (IOException e
) {
154 public TmfEvent
parseEvent(TmfContext context
) {
156 // parseNextEvent will update the context
157 TmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
160 catch (IOException e
) {
167 public void setTimeRange(TmfTimeRange range
) {
168 super.setTimeRange(range
);
172 public void setStartTime(TmfTimestamp startTime
) {
173 super.setStartTime(startTime
);
177 public void setEndTime(TmfTimestamp endTime
) {
178 super.setEndTime(endTime
);