Commit | Line | Data |
---|---|---|
a52fde77 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal | |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
5df842b3 | 5 | * |
a52fde77 AM |
6 | * All rights reserved. This program and the accompanying materials are |
7 | * made available under the terms of the Eclipse Public License v1.0 which | |
8 | * accompanies this distribution, and is available at | |
9 | * http://www.eclipse.org/legal/epl-v10.html | |
5df842b3 | 10 | * |
a52fde77 AM |
11 | *******************************************************************************/ |
12 | ||
2ab9afbc | 13 | package org.eclipse.linuxtools.internal.tmf.core.statesystem; |
a52fde77 AM |
14 | |
15 | import java.io.File; | |
16 | import java.io.FileInputStream; | |
17 | import java.io.PrintWriter; | |
18 | import java.util.List; | |
19 | ||
6d08acca AM |
20 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
21 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
a52fde77 | 22 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; |
a52fde77 AM |
23 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
24 | ||
25 | /** | |
26 | * The main difference between StateSystem and StateHistorySystem is that SHS | |
27 | * allows 'seeking' back in time to reload a Current State at a previous time. | |
28 | * "How to go back in time" is defined by the implementation of the | |
29 | * HistoryBackend. | |
5df842b3 | 30 | * |
a52fde77 AM |
31 | * A StateHistorySystem contains one and only one HistoryBackend. If you want to |
32 | * use a paradigm with more than one provider (eg. more or less precision | |
33 | * depending on what's asked by the user), implement one wrapper HistoryBackend | |
34 | * which can then contain your 2-3 other backends underneath. | |
5df842b3 | 35 | * |
a52fde77 | 36 | * @author alexmont |
5df842b3 | 37 | * |
a52fde77 AM |
38 | */ |
39 | public interface IStateHistoryBackend { | |
40 | ||
41 | /** | |
42 | * Get the start time of this state history. This is usually the same as the | |
43 | * start time of the originating trace. | |
5df842b3 | 44 | * |
a52fde77 AM |
45 | * @return The start time |
46 | */ | |
47 | public long getStartTime(); | |
48 | ||
49 | /** | |
50 | * Get the current end time of the state history. It will change as the | |
51 | * history is being built. | |
5df842b3 | 52 | * |
a52fde77 AM |
53 | * @return The end time |
54 | */ | |
55 | public long getEndTime(); | |
56 | ||
57 | /** | |
58 | * Main method to insert state intervals into the history. | |
5df842b3 | 59 | * |
a52fde77 AM |
60 | * @param stateStartTime |
61 | * The start time of the interval | |
62 | * @param stateEndTime | |
63 | * The end time of the interval | |
64 | * @param quark | |
65 | * The quark of the attribute this interval refers to | |
66 | * @param value | |
67 | * The StateValue represented by this interval | |
68 | * @throws TimeRangeException | |
69 | * If the start or end time are invalid | |
70 | */ | |
71 | // FIXME change to IStateInterval? | |
72 | public void insertPastState(long stateStartTime, long stateEndTime, | |
73 | int quark, ITmfStateValue value) throws TimeRangeException; | |
74 | ||
75 | /** | |
76 | * Indicate to the provider that we are done building the history (so it can | |
77 | * close off, stop threads, etc.) | |
5df842b3 | 78 | * |
a52fde77 AM |
79 | * @param endTime |
80 | * The end time to assign to this state history. It could be | |
81 | * farther in time than the last state inserted, for example. | |
82 | * @throws TimeRangeException | |
83 | * If the requested time makes no sense. | |
84 | */ | |
85 | public void finishedBuilding(long endTime) throws TimeRangeException; | |
86 | ||
87 | /** | |
88 | * It is the responsibility of the backend to define where to save the | |
89 | * Attribute Tree (since it's only useful to "reopen" an Attribute Tree if | |
90 | * we have the matching History). | |
5df842b3 | 91 | * |
a52fde77 AM |
92 | * This method defines where to read for the attribute tree when opening an |
93 | * already-existing history. Refer to the file format documentation. | |
5df842b3 | 94 | * |
a52fde77 AM |
95 | * @return A FileInputStream object pointing to the correct file/location in |
96 | * the file where to read the attribute tree information. | |
97 | */ | |
98 | public FileInputStream supplyAttributeTreeReader(); | |
99 | ||
100 | // FIXME change to FOS too? | |
5df842b3 AM |
101 | /** |
102 | * Supply the File object to which we will write the attribute tree. The | |
103 | * position in this file is supplied by -TreeWriterFilePosition. | |
104 | * | |
105 | * @return The target File | |
106 | */ | |
a52fde77 AM |
107 | public File supplyAttributeTreeWriterFile(); |
108 | ||
5df842b3 AM |
109 | /** |
110 | * Supply the position in the file where we should write the attribute tree | |
111 | * when asked to. | |
112 | * | |
113 | * @return The file position (we will seek() to it) | |
114 | */ | |
a52fde77 AM |
115 | public long supplyAttributeTreeWriterFilePosition(); |
116 | ||
36bf82a2 AM |
117 | /** |
118 | * Delete any generated files or anything that might have been created by | |
119 | * the history backend (either temporary or save files). By calling this, we | |
120 | * return to the state as it was before ever building the history. | |
5df842b3 | 121 | * |
36bf82a2 AM |
122 | * You might not want to call automatically if, for example, you want an |
123 | * index file to persist on disk. This could be limited to actions | |
124 | * originating from the user. | |
125 | */ | |
126 | public void removeFiles(); | |
127 | ||
1a4205d9 AM |
128 | /** |
129 | * Notify the state history back-end that the trace is being closed, so it | |
130 | * should release its file descriptors, close its connections, etc. | |
131 | */ | |
132 | public void dispose(); | |
133 | ||
a52fde77 AM |
134 | /** |
135 | * @name Query methods | |
136 | */ | |
137 | ||
138 | /** | |
139 | * Complete "give me the state at a given time" method 'currentStateInfo' is | |
140 | * an "out" parameter, that is, write to it the needed information and | |
141 | * return. DO NOT 'new' currentStateInfo, it will be lost and nothing will | |
142 | * be returned! | |
5df842b3 | 143 | * |
a52fde77 AM |
144 | * @param currentStateInfo |
145 | * List of StateValues (index == quark) to fill up | |
146 | * @param t | |
147 | * Target timestamp of the query | |
5df842b3 AM |
148 | * @throws TimeRangeException |
149 | * If the timestamp is outside of the history/trace | |
a52fde77 AM |
150 | */ |
151 | public void doQuery(List<ITmfStateInterval> currentStateInfo, long t) | |
152 | throws TimeRangeException; | |
153 | ||
154 | /** | |
155 | * Some providers might want to specify a different way to obtain just a | |
156 | * single StateValue instead of updating the whole list. If the method to | |
157 | * use is the same, then feel free to just implement this as a wrapper using | |
158 | * doQuery(). | |
5df842b3 | 159 | * |
a52fde77 AM |
160 | * @param t |
161 | * The target timestamp of the query. | |
162 | * @param attributeQuark | |
163 | * The single attribute for which you want the state interval | |
164 | * @return The state interval matching this timestamp/attribute pair | |
165 | * @throws TimeRangeException | |
166 | * If the timestamp was invalid | |
167 | * @throws AttributeNotFoundException | |
168 | * If the quark was invalid | |
169 | */ | |
170 | public ITmfStateInterval doSingularQuery(long t, int attributeQuark) | |
171 | throws TimeRangeException, AttributeNotFoundException; | |
5df842b3 | 172 | |
b255ae4b AM |
173 | /** |
174 | * Simple check to make sure the requested timestamps are within the borders | |
5df842b3 AM |
175 | * of this state history. This is used internally, but could also be used by |
176 | * the request sender (to check before sending in a lot of requests for | |
b255ae4b | 177 | * example). |
5df842b3 | 178 | * |
b255ae4b AM |
179 | * @param t |
180 | * The queried timestamp | |
181 | * @return True if the timestamp is within range, false if not. | |
182 | */ | |
183 | public boolean checkValidTime(long t); | |
a52fde77 AM |
184 | |
185 | /** | |
186 | * Debug method to print the contents of the history backend. | |
5df842b3 | 187 | * |
a52fde77 AM |
188 | * @param writer |
189 | * The PrintWriter where to write the output | |
190 | */ | |
191 | public void debugPrint(PrintWriter writer); | |
192 | } |