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