Commit | Line | Data |
---|---|---|
068641fa GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 École Polytechnique de Montréal | |
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.statesystem.core.tests.stubs.backend; | |
11 | ||
12 | import java.io.File; | |
13 | import java.io.IOException; | |
14 | ||
15 | import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig; | |
068641fa | 16 | import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTreeBackend; |
3a081e85 | 17 | import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.IHistoryTree; |
068641fa GB |
18 | |
19 | /** | |
20 | * Stub class for the {@link HistoryTreeBackend}. It creates a | |
3a081e85 | 21 | * {@link HistoryTreeClassicStub} to grant access to some protected methods. |
068641fa GB |
22 | * |
23 | * @author Geneviève Bastien | |
24 | */ | |
25 | public class HistoryTreeBackendStub extends HistoryTreeBackend { | |
26 | ||
3a081e85 GB |
27 | private static HistoryTreeType HT_TYPE = HistoryTreeType.CLASSIC; |
28 | ||
29 | /** | |
30 | * Sets the type of tree to build. Since the history tree is initialized in | |
31 | * the parent's constructor, this stub class needs to know the type of tree | |
32 | * to build. | |
33 | * | |
34 | * @param htType | |
35 | * The type of history tree to build for this backend | |
36 | */ | |
37 | public static void setTreeType(HistoryTreeType htType) { | |
38 | HT_TYPE = htType; | |
39 | } | |
40 | ||
41 | /** | |
42 | * Enumeration of all history tree types implemented. This will be used to | |
43 | * create the right type of history tree | |
44 | */ | |
45 | public enum HistoryTreeType { | |
46 | /** | |
47 | * The classic history tree | |
48 | */ | |
49 | CLASSIC | |
50 | } | |
51 | ||
068641fa GB |
52 | /** |
53 | * Constructor for new history files. Use this when creating a new history | |
54 | * from scratch. | |
55 | * | |
56 | * @param ssid | |
57 | * The state system's ID | |
58 | * @param newStateFile | |
59 | * The filename/location where to store the state history (Should | |
60 | * end in .ht) | |
61 | * @param providerVersion | |
62 | * Version of of the state provider. We will only try to reopen | |
63 | * existing files if this version matches the one in the | |
64 | * framework. | |
65 | * @param startTime | |
66 | * The earliest time stamp that will be stored in the history | |
67 | * @param blockSize | |
68 | * The size of the blocks in the history file. This should be a | |
69 | * multiple of 4096. | |
70 | * @param maxChildren | |
71 | * The maximum number of children each core node can have | |
72 | * @throws IOException | |
73 | * Thrown if we can't create the file for some reason | |
74 | */ | |
75 | public HistoryTreeBackendStub(String ssid, | |
76 | File newStateFile, | |
77 | int providerVersion, | |
78 | long startTime, | |
79 | int blockSize, | |
80 | int maxChildren) throws IOException { | |
81 | super(ssid, newStateFile, providerVersion, startTime, blockSize, maxChildren); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Existing history constructor. Use this to open an existing state-file. | |
86 | * | |
87 | * @param ssid | |
88 | * The state system's id | |
89 | * @param existingStateFile | |
90 | * Filename/location of the history we want to load | |
91 | * @param providerVersion | |
92 | * Expected version of of the state provider plugin. | |
93 | * @throws IOException | |
94 | * If we can't read the file, if it doesn't exist, is not | |
95 | * recognized, or if the version of the file does not match the | |
96 | * expected providerVersion. | |
97 | */ | |
98 | public HistoryTreeBackendStub(String ssid, File existingStateFile, int providerVersion) | |
99 | throws IOException { | |
100 | super(ssid, existingStateFile, providerVersion); | |
101 | } | |
102 | ||
103 | @Override | |
3a081e85 GB |
104 | protected IHistoryTree initializeSHT(HTConfig conf) throws IOException { |
105 | switch (HT_TYPE) { | |
106 | case CLASSIC: | |
107 | return new HistoryTreeClassicStub(conf); | |
108 | default: | |
109 | return new HistoryTreeClassicStub(conf); | |
110 | } | |
068641fa GB |
111 | } |
112 | ||
113 | @Override | |
3a081e85 GB |
114 | protected IHistoryTree initializeSHT(File existingStateFile, int providerVersion) throws IOException { |
115 | switch (HT_TYPE) { | |
116 | case CLASSIC: | |
117 | return new HistoryTreeClassicStub(existingStateFile, providerVersion); | |
118 | default: | |
119 | return new HistoryTreeClassicStub(existingStateFile, providerVersion); | |
120 | } | |
068641fa GB |
121 | } |
122 | ||
9a0967e4 GB |
123 | /** |
124 | * Get the History Tree built by this backend. | |
125 | * | |
126 | * @return The history tree | |
127 | */ | |
3a081e85 GB |
128 | public HistoryTreeClassicStub getHistoryTree() { |
129 | return (HistoryTreeClassicStub) super.getSHT(); | |
9a0967e4 GB |
130 | } |
131 | ||
068641fa | 132 | } |