da302f2f1587c2ef311631bcbdeb62d9563e25f2
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.datastore.core / src / org / eclipse / tracecompass / internal / provisional / datastore / core / historytree / overlapping / OverlappingHistoryTree.java
1 /*******************************************************************************
2 * Copyright (c) 2017 É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.internal.provisional.datastore.core.historytree.overlapping;
11
12 import java.io.File;
13 import java.io.IOException;
14
15 import org.eclipse.tracecompass.internal.provisional.datastore.core.interval.IHTInterval;
16 import org.eclipse.tracecompass.internal.provisional.datastore.core.interval.IHTIntervalReader;
17
18 /**
19 * Basic implementation of {@link AbstractOverlappingHistoryTree} that can
20 * be used directly by clients.
21 *
22 * @author Loic Prieur-Drevon
23 * @author Geneviève Bastien
24 * @param <E>
25 * The type of objects that will be saved in the tree
26 */
27 public class OverlappingHistoryTree<E extends IHTInterval>
28 extends AbstractOverlappingHistoryTree<E, OverlappingNode<E>> {
29
30 /**
31 * The magic number for this file format.
32 */
33 public static final int HISTORY_FILE_MAGIC_NUMBER = 0x05FFA800;
34
35 /** File format version. Increment when breaking compatibility. */
36 private static final int FILE_VERSION = 1;
37
38 private final IHTNodeFactory<E, OverlappingNode<E>> fNodeFactory =
39 (t, b, m, seq, p, start) -> new OverlappingNode<>(t, b, m, seq, p, start);
40
41 // ------------------------------------------------------------------------
42 // Constructors/"Destructors"
43 // ------------------------------------------------------------------------
44
45 /**
46 * Create a new Overlapping History Tree from scratch, specifying all
47 * configuration parameters.
48 *
49 * @param stateHistoryFile
50 * The name of the history file
51 * @param blockSize
52 * The size of each "block" on disk in bytes. One node will
53 * always fit in one block. It should be at least 4096.
54 * @param maxChildren
55 * The maximum number of children allowed per core (non-leaf)
56 * node.
57 * @param providerVersion
58 * The version of the state provider. If a file already exists,
59 * and their versions match, the history file will not be rebuilt
60 * uselessly.
61 * @param treeStart
62 * The start time of the history
63 * @param intervalReader
64 * The factory to create new tree data elements when reading from
65 * the disk
66 * @throws IOException
67 * If an error happens trying to open/write to the file
68 * specified in the config
69 */
70 public OverlappingHistoryTree(File stateHistoryFile,
71 int blockSize,
72 int maxChildren,
73 int providerVersion,
74 long treeStart,
75 IHTIntervalReader<E> intervalReader) throws IOException {
76
77 super(stateHistoryFile,
78 blockSize,
79 maxChildren,
80 providerVersion,
81 treeStart,
82 intervalReader);
83 }
84
85 /**
86 * "Reader" constructor : instantiate a SHTree from an existing tree file on
87 * disk
88 *
89 * @param existingStateFile
90 * Path/filename of the history-file we are to open
91 * @param expectedProviderVersion
92 * The expected version of the state provider
93 * @param objectReader
94 * The factory used to read segments from the history tree
95 * @throws IOException
96 * If an error happens reading the file
97 */
98 public OverlappingHistoryTree(File existingStateFile,
99 int expectedProviderVersion,
100 IHTIntervalReader<E> objectReader) throws IOException {
101 super(existingStateFile, expectedProviderVersion, objectReader);
102 }
103
104 @Override
105 protected int getMagicNumber() {
106 return HISTORY_FILE_MAGIC_NUMBER;
107 }
108
109 @Override
110 protected int getFileVersion() {
111 return FILE_VERSION;
112 }
113
114 @Override
115 protected IHTNodeFactory<E, OverlappingNode<E>> getNodeFactory() {
116 return fNodeFactory;
117 }
118
119 }
This page took 0.033014 seconds and 4 git commands to generate.