[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.trace;
14
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18
19 import org.eclipse.linuxtools.tmf.event.TmfEvent;
20 import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
21
22 /**
23 * <b><u>TmfTraceStub</u></b>
24 * <p>
25 * Dummy test trace. Use in conjunction with TmfEventParserStub.
26 */
27 public class TmfTraceStub extends TmfTrace<TmfEvent> {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 // The actual stream
34 private final RandomAccessFile fTrace;
35
36 // The associated event parser
37 private final ITmfEventParser fParser;
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
43 /**
44 * @param filename
45 * @throws FileNotFoundException
46 */
47 public TmfTraceStub(String filename) throws FileNotFoundException {
48 this(filename, DEFAULT_CACHE_SIZE, false);
49 }
50
51 /**
52 * @param filename
53 * @param cacheSize
54 * @throws FileNotFoundException
55 */
56 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
57 this(filename, cacheSize, false);
58 }
59
60 /**
61 * @param filename
62 * @throws FileNotFoundException
63 */
64 public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
65 this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
66 }
67
68 /**
69 * @param filename
70 * @param cacheSize
71 * @throws FileNotFoundException
72 */
73 public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
74 super(TmfEvent.class, filename, cacheSize);
75 fTrace = new RandomAccessFile(filename, "r");
76 fParser = new TmfEventParserStub();
77 indexTrace(waitForCompletion);
78 }
79
80 // ------------------------------------------------------------------------
81 // Accessors
82 // ------------------------------------------------------------------------
83
84 public RandomAccessFile getStream() {
85 return fTrace;
86 }
87
88 // ------------------------------------------------------------------------
89 // Operators
90 // ------------------------------------------------------------------------
91
92 /* (non-Javadoc)
93 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
94 */
95 public TmfTraceContext seekLocation(Object location) {
96 try {
97 synchronized(fTrace) {
98 // Position the trace, read the event (to obtain its timestamp)
99 // and then re-position the trace (not great...)
100 fTrace.seek((location != null) ? (Long) location : 0);
101 TmfTraceContext context = new TmfTraceContext(getCurrentLocation());
102 return context;
103 }
104 } catch (IOException e) {
105 e.printStackTrace();
106 }
107 return null;
108 }
109
110 /* (non-Javadoc)
111 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
112 */
113 @Override
114 public Object getCurrentLocation() {
115 try {
116 return new Long(fTrace.getFilePointer());
117 } catch (IOException e) {
118 // TODO Auto-generated catch block
119 e.printStackTrace();
120 }
121 return null;
122 }
123
124 /* (non-Javadoc)
125 * @see org.eclipse.linuxtools.tmf.trace.TmfTrace#parseEvent()
126 */
127 @Override
128 public TmfEvent parseEvent(TmfTraceContext context) {
129 try {
130 // paserNextEvent updates the context
131 TmfEvent event = fParser.parseNextEvent(this, context);
132 return event;
133 }
134 catch (IOException e) {
135 e.printStackTrace();
136 }
137 return null;
138 }
139
140 }
This page took 0.03574 seconds and 5 git commands to generate.