tmf: Add the Tmf- prefix to the state system interfaces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / StateSystemManager.java
CommitLineData
6e71ce46
AM
1/*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
83134537 5 *
6e71ce46
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
83134537 10 *
6e71ce46
AM
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.statesystem;
14
15import java.io.File;
16import java.io.IOException;
17
2ab9afbc
AM
18import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder;
19import org.eclipse.linuxtools.internal.tmf.core.statesystem.IStateHistoryBackend;
20import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.HistoryTreeBackend;
21import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.ThreadedHistoryTreeBackend;
6e71ce46
AM
22import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
23import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
6e71ce46
AM
24
25/**
26 * This abstract manager class handles loading or creating state history files
27 * for use in TMF's generic state system.
83134537 28 *
2cb26548
AM
29 * @version 1.0
30 * @author Alexandre Montplaisir
6e71ce46
AM
31 */
32public abstract class StateSystemManager extends TmfComponent {
33
34 /** Size of the blocking queue to use when building a state history */
35 private final static int QUEUE_SIZE = 10000;
36
37 /**
38 * Load the history file matching the target trace. If the file already
39 * exists, it will be opened directly. If not, it will be created from
40 * scratch. In the case the history has to be built, it's possible to block
41 * the calling thread until construction is complete.
83134537 42 *
6e71ce46
AM
43 * @param htFile
44 * The target name of the history file we want to use. If it
45 * exists it will be opened. If it doesn't, a new file will be
46 * created with this name/path.
47 * @param htInput
48 * The IStateChangeInput to use for building the history file. It
49 * may be required even if we are opening an already-existing
50 * history (ie, for partial histories).
e34f7caa
AM
51 * @param buildManually
52 * If false, the construction will wait for a signal before
53 * starting. If true, it will build everything right now and
54 * block the caller. It has no effect if the file already exists.
6e71ce46
AM
55 * @return A IStateSystemQuerier handler to the state system, with which you
56 * can then run queries on the history.
57 * @throws TmfTraceException
5df842b3
AM
58 * If there was a problem reading or writing one of the files.
59 * See the contents of this exception for more info.
f1f86dfb 60 * @since 2.0
6e71ce46 61 */
f1f86dfb 62 public static ITmfStateSystem loadStateHistory(File htFile,
e34f7caa 63 IStateChangeInput htInput, boolean buildManually)
51e216bd 64 throws TmfTraceException {
f1f86dfb 65 ITmfStateSystem ss;
6e71ce46 66 IStateHistoryBackend htBackend;
51e216bd 67
6e71ce46
AM
68 /* If the target file already exists, do not rebuild it uselessly */
69 // TODO for now we assume it's complete. Might be a good idea to check
70 // at least if its range matches the trace's range.
71 if (htFile.exists()) {
72 /* Load an existing history */
73 try {
74 htBackend = new HistoryTreeBackend(htFile);
75 ss = HistoryBuilder.openExistingHistory(htBackend);
76 return ss;
77 } catch (IOException e) {
78 /*
79 * There was an error opening the existing file. Perhaps it was
80 * corrupted, perhaps it's an old version? We'll just
81 * fall-through and try to build a new one from scratch instead.
82 */
83 }
84 }
85
86 /* Create a new state history from scratch */
87 HistoryBuilder builder;
51e216bd 88
6e71ce46
AM
89 if (htInput == null) {
90 return null;
91 }
92 try {
93 htBackend = new ThreadedHistoryTreeBackend(htFile,
94 htInput.getStartTime(), QUEUE_SIZE);
e34f7caa 95 builder = new HistoryBuilder(htInput, htBackend, buildManually);
6e71ce46 96 } catch (IOException e) {
51e216bd
AM
97 /*
98 * If it fails here however, it means there was a problem writing to
99 * the disk, so throw a real exception this time.
6e71ce46
AM
100 */
101 throw new TmfTraceException(e.toString(), e);
102 }
103 return builder.getStateSystemQuerier();
104 }
105}
This page took 0.035636 seconds and 5 git commands to generate.