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; | |
3a081e85 GB |
14 | import java.nio.channels.ClosedChannelException; |
15 | ||
16 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
17 | ||
18 | /** | |
19 | * Meta-container for the History Tree. This structure contains all the | |
20 | * high-level data relevant to the tree. | |
21 | * | |
22 | * @author Alexandre Montplaisir | |
23 | */ | |
24 | public interface IHistoryTree { | |
25 | ||
26 | /** | |
27 | * Size of the "tree header" in the tree-file The nodes will use this offset | |
28 | * to know where they should be in the file. This should always be a | |
29 | * multiple of 4K. | |
30 | */ | |
31 | int TREE_HEADER_SIZE = 4096; | |
32 | ||
33 | /** | |
34 | * "Save" the tree to disk. This method will cause the treeIO object to | |
35 | * commit all nodes to disk and then return the RandomAccessFile descriptor | |
36 | * so the Tree object can save its configuration into the header of the | |
37 | * file. | |
38 | * | |
39 | * @param requestedEndTime | |
40 | * The greatest timestamp present in the history tree | |
41 | */ | |
42 | void closeTree(long requestedEndTime); | |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Accessors | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
48 | /** | |
49 | * Get the start time of this tree. | |
50 | * | |
51 | * @return The start time | |
52 | */ | |
53 | long getTreeStart(); | |
54 | ||
55 | /** | |
56 | * Get the current end time of this tree. | |
57 | * | |
58 | * @return The end time | |
59 | */ | |
60 | long getTreeEnd(); | |
61 | ||
62 | /** | |
63 | * Get the number of nodes in this tree. | |
64 | * | |
65 | * @return The number of nodes | |
66 | */ | |
67 | int getNodeCount(); | |
68 | ||
69 | /** | |
70 | * Get the current root node of this tree | |
71 | * | |
72 | * @return The root node | |
73 | */ | |
74 | HTNode getRootNode(); | |
75 | ||
76 | // ------------------------------------------------------------------------ | |
77 | // HT_IO interface | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
80 | /** | |
81 | * Return the FileInputStream reader with which we will read an attribute | |
82 | * tree (it will be sought to the correct position). | |
83 | * | |
84 | * @return The FileInputStream indicating the file and position from which | |
85 | * the attribute tree can be read. | |
86 | */ | |
87 | FileInputStream supplyATReader(); | |
88 | ||
89 | /** | |
90 | * Return the file to which we will write the attribute tree. | |
91 | * | |
92 | * @return The file to which we will write the attribute tree | |
93 | */ | |
94 | File supplyATWriterFile(); | |
95 | ||
96 | /** | |
97 | * Return the position in the file (given by {@link #supplyATWriterFile}) | |
98 | * where to start writing the attribute tree. | |
99 | * | |
100 | * @return The position in the file where to start writing | |
101 | */ | |
102 | long supplyATWriterFilePos(); | |
103 | ||
104 | /** | |
105 | * Read a node from the tree. | |
106 | * | |
107 | * @param seqNumber | |
108 | * The sequence number of the node to read | |
109 | * @return The node | |
110 | * @throws ClosedChannelException | |
111 | * If the tree IO is unavailable | |
112 | */ | |
113 | HTNode readNode(int seqNumber) throws ClosedChannelException; | |
114 | ||
115 | /** | |
116 | * Write a node object to the history file. | |
117 | * | |
118 | * @param node | |
119 | * The node to write to disk | |
120 | */ | |
121 | void writeNode(HTNode node); | |
122 | ||
123 | /** | |
124 | * Close the history file. | |
125 | */ | |
126 | void closeFile(); | |
127 | ||
128 | /** | |
129 | * Delete the history file. | |
130 | */ | |
131 | void deleteFile(); | |
132 | ||
133 | // ------------------------------------------------------------------------ | |
134 | // Operations | |
135 | // ------------------------------------------------------------------------ | |
136 | ||
137 | /** | |
138 | * Insert an interval in the tree. | |
139 | * | |
140 | * @param interval | |
141 | * The interval to be inserted | |
142 | * @throws TimeRangeException | |
143 | * If the start of end time of the interval are invalid | |
144 | */ | |
145 | void insertInterval(HTInterval interval) throws TimeRangeException; | |
146 | ||
147 | /** | |
148 | * Inner method to select the next child of the current node intersecting | |
149 | * the given timestamp. Useful for moving down the tree following one | |
150 | * branch. | |
151 | * | |
152 | * @param currentNode | |
153 | * The node on which the request is made | |
154 | * @param t | |
155 | * The timestamp to choose which child is the next one | |
156 | * @return The child node intersecting t | |
157 | * @throws ClosedChannelException | |
158 | * If the file channel was closed while we were reading the tree | |
159 | */ | |
160 | HTNode selectNextChild(CoreNode currentNode, long t) throws ClosedChannelException; | |
161 | ||
162 | /** | |
163 | * Get the current size of the history file. | |
164 | * | |
165 | * @return The history file size | |
166 | */ | |
167 | long getFileSize(); | |
168 | ||
3a081e85 | 169 | } |