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