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_CACHE_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_CACHE_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
) {
98 public ITmfTrace
createTraceCopy() {
99 ITmfTrace returnedValue
= null;
100 returnedValue
= clone();
101 return returnedValue
;
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
108 public RandomAccessFile
getStream() {
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 @SuppressWarnings("unchecked")
118 public TmfContext
seekLocation(ITmfLocation
<?
> location
) {
120 synchronized(fTrace
) {
121 // Position the trace at the requested location and
122 // returns the corresponding context
125 if (location
!= null) {
126 loc
= ((TmfLocation
<Long
>) location
).getLocation();
127 rank
= ITmfContext
.UNKNOWN_RANK
;
129 if (loc
!= fTrace
.getFilePointer()) {
132 TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
135 } catch (IOException e
) {
142 public TmfLocation
<Long
> getCurrentLocation() {
144 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
145 } catch (IOException e
) {
152 public TmfEvent
parseEvent(TmfContext context
) {
154 // parseNextEvent will update the context
155 TmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
158 catch (IOException e
) {
165 public void setTimeRange(TmfTimeRange range
) {
166 super.setTimeRange(range
);
170 public void setStartTime(TmfTimestamp startTime
) {
171 super.setStartTime(startTime
);
175 public void setEndTime(TmfTimestamp endTime
) {
176 super.setEndTime(endTime
);