tmf: Split ITmfStateSystem.waitUntilBuilt() in separate methods
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / ITmfStateSystem.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Initial API
11 ******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.statesystem;
14
15 import java.util.List;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
19 import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
20 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
21 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
22 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
23 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
24
25 /**
26 * This is the read-only interface to the generic state system. It contains all
27 * the read-only quark-getting methods, as well as the history-querying ones.
28 *
29 * @author Alexandre Montplaisir
30 * @version 2.0
31 * @since 2.0
32 */
33 public interface ITmfStateSystem {
34
35 /**
36 * Return the start time of this history. It usually matches the start time
37 * of the original trace.
38 *
39 * @return The history's registered start time
40 */
41 long getStartTime();
42
43 /**
44 * Return the current end time of the history.
45 *
46 * @return The current end time of this state history
47 */
48 long getCurrentEndTime();
49
50 /**
51 * Check if the construction of this state system was cancelled or not. If
52 * false is returned, it can mean that the building was finished
53 * successfully, or that it is still ongoing. You can check independently
54 * with {@link #waitUntilBuilt()} if it is finished or not.
55 *
56 * @return If the construction was cancelled or not. In true is returned, no
57 * queries should be run afterwards.
58 * @since 3.0
59 */
60 boolean isCancelled();
61
62 /**
63 * While it's possible to query a state history that is being built,
64 * sometimes we might want to wait until the construction is finished before
65 * we start doing queries.
66 *
67 * This method blocks the calling thread until the history back-end is done
68 * building. If it's already built (ie, opening a pre-existing file) this
69 * should return immediately.
70 *
71 * You should always check with {@link #isCancelled()} if it is safe to
72 * query this state system before doing queries.
73 *
74 * @since 3.0
75 */
76 void waitUntilBuilt();
77
78 /**
79 * Notify the state system that the trace is being closed, so it should
80 * clean up, close its files, etc.
81 */
82 void dispose();
83
84 /**
85 * Return the current total amount of attributes in the system. This is also
86 * equal to the quark that will be assigned to the next attribute that's
87 * created.
88 *
89 * @return The current number of attributes in the system
90 */
91 int getNbAttributes();
92
93 /**
94 * @name Read-only quark-getting methods
95 */
96
97 /**
98 * Basic quark-retrieving method. Pass an attribute in parameter as an array
99 * of strings, the matching quark will be returned.
100 *
101 * This version will NOT create any new attributes. If an invalid attribute
102 * is requested, an exception will be thrown.
103 *
104 * @param attribute
105 * Attribute given as its full path in the Attribute Tree
106 * @return The quark of the requested attribute, if it existed.
107 * @throws AttributeNotFoundException
108 * This exception is thrown if the requested attribute simply
109 * did not exist in the system.
110 */
111 int getQuarkAbsolute(String... attribute)
112 throws AttributeNotFoundException;
113
114 /**
115 * "Relative path" quark-getting method. Instead of specifying a full path,
116 * if you know the path is relative to another attribute for which you
117 * already have the quark, use this for better performance.
118 *
119 * This is useful for cases where a lot of modifications or queries will
120 * originate from the same branch of the attribute tree : the common part of
121 * the path won't have to be re-hashed for every access.
122 *
123 * This version will NOT create any new attributes. If an invalid attribute
124 * is requested, an exception will be thrown.
125 *
126 * @param startingNodeQuark
127 * The quark of the attribute from which 'subPath' originates.
128 * @param subPath
129 * "Rest" of the path to get to the final attribute
130 * @return The matching quark, if it existed
131 * @throws AttributeNotFoundException
132 * If the quark is invalid
133 */
134 int getQuarkRelative(int startingNodeQuark, String... subPath)
135 throws AttributeNotFoundException;
136
137 /**
138 * Return the sub-attributes of the target attribute, as a List of quarks.
139 *
140 * @param quark
141 * The attribute of which you want to sub-attributes. You can use
142 * "-1" here to specify the root node.
143 * @param recursive
144 * True if you want all recursive sub-attributes, false if you
145 * only want the first level.
146 * @return A List of integers, matching the quarks of the sub-attributes.
147 * @throws AttributeNotFoundException
148 * If the quark was not existing or invalid.
149 */
150 List<Integer> getSubAttributes(int quark, boolean recursive)
151 throws AttributeNotFoundException;
152
153 /**
154 * Batch quark-retrieving method. This method allows you to specify a path
155 * pattern which includes a wildcard "*" somewhere. It will check all the
156 * existing attributes in the attribute tree and return those who match the
157 * pattern.
158 *
159 * For example, passing ("Threads", "*", "Exec_mode") will return the list
160 * of quarks for attributes "Threads/1000/Exec_mode",
161 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
162 * time in the attribute tree.
163 *
164 * If no wildcard is specified, the behavior is the same as
165 * getQuarkAbsolute() (except it will return a List with one entry). This
166 * method will never create new attributes.
167 *
168 * Only one wildcard "*" is supported at this time.
169 *
170 * @param pattern
171 * The array of strings representing the pattern to look for. It
172 * should ideally contain one entry that is only a "*".
173 * @return A List of attribute quarks, representing attributes that matched
174 * the pattern. If no attribute matched, the list will be empty (but
175 * not null).
176 */
177 List<Integer> getQuarks(String... pattern);
178
179 /**
180 * Return the name assigned to this quark. This returns only the "basename",
181 * not the complete path to this attribute.
182 *
183 * @param attributeQuark
184 * The quark for which we want the name
185 * @return The name of the quark
186 */
187 String getAttributeName(int attributeQuark);
188
189 /**
190 * This returns the slash-separated path of an attribute by providing its
191 * quark
192 *
193 * @param attributeQuark
194 * The quark of the attribute we want
195 * @return One single string separated with '/', like a filesystem path
196 */
197 String getFullAttributePath(int attributeQuark);
198
199 /**
200 * @name Query methods
201 */
202
203 /**
204 * Returns the current state value we have (in the Transient State) for the
205 * given attribute.
206 *
207 * This is useful even for a StateHistorySystem, as we are guaranteed it
208 * will only do a memory access and not go look on disk (and we don't even
209 * have to provide a timestamp!)
210 *
211 * @param attributeQuark
212 * For which attribute we want the current state
213 * @return The State value that's "current" for this attribute
214 * @throws AttributeNotFoundException
215 * If the requested attribute is invalid
216 */
217 ITmfStateValue queryOngoingState(int attributeQuark)
218 throws AttributeNotFoundException;
219
220 /**
221 * Get the start time of the current ongoing state, for the specified
222 * attribute.
223 *
224 * @param attribute
225 * Quark of the attribute
226 * @return The current start time of the ongoing state
227 * @throws AttributeNotFoundException
228 * If the attribute is invalid
229 */
230 long getOngoingStartTime(int attribute)
231 throws AttributeNotFoundException;
232
233 /**
234 * Load the complete state information at time 't' into the returned List.
235 * You can then get the intervals for single attributes by using
236 * List.get(n), where 'n' is the quark of the attribute.
237 *
238 * On average if you need around 10 or more queries for the same timestamps,
239 * use this method. If you need less than 10 (for example, running many
240 * queries for the same attributes but at different timestamps), you might
241 * be better using the querySingleState() methods instead.
242 *
243 * @param t
244 * We will recreate the state information to what it was at time
245 * t.
246 * @return The List of intervals, where the offset = the quark
247 * @throws TimeRangeException
248 * If the 't' parameter is outside of the range of the state
249 * history.
250 * @throws StateSystemDisposedException
251 * If the query is sent after the state system has been disposed
252 */
253 List<ITmfStateInterval> queryFullState(long t)
254 throws TimeRangeException, StateSystemDisposedException;
255
256 /**
257 * Singular query method. This one does not update the whole stateInfo
258 * vector, like queryFullState() does. It only searches for one specific
259 * entry in the state history.
260 *
261 * It should be used when you only want very few entries, instead of the
262 * whole state (or many entries, but all at different timestamps). If you do
263 * request many entries all at the same time, you should use the
264 * conventional queryFullState() + List.get() method.
265 *
266 * @param t
267 * The timestamp at which we want the state
268 * @param attributeQuark
269 * Which attribute we want to get the state of
270 * @return The StateInterval representing the state
271 * @throws TimeRangeException
272 * If 't' is invalid
273 * @throws AttributeNotFoundException
274 * If the requested quark does not exist in the model
275 * @throws StateSystemDisposedException
276 * If the query is sent after the state system has been disposed
277 */
278 ITmfStateInterval querySingleState(long t, int attributeQuark)
279 throws AttributeNotFoundException, TimeRangeException,
280 StateSystemDisposedException;
281
282 /**
283 * Convenience method to query attribute stacks (created with
284 * pushAttribute()/popAttribute()). This will return the interval that is
285 * currently at the top of the stack, or 'null' if that stack is currently
286 * empty. It works similarly to querySingleState().
287 *
288 * To retrieve the other values in a stack, you can query the sub-attributes
289 * manually.
290 *
291 * @param t
292 * The timestamp of the query
293 * @param stackAttributeQuark
294 * The top-level stack-attribute (that was the target of
295 * pushAttribute() at creation time)
296 * @return The interval that was at the top of the stack, or 'null' if the
297 * stack was empty.
298 * @throws StateValueTypeException
299 * If the target attribute is not a valid stack attribute (if it
300 * has a string value for example)
301 * @throws AttributeNotFoundException
302 * If the attribute was simply not found
303 * @throws TimeRangeException
304 * If the given timestamp is invalid
305 * @throws StateSystemDisposedException
306 * If the query is sent after the state system has been disposed
307 * @since 2.0
308 */
309 ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
310 throws StateValueTypeException, AttributeNotFoundException,
311 TimeRangeException, StateSystemDisposedException;
312
313 /**
314 * Return a list of state intervals, containing the "history" of a given
315 * attribute between timestamps t1 and t2. The list will be ordered by
316 * ascending time.
317 *
318 * Note that contrary to queryFullState(), the returned list here is in the
319 * "direction" of time (and not in the direction of attributes, as is the
320 * case with queryFullState()).
321 *
322 * @param attributeQuark
323 * Which attribute this query is interested in
324 * @param t1
325 * Start time of the range query
326 * @param t2
327 * Target end time of the query. If t2 is greater than the end of
328 * the trace, we will return what we have up to the end of the
329 * history.
330 * @return The List of state intervals that happened between t1 and t2
331 * @throws TimeRangeException
332 * If t1 is invalid, or if t2 <= t1
333 * @throws AttributeNotFoundException
334 * If the requested quark does not exist in the model.
335 * @throws StateSystemDisposedException
336 * If the query is sent after the state system has been disposed
337 */
338 List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
339 long t1, long t2) throws TimeRangeException,
340 AttributeNotFoundException, StateSystemDisposedException;
341
342 /**
343 * Return the state history of a given attribute, but with at most one
344 * update per "resolution". This can be useful for populating views (where
345 * it's useless to have more than one query per pixel, for example). A
346 * progress monitor can be used to cancel the query before completion.
347 *
348 * @param attributeQuark
349 * Which attribute this query is interested in
350 * @param t1
351 * Start time of the range query
352 * @param t2
353 * Target end time of the query. If t2 is greater than the end of
354 * the trace, we will return what we have up to the end of the
355 * history.
356 * @param resolution
357 * The "step" of this query
358 * @param monitor
359 * A progress monitor. If the monitor is canceled during a query,
360 * we will return what has been found up to that point. You can
361 * use "null" if you do not want to use one.
362 * @return The List of states that happened between t1 and t2
363 * @throws TimeRangeException
364 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
365 * greater than zero.
366 * @throws AttributeNotFoundException
367 * If the attribute doesn't exist
368 * @throws StateSystemDisposedException
369 * If the query is sent after the state system has been disposed
370 * @since 2.0
371 */
372 List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
373 long t1, long t2, long resolution, IProgressMonitor monitor)
374 throws TimeRangeException, AttributeNotFoundException,
375 StateSystemDisposedException;
376 }
This page took 0.041204 seconds and 5 git commands to generate.