ss: Bug 486689: Add methods for getting an optional attribute quark
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / ITmfStateSystem.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 Ericsson and others.
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.tracecompass.statesystem.core;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
19 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
20 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
21 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
22 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
23
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 * @noimplement Only the internal StateSystem class should implement this
31 * interface.
32 */
33 public interface ITmfStateSystem {
34
35 /** Root attribute quark
36 * @since 2.0*/
37 int ROOT_ATTRIBUTE = -1;
38 /** Invalid attribute quark
39 * @since 2.0*/
40 int INVALID_ATTRIBUTE = -2;
41
42 /**
43 * Get the ID of this state system.
44 *
45 * @return The state system's ID
46 */
47 String getSSID();
48
49 /**
50 * Return the start time of this history. It usually matches the start time
51 * of the original trace.
52 *
53 * @return The history's registered start time
54 */
55 long getStartTime();
56
57 /**
58 * Return the current end time of the history.
59 *
60 * @return The current end time of this state history
61 */
62 long getCurrentEndTime();
63
64 /**
65 * Check if the construction of this state system was cancelled or not. If
66 * false is returned, it can mean that the building was finished
67 * successfully, or that it is still ongoing. You can check independently
68 * with {@link #waitUntilBuilt()} if it is finished or not.
69 *
70 * @return If the construction was cancelled or not. In true is returned, no
71 * queries should be run afterwards.
72 */
73 boolean isCancelled();
74
75 /**
76 * While it's possible to query a state history that is being built,
77 * sometimes we might want to wait until the construction is finished before
78 * we start doing queries.
79 *
80 * This method blocks the calling thread until the history back-end is done
81 * building. If it's already built (ie, opening a pre-existing file) this
82 * should return immediately.
83 *
84 * You should always check with {@link #isCancelled()} if it is safe to
85 * query this state system before doing queries.
86 */
87 void waitUntilBuilt();
88
89 /**
90 * Wait until the state system construction is finished. Similar to
91 * {@link #waitUntilBuilt()}, but we also specify a timeout. If the timeout
92 * elapses before the construction is finished, the method will return.
93 *
94 * The return value determines if the return was due to the construction
95 * finishing (true), or the timeout elapsing (false).
96 *
97 * This can be useful, for example, for a component doing queries
98 * periodically to the system while it is being built.
99 *
100 * @param timeout
101 * Timeout value in milliseconds
102 * @return True if the return was due to the construction finishing, false
103 * if it was because the timeout elapsed. Same logic as
104 * {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)}
105 */
106 boolean waitUntilBuilt(long timeout);
107
108 /**
109 * Notify the state system that the trace is being closed, so it should
110 * clean up, close its files, etc.
111 */
112 void dispose();
113
114 // ------------------------------------------------------------------------
115 // Read-only quark-getting methods
116 // ------------------------------------------------------------------------
117
118 /**
119 * Return the current total amount of attributes in the system. This is also
120 * equal to the quark that will be assigned to the next attribute that's
121 * created.
122 *
123 * @return The current number of attributes in the system
124 */
125 int getNbAttributes();
126
127 /**
128 * Basic quark-retrieving method. Pass an attribute in parameter as an array
129 * of strings, the matching quark will be returned.
130 * <p>
131 * This version will NOT create any new attributes. If an invalid attribute
132 * is requested, an exception will be thrown.
133 * <p>
134 * If it is expected that the requested attribute might be absent, it is
135 * recommended to use {@link #optQuarkAbsolute(String...)} instead.
136 *
137 * @param attribute
138 * Attribute given as its full path in the Attribute Tree
139 * @return The quark of the requested attribute, if it existed.
140 * @throws AttributeNotFoundException
141 * This exception is thrown if the requested attribute simply
142 * did not exist in the system.
143 */
144 int getQuarkAbsolute(String... attribute)
145 throws AttributeNotFoundException;
146
147 /**
148 * Quark-retrieving method for an optional attribute that may or may not be
149 * present. Pass an attribute in parameter as an array of strings, if it
150 * exists, the matching quark will be returned.
151 * <p>
152 * This version will NOT create any new attributes. If an attribute that
153 * does not exist is requested, {@link #INVALID_ATTRIBUTE} will be returned.
154 *
155 * @param attribute
156 * Attribute given as its full path in the Attribute Tree
157 * @return The quark of the requested attribute, or
158 * {@link #INVALID_ATTRIBUTE} if it does not exist.
159 * @since 2.0
160 */
161 int optQuarkAbsolute(String... attribute);
162
163 /**
164 * "Relative path" quark-getting method. Instead of specifying a full path,
165 * if you know the path is relative to another attribute for which you
166 * already have the quark, use this for better performance.
167 * <p>
168 * This is useful for cases where a lot of modifications or queries will
169 * originate from the same branch of the attribute tree : the common part of
170 * the path won't have to be re-hashed for every access.
171 * <p>
172 * This version will NOT create any new attributes. If an invalid attribute
173 * is requested, an exception will be thrown.
174 * <p>
175 * If it is expected that the requested sub-attribute might be absent, it is
176 * recommended to use {@link #optQuarkRelative(int, String...)} instead.
177 *
178 * @param startingNodeQuark
179 * The quark of the attribute from which 'subPath' originates.
180 * @param subPath
181 * "Rest" of the path to get to the final attribute
182 * @return The matching quark, if it existed
183 * @throws IndexOutOfBoundsException
184 * If the starting node quark is out of range
185 * @throws AttributeNotFoundException
186 * If the sub-attribute does not exist
187 */
188 int getQuarkRelative(int startingNodeQuark, String... subPath)
189 throws AttributeNotFoundException;
190
191 /**
192 * "Relative path" quark-getting method for an optional attribute that may
193 * or may not be present. Instead of specifying a full path, if you know the
194 * path is relative to another attribute for which you already have the
195 * quark, use this for better performance.
196 * <p>
197 * This is useful for cases where a lot of modifications or queries will
198 * originate from the same branch of the attribute tree : the common part of
199 * the path won't have to be re-hashed for every access.
200 * <p>
201 * This version will NOT create any new attributes. If a sub-attribute that
202 * does not exist is requested, {@link #INVALID_ATTRIBUTE} will be returned.
203 *
204 * @param startingNodeQuark
205 * The quark of the attribute from which 'subPath' originates.
206 * @param subPath
207 * "Rest" of the path to get to the final attribute
208 * @return The quark of the requested sub-attribute, or
209 * {@link #INVALID_ATTRIBUTE} if it does not exist.
210 * @throws IndexOutOfBoundsException
211 * If the starting node quark is out of range
212 * @since 2.0
213 */
214 int optQuarkRelative(int startingNodeQuark, String... subPath);
215
216 /**
217 * Return the sub-attributes of the target attribute, as a List of quarks.
218 *
219 * @param quark
220 * The attribute of which you want to sub-attributes. You can use
221 * {@link #ROOT_ATTRIBUTE} here to specify the root node.
222 * @param recursive
223 * True if you want all recursive sub-attributes, false if you
224 * only want the first level.
225 * @return A List of integers, matching the quarks of the sub-attributes.
226 * @throws AttributeNotFoundException
227 * If the quark was not existing or invalid.
228 */
229 @NonNull List<@NonNull Integer> getSubAttributes(int quark, boolean recursive)
230 throws AttributeNotFoundException;
231
232 /**
233 * Return the sub-attributes of the target attribute, as a List of quarks,
234 * similarly to {@link #getSubAttributes(int, boolean)}, but with an added
235 * regex pattern to filter on the return attributes.
236 *
237 * @param quark
238 * The attribute of which you want to sub-attributes. You can use
239 * {@link #ROOT_ATTRIBUTE} here to specify the root node.
240 * @param recursive
241 * True if you want all recursive sub-attributes, false if you
242 * only want the first level. Note that the returned value will
243 * be flattened.
244 * @param pattern
245 * The regular expression to match the attribute base name.
246 * @return A List of integers, matching the quarks of the sub-attributes
247 * that match the regex. An empty list is returned if there is no
248 * matching attribute.
249 * @throws AttributeNotFoundException
250 * If the 'quark' was not existing or invalid.
251 */
252 @NonNull List<@NonNull Integer> getSubAttributes(int quark, boolean recursive, String pattern)
253 throws AttributeNotFoundException;
254
255 /**
256 * Batch quark-retrieving method. This method allows you to specify a path
257 * pattern which includes a wildcard "*" somewhere. It will check all the
258 * existing attributes in the attribute tree and return those who match the
259 * pattern.
260 *
261 * For example, passing ("Threads", "*", "Exec_mode") will return the list
262 * of quarks for attributes "Threads/1000/Exec_mode",
263 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
264 * time in the attribute tree.
265 *
266 * If no wildcard is specified, the behavior is the same as
267 * getQuarkAbsolute() (except it will return a List with one entry). This
268 * method will never create new attributes.
269 *
270 * Only one wildcard "*" is supported at this time.
271 *
272 * @param pattern
273 * The array of strings representing the pattern to look for. It
274 * should ideally contain one entry that is only a "*".
275 * @return A List of attribute quarks, representing attributes that matched
276 * the pattern. If no attribute matched, the list will be empty (but
277 * not null).
278 */
279 @NonNull List<@NonNull Integer> getQuarks(String... pattern);
280
281 /**
282 * Return the name assigned to this quark. This returns only the "basename",
283 * not the complete path to this attribute.
284 *
285 * @param attributeQuark
286 * The quark for which we want the name
287 * @return The name of the quark
288 * @throws IndexOutOfBoundsException
289 * If the attribute quark is out of range
290 */
291 @NonNull String getAttributeName(int attributeQuark);
292
293 /**
294 * This returns the slash-separated path of an attribute by providing its
295 * quark
296 *
297 * @param attributeQuark
298 * The quark of the attribute we want
299 * @return One single string separated with '/', like a filesystem path
300 * @throws IndexOutOfBoundsException
301 * If the attribute quark is out of range
302 */
303 @NonNull String getFullAttributePath(int attributeQuark);
304
305 /**
306 * Return the full attribute path, as an array of strings representing each
307 * element.
308 *
309 * @param attributeQuark
310 * The quark of the attribute we want.
311 * @return The array of path elements
312 * @throws IndexOutOfBoundsException
313 * If the attribute quark is out of range
314 * @since 1.0
315 */
316 String @NonNull [] getFullAttributePathArray(int attributeQuark);
317
318 /**
319 * Returns the parent quark of the attribute.
320 *
321 * @param attributeQuark
322 * The quark of the attribute
323 * @return Quark of the parent attribute or {@link #ROOT_ATTRIBUTE} if root
324 * quark or no parent.
325 * @throws IndexOutOfBoundsException
326 * If the attribute quark is out of range
327 */
328 int getParentAttributeQuark(int attributeQuark);
329
330 // ------------------------------------------------------------------------
331 // Query methods
332 // ------------------------------------------------------------------------
333
334 /**
335 * Returns the current state value we have (in the Transient State) for the
336 * given attribute.
337 *
338 * This is useful even for a StateHistorySystem, as we are guaranteed it
339 * will only do a memory access and not go look on disk (and we don't even
340 * have to provide a timestamp!)
341 *
342 * @param attributeQuark
343 * For which attribute we want the current state
344 * @return The State value that's "current" for this attribute
345 * @throws AttributeNotFoundException
346 * If the requested attribute is invalid
347 */
348 ITmfStateValue queryOngoingState(int attributeQuark)
349 throws AttributeNotFoundException;
350
351 /**
352 * Get the start time of the current ongoing state, for the specified
353 * attribute.
354 *
355 * @param attribute
356 * Quark of the attribute
357 * @return The current start time of the ongoing state
358 * @throws AttributeNotFoundException
359 * If the attribute is invalid
360 */
361 long getOngoingStartTime(int attribute)
362 throws AttributeNotFoundException;
363
364 /**
365 * Load the complete state information at time 't' into the returned List.
366 * You can then get the intervals for single attributes by using
367 * List.get(n), where 'n' is the quark of the attribute.
368 *
369 * On average if you need around 10 or more queries for the same timestamps,
370 * use this method. If you need less than 10 (for example, running many
371 * queries for the same attributes but at different timestamps), you might
372 * be better using the querySingleState() methods instead.
373 *
374 * @param t
375 * We will recreate the state information to what it was at time
376 * t.
377 * @return The List of intervals, where the offset = the quark
378 * @throws TimeRangeException
379 * If the 't' parameter is outside of the range of the state
380 * history.
381 * @throws StateSystemDisposedException
382 * If the query is sent after the state system has been disposed
383 */
384 @NonNull List<@NonNull ITmfStateInterval> queryFullState(long t)
385 throws StateSystemDisposedException;
386
387 /**
388 * Singular query method. This one does not update the whole stateInfo
389 * vector, like queryFullState() does. It only searches for one specific
390 * entry in the state history.
391 *
392 * It should be used when you only want very few entries, instead of the
393 * whole state (or many entries, but all at different timestamps). If you do
394 * request many entries all at the same time, you should use the
395 * conventional queryFullState() + List.get() method.
396 *
397 * @param t
398 * The timestamp at which we want the state
399 * @param attributeQuark
400 * Which attribute we want to get the state of
401 * @return The StateInterval representing the state
402 * @throws TimeRangeException
403 * If 't' is invalid
404 * @throws AttributeNotFoundException
405 * If the requested quark does not exist in the model
406 * @throws StateSystemDisposedException
407 * If the query is sent after the state system has been disposed
408 */
409 @NonNull ITmfStateInterval querySingleState(long t, int attributeQuark)
410 throws AttributeNotFoundException, StateSystemDisposedException;
411 }
This page took 0.09717 seconds and 5 git commands to generate.