[290335] Synchronization fix.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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
21 /**
22 * <b><u>TmfTraceStub</u></b>
23 * <p>
24 * TODO: Implement me. Please.
25 */
26 public class TmfTraceStub extends TmfTrace {
27
28 // ========================================================================
29 // Attributes
30 // ========================================================================
31
32 // The actual stream
33 private final RandomAccessFile fTrace;
34
35 // The associated event parser
36 private final ITmfEventParser fParser;
37
38 // ========================================================================
39 // Constructors
40 // ========================================================================
41
42 /**
43 * @param filename
44 * @throws FileNotFoundException
45 */
46 public TmfTraceStub(String filename) throws FileNotFoundException {
47 this(filename, DEFAULT_PAGE_SIZE);
48 }
49
50 /**
51 * @param filename
52 * @param cacheSize
53 * @throws FileNotFoundException
54 */
55 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
56 super(filename, cacheSize, true);
57 fTrace = new RandomAccessFile(filename, "r");
58 fParser = new TmfEventParserStub();
59 indexStream();
60 }
61
62 // ========================================================================
63 // Accessors
64 // ========================================================================
65
66 public RandomAccessFile getStream() {
67 return fTrace;
68 }
69
70 // ========================================================================
71 // Operators
72 // ========================================================================
73
74 /* (non-Javadoc)
75 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
76 */
77 public TmfTraceContext seekLocation(Object location) {
78 TmfTraceContext context = null;
79 try {
80 synchronized(fTrace) {
81 fTrace.seek((location != null) ? (Long) location : 0);
82 context = new TmfTraceContext(getCurrentLocation(), null, 0);
83 }
84 } catch (IOException e) {
85 // TODO Auto-generated catch block
86 e.printStackTrace();
87 }
88 return context;
89 }
90
91 /* (non-Javadoc)
92 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
93 */
94 @Override
95 public Object getCurrentLocation() {
96 try {
97 return new Long(fTrace.getFilePointer());
98 } catch (IOException e) {
99 // TODO Auto-generated catch block
100 e.printStackTrace();
101 }
102 return null;
103 }
104
105 /* (non-Javadoc)
106 * @see org.eclipse.linuxtools.tmf.trace.TmfTrace#parseEvent()
107 */
108 @Override
109 public synchronized TmfEvent parseEvent(TmfTraceContext context) {
110 try {
111 fTrace.seek((context.location != null) ? (Long) context.location : 0);
112 TmfEvent event = fParser.parseNextEvent(this);
113 context = new TmfTraceContext(getCurrentLocation(), null, 0);
114 return event;
115 }
116 catch (IOException e) {
117 e.printStackTrace();
118 }
119 return null;
120 }
121
122 // ========================================================================
123 // Helper functions
124 // ========================================================================
125
126 }
This page took 0.033244 seconds and 6 git commands to generate.