tmf: Add a ITmfStateSystem.waitUntilBuilt() method with timeout
[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 * Wait until the state system construction is finished. Similar to
80 * {@link #waitUntilBuilt()}, but we also specify a timeout. If the timeout
81 * elapses before the construction is finished, the method will return.
82 *
83 * The return value determines if the return was due to the construction
84 * finishing (true), or the timeout elapsing (false).
85 *
86 * This can be useful, for example, for a component doing queries
87 * periodically to the system while it is being built.
88 *
89 * @param timeout
90 * Timeout value in milliseconds
91 * @return True if the return was due to the construction finishing, false
92 * if it was because the timeout elapsed. Same logic as
93 * {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)}
94 * @since 3.0
95 */
96 boolean waitUntilBuilt(long timeout);
97
98 /**
99 * Notify the state system that the trace is being closed, so it should
100 * clean up, close its files, etc.
101 */
102 void dispose();
103
104 /**
105 * Return the current total amount of attributes in the system. This is also
106 * equal to the quark that will be assigned to the next attribute that's
107 * created.
108 *
109 * @return The current number of attributes in the system
110 */
111 int getNbAttributes();
112
113 /**
114 * @name Read-only quark-getting methods
115 */
116
117 /**
118 * Basic quark-retrieving method. Pass an attribute in parameter as an array
119 * of strings, the matching quark will be returned.
120 *
121 * This version will NOT create any new attributes. If an invalid attribute
122 * is requested, an exception will be thrown.
123 *
124 * @param attribute
125 * Attribute given as its full path in the Attribute Tree
126 * @return The quark of the requested attribute, if it existed.
127 * @throws AttributeNotFoundException
128 * This exception is thrown if the requested attribute simply
129 * did not exist in the system.
130 */
131 int getQuarkAbsolute(String... attribute)
132 throws AttributeNotFoundException;
133
134 /**
135 * "Relative path" quark-getting method. Instead of specifying a full path,
136 * if you know the path is relative to another attribute for which you
137 * already have the quark, use this for better performance.
138 *
139 * This is useful for cases where a lot of modifications or queries will
140 * originate from the same branch of the attribute tree : the common part of
141 * the path won't have to be re-hashed for every access.
142 *
143 * This version will NOT create any new attributes. If an invalid attribute
144 * is requested, an exception will be thrown.
145 *
146 * @param startingNodeQuark
147 * The quark of the attribute from which 'subPath' originates.
148 * @param subPath
149 * "Rest" of the path to get to the final attribute
150 * @return The matching quark, if it existed
151 * @throws AttributeNotFoundException
152 * If the quark is invalid
153 */
154 int getQuarkRelative(int startingNodeQuark, String... subPath)
155 throws AttributeNotFoundException;
156
157 /**
158 * Return the sub-attributes of the target attribute, as a List of quarks.
159 *
160 * @param quark
161 * The attribute of which you want to sub-attributes. You can use
162 * "-1" here to specify the root node.
163 * @param recursive
164 * True if you want all recursive sub-attributes, false if you
165 * only want the first level.
166 * @return A List of integers, matching the quarks of the sub-attributes.
167 * @throws AttributeNotFoundException
168 * If the quark was not existing or invalid.
169 */
170 List<Integer> getSubAttributes(int quark, boolean recursive)
171 throws AttributeNotFoundException;
172
173 /**
174 * Batch quark-retrieving method. This method allows you to specify a path
175 * pattern which includes a wildcard "*" somewhere. It will check all the
176 * existing attributes in the attribute tree and return those who match the
177 * pattern.
178 *
179 * For example, passing ("Threads", "*", "Exec_mode") will return the list
180 * of quarks for attributes "Threads/1000/Exec_mode",
181 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
182 * time in the attribute tree.
183 *
184 * If no wildcard is specified, the behavior is the same as
185 * getQuarkAbsolute() (except it will return a List with one entry). This
186 * method will never create new attributes.
187 *
188 * Only one wildcard "*" is supported at this time.
189 *
190 * @param pattern
191 * The array of strings representing the pattern to look for. It
192 * should ideally contain one entry that is only a "*".
193 * @return A List of attribute quarks, representing attributes that matched
194 * the pattern. If no attribute matched, the list will be empty (but
195 * not null).
196 */
197 List<Integer> getQuarks(String... pattern);
198
199 /**
200 * Return the name assigned to this quark. This returns only the "basename",
201 * not the complete path to this attribute.
202 *
203 * @param attributeQuark
204 * The quark for which we want the name
205 * @return The name of the quark
206 */
207 String getAttributeName(int attributeQuark);
208
209 /**
210 * This returns the slash-separated path of an attribute by providing its
211 * quark
212 *
213 * @param attributeQuark
214 * The quark of the attribute we want
215 * @return One single string separated with '/', like a filesystem path
216 */
217 String getFullAttributePath(int attributeQuark);
218
219 /**
220 * @name Query methods
221 */
222
223 /**
224 * Returns the current state value we have (in the Transient State) for the
225 * given attribute.
226 *
227 * This is useful even for a StateHistorySystem, as we are guaranteed it
228 * will only do a memory access and not go look on disk (and we don't even
229 * have to provide a timestamp!)
230 *
231 * @param attributeQuark
232 * For which attribute we want the current state
233 * @return The State value that's "current" for this attribute
234 * @throws AttributeNotFoundException
235 * If the requested attribute is invalid
236 */
237 ITmfStateValue queryOngoingState(int attributeQuark)
238 throws AttributeNotFoundException;
239
240 /**
241 * Get the start time of the current ongoing state, for the specified
242 * attribute.
243 *
244 * @param attribute
245 * Quark of the attribute
246 * @return The current start time of the ongoing state
247 * @throws AttributeNotFoundException
248 * If the attribute is invalid
249 */
250 long getOngoingStartTime(int attribute)
251 throws AttributeNotFoundException;
252
253 /**
254 * Load the complete state information at time 't' into the returned List.
255 * You can then get the intervals for single attributes by using
256 * List.get(n), where 'n' is the quark of the attribute.
257 *
258 * On average if you need around 10 or more queries for the same timestamps,
259 * use this method. If you need less than 10 (for example, running many
260 * queries for the same attributes but at different timestamps), you might
261 * be better using the querySingleState() methods instead.
262 *
263 * @param t
264 * We will recreate the state information to what it was at time
265 * t.
266 * @return The List of intervals, where the offset = the quark
267 * @throws TimeRangeException
268 * If the 't' parameter is outside of the range of the state
269 * history.
270 * @throws StateSystemDisposedException
271 * If the query is sent after the state system has been disposed
272 */
273 List<ITmfStateInterval> queryFullState(long t)
274 throws TimeRangeException, StateSystemDisposedException;
275
276 /**
277 * Singular query method. This one does not update the whole stateInfo
278 * vector, like queryFullState() does. It only searches for one specific
279 * entry in the state history.
280 *
281 * It should be used when you only want very few entries, instead of the
282 * whole state (or many entries, but all at different timestamps). If you do
283 * request many entries all at the same time, you should use the
284 * conventional queryFullState() + List.get() method.
285 *
286 * @param t
287 * The timestamp at which we want the state
288 * @param attributeQuark
289 * Which attribute we want to get the state of
290 * @return The StateInterval representing the state
291 * @throws TimeRangeException
292 * If 't' is invalid
293 * @throws AttributeNotFoundException
294 * If the requested quark does not exist in the model
295 * @throws StateSystemDisposedException
296 * If the query is sent after the state system has been disposed
297 */
298 ITmfStateInterval querySingleState(long t, int attributeQuark)
299 throws AttributeNotFoundException, TimeRangeException,
300 StateSystemDisposedException;
301
302 /**
303 * Convenience method to query attribute stacks (created with
304 * pushAttribute()/popAttribute()). This will return the interval that is
305 * currently at the top of the stack, or 'null' if that stack is currently
306 * empty. It works similarly to querySingleState().
307 *
308 * To retrieve the other values in a stack, you can query the sub-attributes
309 * manually.
310 *
311 * @param t
312 * The timestamp of the query
313 * @param stackAttributeQuark
314 * The top-level stack-attribute (that was the target of
315 * pushAttribute() at creation time)
316 * @return The interval that was at the top of the stack, or 'null' if the
317 * stack was empty.
318 * @throws StateValueTypeException
319 * If the target attribute is not a valid stack attribute (if it
320 * has a string value for example)
321 * @throws AttributeNotFoundException
322 * If the attribute was simply not found
323 * @throws TimeRangeException
324 * If the given timestamp is invalid
325 * @throws StateSystemDisposedException
326 * If the query is sent after the state system has been disposed
327 * @since 2.0
328 */
329 ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
330 throws StateValueTypeException, AttributeNotFoundException,
331 TimeRangeException, StateSystemDisposedException;
332
333 /**
334 * Return a list of state intervals, containing the "history" of a given
335 * attribute between timestamps t1 and t2. The list will be ordered by
336 * ascending time.
337 *
338 * Note that contrary to queryFullState(), the returned list here is in the
339 * "direction" of time (and not in the direction of attributes, as is the
340 * case with queryFullState()).
341 *
342 * @param attributeQuark
343 * Which attribute this query is interested in
344 * @param t1
345 * Start time of the range query
346 * @param t2
347 * Target end time of the query. If t2 is greater than the end of
348 * the trace, we will return what we have up to the end of the
349 * history.
350 * @return The List of state intervals that happened between t1 and t2
351 * @throws TimeRangeException
352 * If t1 is invalid, or if t2 <= t1
353 * @throws AttributeNotFoundException
354 * If the requested quark does not exist in the model.
355 * @throws StateSystemDisposedException
356 * If the query is sent after the state system has been disposed
357 */
358 List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
359 long t1, long t2) throws TimeRangeException,
360 AttributeNotFoundException, StateSystemDisposedException;
361
362 /**
363 * Return the state history of a given attribute, but with at most one
364 * update per "resolution". This can be useful for populating views (where
365 * it's useless to have more than one query per pixel, for example). A
366 * progress monitor can be used to cancel the query before completion.
367 *
368 * @param attributeQuark
369 * Which attribute this query is interested in
370 * @param t1
371 * Start time of the range query
372 * @param t2
373 * Target end time of the query. If t2 is greater than the end of
374 * the trace, we will return what we have up to the end of the
375 * history.
376 * @param resolution
377 * The "step" of this query
378 * @param monitor
379 * A progress monitor. If the monitor is canceled during a query,
380 * we will return what has been found up to that point. You can
381 * use "null" if you do not want to use one.
382 * @return The List of states that happened between t1 and t2
383 * @throws TimeRangeException
384 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
385 * greater than zero.
386 * @throws AttributeNotFoundException
387 * If the attribute doesn't exist
388 * @throws StateSystemDisposedException
389 * If the query is sent after the state system has been disposed
390 * @since 2.0
391 */
392 List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
393 long t1, long t2, long resolution, IProgressMonitor monitor)
394 throws TimeRangeException, AttributeNotFoundException,
395 StateSystemDisposedException;
396 }
This page took 0.038442 seconds and 5 git commands to generate.