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
.tests
.stubs
.trace
;
15 import java
.io
.FileNotFoundException
;
16 import java
.io
.IOException
;
17 import java
.io
.RandomAccessFile
;
18 import java
.util
.concurrent
.locks
.ReentrantLock
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.parser
.ITmfEventParser
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
32 * <b><u>TmfTraceStub</u></b>
34 * Dummy test trace. Use in conjunction with TmfEventParserStub.
36 @SuppressWarnings("nls")
37 public class TmfTraceStub
extends TmfTrace
<TmfEvent
> {
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 private RandomAccessFile fTrace
;
46 // The associated event parser
47 private final ITmfEventParser
<TmfEvent
> fParser
;
49 // The synchronization lock
50 private final ReentrantLock fLock
= new ReentrantLock();
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
58 * @throws FileNotFoundException
60 public TmfTraceStub(final String path
) throws FileNotFoundException
{
61 this(path
, DEFAULT_INDEX_PAGE_SIZE
, false);
67 * @throws FileNotFoundException
69 public TmfTraceStub(final String path
, final int cacheSize
) throws FileNotFoundException
{
70 this(path
, cacheSize
, false);
75 * @param waitForCompletion
76 * @throws FileNotFoundException
78 public TmfTraceStub(final String path
, final boolean waitForCompletion
) throws FileNotFoundException
{
79 this(path
, DEFAULT_INDEX_PAGE_SIZE
, waitForCompletion
);
85 * @param waitForCompletion
86 * @throws FileNotFoundException
88 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
) throws FileNotFoundException
{
89 // super(null, TmfEvent.class, path, cacheSize, false);
90 super(null, TmfEvent
.class, path
, cacheSize
);
91 fTrace
= new RandomAccessFile(path
, "r");
92 fParser
= new TmfEventParserStub();
99 * @param waitForCompletion
101 * @throws FileNotFoundException
103 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
, final ITmfEventParser
<TmfEvent
> parser
) throws FileNotFoundException
{
104 // super(null, TmfEvent.class, path, cacheSize, false);
105 super(null, TmfEvent
.class, path
, cacheSize
);
106 fTrace
= new RandomAccessFile(path
, "r");
113 public TmfTraceStub(final TmfTraceStub trace
) throws FileNotFoundException
{
114 // super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize(), false);
115 super(trace
.getResource(), TmfEvent
.class, trace
.getPath(), trace
.getIndexPageSize());
116 fTrace
= new RandomAccessFile(getPath(), "r");
117 fParser
= new TmfEventParserStub();
118 // This is really not pretty (the object is not constructed yet...)
125 // public TmfTraceStub clone() {
126 // TmfTraceStub clone = null;
128 // clone = (TmfTraceStub) super.clone();
129 // clone.fTrace = new RandomAccessFile(getPath(), "r");
130 // clone.fParser = new TmfEventParserStub();
131 // } catch (final FileNotFoundException e) {
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
140 public RandomAccessFile
getStream() {
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 @SuppressWarnings("unchecked")
150 public TmfContext
seekLocation(final ITmfLocation
<?
> location
) {
154 if (fTrace
!= null) {
155 // Position the trace at the requested location and
156 // returns the corresponding context
159 if (location
!= null) {
160 loc
= ((TmfLocation
<Long
>) location
).getLocation();
161 rank
= ITmfContext
.UNKNOWN_RANK
;
163 if (loc
!= fTrace
.getFilePointer())
165 final TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
168 } catch (final IOException e
) {
170 } catch (final NullPointerException e
) {
173 } catch (final NullPointerException e
) {
184 public TmfContext
seekLocation(final double ratio
) {
187 if (fTrace
!= null) {
188 final ITmfLocation
<?
> location
= new TmfLocation
<Long
>(Long
.valueOf((long) (ratio
* fTrace
.length())));
189 final TmfContext context
= seekLocation(location
);
190 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
193 } catch (final IOException e
) {
203 @SuppressWarnings("rawtypes")
204 public double getLocationRatio(final ITmfLocation location
) {
208 if (location
.getLocation() instanceof Long
)
209 return (double) ((Long
) location
.getLocation()) / fTrace
.length();
210 } catch (final IOException e
) {
219 public TmfLocation
<Long
> getCurrentLocation() {
223 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
224 } catch (final IOException e
) {
233 public ITmfEvent
parseEvent(final ITmfContext context
) {
236 // parseNextEvent will update the context
237 if (fTrace
!= null) {
238 final ITmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
242 catch (final IOException e
) {
251 public void setTimeRange(final TmfTimeRange range
) {
252 super.setTimeRange(range
);
256 public void setStartTime(final ITmfTimestamp startTime
) {
257 super.setStartTime(startTime
);
261 public void setEndTime(final ITmfTimestamp endTime
) {
262 super.setEndTime(endTime
);
266 public void dispose() {
269 if (fTrace
!= null) {
273 } catch (final IOException e
) {
This page took 0.037398 seconds and 6 git commands to generate.