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 this(filename
, DEFAULT_INDEX_PAGE_SIZE
, false);
56 * @throws FileNotFoundException
58 public TmfTraceStub(String filename
, int cacheSize
) throws FileNotFoundException
{
59 this(filename
, cacheSize
, false);
64 * @param waitForCompletion
65 * @throws FileNotFoundException
67 public TmfTraceStub(String filename
, boolean waitForCompletion
) throws FileNotFoundException
{
68 this(filename
, DEFAULT_INDEX_PAGE_SIZE
, waitForCompletion
);
74 * @param waitForCompletion
75 * @throws FileNotFoundException
77 public TmfTraceStub(String filename
, int cacheSize
, boolean waitForCompletion
) throws FileNotFoundException
{
78 super(filename
, TmfEvent
.class, filename
, cacheSize
);
79 fTrace
= new RandomAccessFile(filename
, "r");
80 fParser
= new TmfEventParserStub();
86 public TmfTraceStub
clone() {
87 TmfTraceStub clone
= null;
89 clone
= (TmfTraceStub
) super.clone();
90 clone
.fTrace
= new RandomAccessFile(getPath(), "r");
91 clone
.fParser
= new TmfEventParserStub();
92 } catch (CloneNotSupportedException e
) {
93 } catch (FileNotFoundException e
) {
99 public ITmfTrace
createTraceCopy() {
100 ITmfTrace returnedValue
= null;
101 returnedValue
= clone();
102 return returnedValue
;
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
109 public RandomAccessFile
getStream() {
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
118 @SuppressWarnings("unchecked")
119 public TmfContext
seekLocation(ITmfLocation
<?
> location
) {
121 synchronized(fTrace
) {
122 // Position the trace at the requested location and
123 // returns the corresponding context
126 if (location
!= null) {
127 loc
= ((TmfLocation
<Long
>) location
).getLocation();
128 rank
= ITmfContext
.UNKNOWN_RANK
;
130 if (loc
!= fTrace
.getFilePointer()) {
133 TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
136 } catch (IOException e
) {
143 public TmfLocation
<Long
> getCurrentLocation() {
145 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
146 } catch (IOException e
) {
153 public TmfEvent
parseEvent(TmfContext context
) {
155 // parseNextEvent will update the context
156 TmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
159 catch (IOException e
) {
166 public void setTimeRange(TmfTimeRange range
) {
167 super.setTimeRange(range
);
171 public void setStartTime(TmfTimestamp startTime
) {
172 super.setStartTime(startTime
);
176 public void setEndTime(TmfTimestamp endTime
) {
177 super.setEndTime(endTime
);