Commit | Line | Data |
---|---|---|
3a081e85 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2010, 2016 Ericsson, École Polytechnique de Montréal, 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 | ||
10 | package org.eclipse.tracecompass.internal.statesystem.core.backend.historytree; | |
11 | ||
12 | import java.io.File; | |
13 | import java.io.FileInputStream; | |
f4baf640 | 14 | import java.io.IOException; |
3a081e85 | 15 | import java.nio.channels.ClosedChannelException; |
588f11a1 | 16 | import java.util.Collection; |
3a081e85 GB |
17 | |
18 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
19 | ||
20 | /** | |
21 | * Meta-container for the History Tree. This structure contains all the | |
22 | * high-level data relevant to the tree. | |
23 | * | |
24 | * @author Alexandre Montplaisir | |
f4baf640 | 25 | * @author Geneviève Bastien |
3a081e85 GB |
26 | */ |
27 | public interface IHistoryTree { | |
28 | ||
f4baf640 GB |
29 | /** |
30 | * Interface for history to create the various HTNodes | |
31 | */ | |
32 | interface IHTNodeFactory { | |
33 | ||
34 | /** | |
35 | * Creates a new core node for the specific history tree | |
36 | * | |
37 | * @param config | |
38 | * Configuration of the History Tree | |
39 | * @param seqNumber | |
40 | * The (unique) sequence number assigned to this particular | |
41 | * node | |
42 | * @param parentSeqNumber | |
43 | * The sequence number of this node's parent node | |
44 | * @param start | |
45 | * The earliest timestamp stored in this node | |
46 | * @return The new core node | |
47 | * @throws IOException | |
48 | * any exception occurring while trying to read/create the | |
49 | * node | |
50 | */ | |
51 | HTNode createCoreNode(HTConfig config, int seqNumber, int parentSeqNumber, long start) throws IOException; | |
52 | ||
53 | /** | |
54 | * Creates a new core node for the specific history tree | |
55 | * | |
56 | * @param config | |
57 | * Configuration of the History Tree | |
58 | * @param seqNumber | |
59 | * The (unique) sequence number assigned to this particular | |
60 | * node | |
61 | * @param parentSeqNumber | |
62 | * The sequence number of this node's parent node | |
63 | * @param start | |
64 | * The earliest timestamp stored in this node | |
65 | * @return The new core node | |
66 | * @throws IOException | |
67 | * any exception occurring while trying to read/create the | |
68 | * node | |
69 | */ | |
70 | HTNode createLeafNode(HTConfig config, int seqNumber, int parentSeqNumber, long start) throws IOException; | |
71 | } | |
72 | ||
3a081e85 GB |
73 | /** |
74 | * Size of the "tree header" in the tree-file The nodes will use this offset | |
75 | * to know where they should be in the file. This should always be a | |
76 | * multiple of 4K. | |
77 | */ | |
78 | int TREE_HEADER_SIZE = 4096; | |
79 | ||
80 | /** | |
81 | * "Save" the tree to disk. This method will cause the treeIO object to | |
82 | * commit all nodes to disk and then return the RandomAccessFile descriptor | |
83 | * so the Tree object can save its configuration into the header of the | |
84 | * file. | |
85 | * | |
86 | * @param requestedEndTime | |
87 | * The greatest timestamp present in the history tree | |
88 | */ | |
89 | void closeTree(long requestedEndTime); | |
90 | ||
91 | // ------------------------------------------------------------------------ | |
92 | // Accessors | |
93 | // ------------------------------------------------------------------------ | |
94 | ||
95 | /** | |
96 | * Get the start time of this tree. | |
97 | * | |
98 | * @return The start time | |
99 | */ | |
100 | long getTreeStart(); | |
101 | ||
102 | /** | |
103 | * Get the current end time of this tree. | |
104 | * | |
105 | * @return The end time | |
106 | */ | |
107 | long getTreeEnd(); | |
108 | ||
109 | /** | |
110 | * Get the number of nodes in this tree. | |
111 | * | |
112 | * @return The number of nodes | |
113 | */ | |
114 | int getNodeCount(); | |
115 | ||
116 | /** | |
117 | * Get the current root node of this tree | |
118 | * | |
119 | * @return The root node | |
120 | */ | |
121 | HTNode getRootNode(); | |
122 | ||
123 | // ------------------------------------------------------------------------ | |
124 | // HT_IO interface | |
125 | // ------------------------------------------------------------------------ | |
126 | ||
127 | /** | |
128 | * Return the FileInputStream reader with which we will read an attribute | |
129 | * tree (it will be sought to the correct position). | |
130 | * | |
131 | * @return The FileInputStream indicating the file and position from which | |
132 | * the attribute tree can be read. | |
133 | */ | |
134 | FileInputStream supplyATReader(); | |
135 | ||
136 | /** | |
137 | * Return the file to which we will write the attribute tree. | |
138 | * | |
139 | * @return The file to which we will write the attribute tree | |
140 | */ | |
141 | File supplyATWriterFile(); | |
142 | ||
143 | /** | |
144 | * Return the position in the file (given by {@link #supplyATWriterFile}) | |
145 | * where to start writing the attribute tree. | |
146 | * | |
147 | * @return The position in the file where to start writing | |
148 | */ | |
149 | long supplyATWriterFilePos(); | |
150 | ||
151 | /** | |
152 | * Read a node from the tree. | |
153 | * | |
154 | * @param seqNumber | |
155 | * The sequence number of the node to read | |
156 | * @return The node | |
157 | * @throws ClosedChannelException | |
158 | * If the tree IO is unavailable | |
159 | */ | |
160 | HTNode readNode(int seqNumber) throws ClosedChannelException; | |
161 | ||
162 | /** | |
163 | * Write a node object to the history file. | |
164 | * | |
165 | * @param node | |
166 | * The node to write to disk | |
167 | */ | |
168 | void writeNode(HTNode node); | |
169 | ||
170 | /** | |
171 | * Close the history file. | |
172 | */ | |
173 | void closeFile(); | |
174 | ||
175 | /** | |
176 | * Delete the history file. | |
177 | */ | |
178 | void deleteFile(); | |
179 | ||
180 | // ------------------------------------------------------------------------ | |
181 | // Operations | |
182 | // ------------------------------------------------------------------------ | |
183 | ||
184 | /** | |
185 | * Insert an interval in the tree. | |
186 | * | |
187 | * @param interval | |
188 | * The interval to be inserted | |
189 | * @throws TimeRangeException | |
190 | * If the start of end time of the interval are invalid | |
191 | */ | |
192 | void insertInterval(HTInterval interval) throws TimeRangeException; | |
193 | ||
194 | /** | |
588f11a1 | 195 | * Inner method to select the next children of the current node intersecting |
3a081e85 GB |
196 | * the given timestamp. Useful for moving down the tree following one |
197 | * branch. | |
198 | * | |
199 | * @param currentNode | |
200 | * The node on which the request is made | |
201 | * @param t | |
202 | * The timestamp to choose which child is the next one | |
588f11a1 | 203 | * @return The child nodes intersecting t |
3a081e85 GB |
204 | * @throws ClosedChannelException |
205 | * If the file channel was closed while we were reading the tree | |
206 | */ | |
f4baf640 | 207 | Collection<HTNode> selectNextChildren(ParentNode currentNode, long t) throws ClosedChannelException; |
3a081e85 GB |
208 | |
209 | /** | |
210 | * Get the current size of the history file. | |
211 | * | |
212 | * @return The history file size | |
213 | */ | |
214 | long getFileSize(); | |
215 | ||
3a081e85 | 216 | } |