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
.trace
.ITmfContext
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
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
> implements ITmfEventParser
<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(this);
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(this);
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(this);
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(this);
140 * @param waitForCompletion
142 * @throws FileNotFoundException
144 @SuppressWarnings("unchecked")
145 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
,
146 final ITmfEventParser
<TmfEvent
> parser
, final ITmfTraceIndexer
<?
> indexer
) throws FileNotFoundException
{
147 super(null, TmfEvent
.class, path
, cacheSize
, 0, indexer
);
148 fTrace
= new RandomAccessFile(path
, "r");
149 fParser
= (ITmfEventParser
<ITmfEvent
>) ((parser
!= null) ? parser
: new TmfEventParserStub(this));
155 public TmfTraceStub(final TmfTraceStub trace
) throws FileNotFoundException
{
157 fTrace
= new RandomAccessFile(getPath(), "r");
158 fParser
= new TmfEventParserStub(this);
161 public void indexTrace() {
162 fIndexer
.buildIndex(true);
166 public void initTrace(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws FileNotFoundException
{
167 fTrace
= new RandomAccessFile(path
, "r");
168 fParser
= new TmfEventParserStub(this);
169 super.initTrace(resource
, path
, type
);
173 public void initialize(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws FileNotFoundException
{
174 super.initialize(resource
, path
, type
);
177 // ------------------------------------------------------------------------
179 // ------------------------------------------------------------------------
181 public RandomAccessFile
getStream() {
185 // ------------------------------------------------------------------------
187 // ------------------------------------------------------------------------
190 @SuppressWarnings("unchecked")
191 public TmfContext
seekEvent(final ITmfLocation
<?
> location
) {
195 if (fTrace
!= null) {
196 // Position the trace at the requested location and
197 // returns the corresponding context
200 if (location
!= null) {
201 loc
= ((TmfLocation
<Long
>) location
).getLocation();
202 rank
= ITmfContext
.UNKNOWN_RANK
;
204 if (loc
!= fTrace
.getFilePointer()) {
207 final TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
210 } catch (final IOException e
) {
212 } catch (final NullPointerException e
) {
215 } catch (final NullPointerException e
) {
226 public TmfContext
seekEvent(final double ratio
) {
229 if (fTrace
!= null) {
230 final ITmfLocation
<?
> location
= new TmfLocation
<Long
>(Long
.valueOf((long) (ratio
* fTrace
.length())));
231 final TmfContext context
= seekEvent(location
);
232 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
235 } catch (final IOException e
) {
245 @SuppressWarnings("rawtypes")
246 public double getLocationRatio(final ITmfLocation location
) {
250 if (location
.getLocation() instanceof Long
)
251 return (double) ((Long
) location
.getLocation()) / fTrace
.length();
252 } catch (final IOException e
) {
261 public TmfLocation
<Long
> getCurrentLocation() {
265 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
266 } catch (final IOException e
) {
275 public ITmfEvent
parseEvent(final ITmfContext context
) {
278 // parseNextEvent will update the context
279 if (fTrace
!= null) {
280 final ITmfEvent event
= fParser
.parseEvent(context
.clone());
284 // catch (final IOException e) {
285 // e.printStackTrace();
293 public void setTimeRange(final TmfTimeRange range
) {
294 super.setTimeRange(range
);
298 public void setStartTime(final ITmfTimestamp startTime
) {
299 super.setStartTime(startTime
);
303 public void setEndTime(final ITmfTimestamp endTime
) {
304 super.setEndTime(endTime
);
308 public void setStreamingInterval(final long interval
) {
309 super.setStreamingInterval(interval
);
313 public void dispose() {
316 if (fTrace
!= null) {
320 } catch (final IOException e
) {
This page took 0.039208 seconds and 5 git commands to generate.