c9d032d4e6780cce4848d9bf057646a08a00036d
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
.core
.resources
.IResource
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.parser
.ITmfEventParser
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTraceIndexer
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
34 * <b><u>TmfTraceStub</u></b>
36 * Dummy test trace. Use in conjunction with TmfEventParserStub.
38 @SuppressWarnings("nls")
39 public class TmfTraceStub
extends TmfTrace
<TmfEvent
> {
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 private RandomAccessFile fTrace
;
48 // The associated event parser
49 private ITmfEventParser
<TmfEvent
> fParser
;
51 // The synchronization lock
52 private final ReentrantLock fLock
= new ReentrantLock();
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
60 * @throws FileNotFoundException
62 public TmfTraceStub() {
64 fParser
= new TmfEventParserStub();
69 * @throws FileNotFoundException
71 public TmfTraceStub(final String path
) throws FileNotFoundException
{
72 this(path
, DEFAULT_TRACE_CACHE_SIZE
, false);
78 * @throws FileNotFoundException
80 public TmfTraceStub(final String path
, final int cacheSize
) throws FileNotFoundException
{
81 this(path
, cacheSize
, false);
87 * @throws FileNotFoundException
89 public TmfTraceStub(final String path
, final int cacheSize
, final long interval
) throws FileNotFoundException
{
90 super(null, TmfEvent
.class, path
, cacheSize
, interval
);
91 fTrace
= new RandomAccessFile(path
, "r");
92 fParser
= new TmfEventParserStub();
98 * @throws FileNotFoundException
100 public TmfTraceStub(final String path
, final int cacheSize
, final ITmfTraceIndexer
<?
> indexer
) throws FileNotFoundException
{
101 this(path
, cacheSize
, false, null, indexer
);
106 * @param waitForCompletion
107 * @throws FileNotFoundException
109 public TmfTraceStub(final String path
, final boolean waitForCompletion
) throws FileNotFoundException
{
110 this(path
, DEFAULT_TRACE_CACHE_SIZE
, waitForCompletion
);
116 * @param waitForCompletion
117 * @throws FileNotFoundException
119 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
) throws FileNotFoundException
{
120 super(null, TmfEvent
.class, path
, cacheSize
);
121 fTrace
= new RandomAccessFile(path
, "r");
122 fParser
= new TmfEventParserStub();
128 * @param waitForCompletion
129 * @throws FileNotFoundException
131 public TmfTraceStub(final IResource resource
, final String path
, final int cacheSize
, final boolean waitForCompletion
) throws FileNotFoundException
{
132 super(resource
, TmfEvent
.class, path
, cacheSize
);
133 fTrace
= new RandomAccessFile(path
, "r");
134 fParser
= new TmfEventParserStub();
140 * @param waitForCompletion
142 * @throws FileNotFoundException
144 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
,
145 final ITmfEventParser
<TmfEvent
> parser
, final ITmfTraceIndexer
<?
> indexer
) throws FileNotFoundException
{
146 super(null, TmfEvent
.class, path
, cacheSize
, 0, indexer
);
147 fTrace
= new RandomAccessFile(path
, "r");
148 fParser
= (parser
!= null) ? parser
: new TmfEventParserStub();
154 public TmfTraceStub(final TmfTraceStub trace
) throws FileNotFoundException
{
156 fTrace
= new RandomAccessFile(getPath(), "r");
157 fParser
= new TmfEventParserStub();
160 public void indexTrace() {
161 fIndexer
.buildIndex(true);
165 public void initTrace(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws FileNotFoundException
{
166 fTrace
= new RandomAccessFile(path
, "r");
167 fParser
= new TmfEventParserStub();
168 super.initTrace(resource
, path
, type
);
172 public void initialize(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws FileNotFoundException
{
173 super.initialize(resource
, path
, type
);
176 // ------------------------------------------------------------------------
178 // ------------------------------------------------------------------------
180 public RandomAccessFile
getStream() {
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
189 @SuppressWarnings("unchecked")
190 public TmfContext
seekLocation(final ITmfLocation
<?
> location
) {
194 if (fTrace
!= null) {
195 // Position the trace at the requested location and
196 // returns the corresponding context
199 if (location
!= null) {
200 loc
= ((TmfLocation
<Long
>) location
).getLocation();
201 rank
= ITmfContext
.UNKNOWN_RANK
;
203 if (loc
!= fTrace
.getFilePointer()) {
206 final TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
209 } catch (final IOException e
) {
211 } catch (final NullPointerException e
) {
214 } catch (final NullPointerException e
) {
225 public TmfContext
seekLocation(final double ratio
) {
228 if (fTrace
!= null) {
229 final ITmfLocation
<?
> location
= new TmfLocation
<Long
>(Long
.valueOf((long) (ratio
* fTrace
.length())));
230 final TmfContext context
= seekLocation(location
);
231 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
234 } catch (final IOException e
) {
244 @SuppressWarnings("rawtypes")
245 public double getLocationRatio(final ITmfLocation location
) {
249 if (location
.getLocation() instanceof Long
)
250 return (double) ((Long
) location
.getLocation()) / fTrace
.length();
251 } catch (final IOException e
) {
260 public TmfLocation
<Long
> getCurrentLocation() {
264 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
265 } catch (final IOException e
) {
274 public ITmfEvent
parseEvent(final ITmfContext context
) {
277 // parseNextEvent will update the context
278 if (fTrace
!= null) {
279 final ITmfEvent event
= fParser
.parseNextEvent(this, context
.clone());
283 catch (final IOException e
) {
292 public void setTimeRange(final TmfTimeRange range
) {
293 super.setTimeRange(range
);
297 public void setStartTime(final ITmfTimestamp startTime
) {
298 super.setStartTime(startTime
);
302 public void setEndTime(final ITmfTimestamp endTime
) {
303 super.setEndTime(endTime
);
307 public void setStreamingInterval(final long interval
) {
308 super.setStreamingInterval(interval
);
312 public void dispose() {
315 if (fTrace
!= null) {
319 } catch (final IOException e
) {
This page took 0.037315 seconds and 4 git commands to generate.