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