595796d88bbebb0403b57063808738cd1f25fcc5
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
.IProject
;
21 import org
.eclipse
.core
.resources
.IResource
;
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
.exceptions
.TmfTraceException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTraceIndexer
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
36 * <b><u>TmfTraceStub</u></b>
38 * Dummy test trace. Use in conjunction with TmfEventParserStub.
40 @SuppressWarnings("nls")
41 public class TmfTraceStub
extends TmfTrace
<TmfEvent
> implements ITmfEventParser
<TmfEvent
> {
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
48 private RandomAccessFile fTrace
;
50 // // The associated event parser
51 // private ITmfEventParser<TmfEvent> fParser;
53 // The synchronization lock
54 private final ReentrantLock fLock
= new ReentrantLock();
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 public TmfTraceStub() {
62 setParser(new TmfEventParserStub(this));
67 * @throws FileNotFoundException
69 public TmfTraceStub(final String path
) throws TmfTraceException
{
70 this(path
, ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, false);
76 * @throws FileNotFoundException
78 public TmfTraceStub(final String path
, final int cacheSize
) throws TmfTraceException
{
79 this(path
, cacheSize
, false);
85 * @throws FileNotFoundException
87 public TmfTraceStub(final String path
, final int cacheSize
, final long interval
) throws TmfTraceException
{
88 super(null, TmfEvent
.class, path
, cacheSize
, interval
);
90 fTrace
= new RandomAccessFile(path
, "r");
91 } catch (FileNotFoundException e
) {
92 throw new TmfTraceException(e
.getMessage());
94 setParser(new TmfEventParserStub(this));
100 * @throws FileNotFoundException
102 public TmfTraceStub(final String path
, final int cacheSize
, final ITmfTraceIndexer
<?
> indexer
) throws TmfTraceException
{
103 this(path
, cacheSize
, false, null, indexer
);
108 * @param waitForCompletion
109 * @throws FileNotFoundException
111 public TmfTraceStub(final String path
, final boolean waitForCompletion
) throws TmfTraceException
{
112 this(path
, ITmfTrace
.DEFAULT_TRACE_CACHE_SIZE
, waitForCompletion
);
118 * @param waitForCompletion
119 * @throws FileNotFoundException
121 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
) throws TmfTraceException
{
122 super(null, TmfEvent
.class, path
, cacheSize
);
124 fTrace
= new RandomAccessFile(path
, "r");
125 } catch (FileNotFoundException e
) {
126 throw new TmfTraceException(e
.getMessage());
128 setParser(new TmfEventParserStub(this));
129 if (waitForCompletion
) {
137 * @param waitForCompletion
138 * @throws FileNotFoundException
140 public TmfTraceStub(final IResource resource
, final String path
, final int cacheSize
, final boolean waitForCompletion
) throws TmfTraceException
{
141 super(resource
, TmfEvent
.class, path
, cacheSize
);
143 fTrace
= new RandomAccessFile(path
, "r");
144 } catch (FileNotFoundException e
) {
145 throw new TmfTraceException(e
.getMessage());
147 setParser(new TmfEventParserStub(this));
153 * @param waitForCompletion
155 * @throws FileNotFoundException
157 public TmfTraceStub(final String path
, final int cacheSize
, final boolean waitForCompletion
,
158 final ITmfEventParser
<TmfEvent
> parser
, final ITmfTraceIndexer
<?
> indexer
) throws TmfTraceException
{
159 super(null, TmfEvent
.class, path
, cacheSize
, 0, indexer
);
161 fTrace
= new RandomAccessFile(path
, "r");
162 } catch (FileNotFoundException e
) {
163 throw new TmfTraceException(e
.getMessage());
165 setParser((parser
!= null) ? parser
: new TmfEventParserStub(this));
171 public TmfTraceStub(final TmfTraceStub trace
) throws TmfTraceException
{
174 fTrace
= new RandomAccessFile(getPath(), "r");
175 } catch (FileNotFoundException e
) {
176 throw new TmfTraceException(e
.getMessage());
178 setParser(new TmfEventParserStub(this));
181 public void indexTrace() {
186 public void initTrace(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws TmfTraceException
{
188 fTrace
= new RandomAccessFile(path
, "r");
189 } catch (FileNotFoundException e
) {
190 throw new TmfTraceException(e
.getMessage());
192 setParser(new TmfEventParserStub(this));
193 super.initTrace(resource
, path
, type
);
197 public void initialize(final IResource resource
, final String path
, final Class
<TmfEvent
> type
) throws TmfTraceException
{
198 super.initialize(resource
, path
, type
);
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
205 public RandomAccessFile
getStream() {
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
214 @SuppressWarnings("unchecked")
215 public TmfContext
seekEvent(final ITmfLocation
<?
> location
) {
219 if (fTrace
!= null) {
220 // Position the trace at the requested location and
221 // returns the corresponding context
224 if (location
!= null) {
225 loc
= ((TmfLocation
<Long
>) location
).getLocation();
226 rank
= ITmfContext
.UNKNOWN_RANK
;
228 if (loc
!= fTrace
.getFilePointer()) {
231 final TmfContext context
= new TmfContext(getCurrentLocation(), rank
);
234 } catch (final IOException e
) {
236 } catch (final NullPointerException e
) {
242 } catch (final NullPointerException e
) {
250 public TmfContext
seekEvent(final double ratio
) {
253 if (fTrace
!= null) {
254 final ITmfLocation
<?
> location
= new TmfLocation
<Long
>(Long
.valueOf((long) (ratio
* fTrace
.length())));
255 final TmfContext context
= seekEvent(location
);
256 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
259 } catch (final IOException e
) {
269 public double getLocationRatio(ITmfLocation
<?
> location
) {
272 if (fTrace
!= null) {
273 if (location
.getLocation() instanceof Long
) {
274 return (double) ((Long
) location
.getLocation()) / fTrace
.length();
277 } catch (final IOException e
) {
286 public TmfLocation
<Long
> getCurrentLocation() {
289 if (fTrace
!= null) {
290 return new TmfLocation
<Long
>(fTrace
.getFilePointer());
292 } catch (final IOException e
) {
301 public TmfEvent
parseEvent(final ITmfContext context
) {
304 // parseNextEvent will update the context
305 if (fTrace
!= null && getParser() != null && context
!= null) {
306 final TmfEvent event
= getParser().parseEvent(context
.clone());
316 public synchronized void setNbEvents(final long nbEvents
) {
317 super.setNbEvents(nbEvents
);
321 public void setTimeRange(final TmfTimeRange range
) {
322 super.setTimeRange(range
);
326 public void setStartTime(final ITmfTimestamp startTime
) {
327 super.setStartTime(startTime
);
331 public void setEndTime(final ITmfTimestamp endTime
) {
332 super.setEndTime(endTime
);
336 public void setStreamingInterval(final long interval
) {
337 super.setStreamingInterval(interval
);
341 public synchronized void dispose() {
344 if (fTrace
!= null) {
348 } catch (final IOException e
) {
357 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
360 public boolean validate(IProject project
, String path
) {
361 return fileExists(path
);
This page took 0.044796 seconds and 4 git commands to generate.