tmf: Clarify why CtfTmfEvent's constructor is public
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / HistoryBuilder.java
CommitLineData
a52fde77
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>
5 *
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
10 *
11 *******************************************************************************/
12
18ab1d18 13package org.eclipse.linuxtools.tmf.core.statesystem;
a52fde77
AM
14
15import java.io.IOException;
16
18ab1d18 17import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateHistorySystem;
a52fde77
AM
18
19/**
20 * This is the high-level wrapper around the State History and its input and
21 * storage plugins. Just create the object using the constructor then .run()
22 *
23 * You can use one HistoryBuilder and it will instantiate everything underneath.
24 * If you need more fine-grained control you can still ignore this and
25 * instantiate everything manually.
26 *
27 * @author alexmont
28 *
29 */
30public class HistoryBuilder implements Runnable {
31
32 private final IStateChangeInput sci;
d26f90fd 33 private final StateHistorySystem shs;
a52fde77
AM
34 private final IStateHistoryBackend hb;
35
db5abf97 36 private final Thread sciThread;
a52fde77
AM
37
38 /**
39 * Instantiate a new HistoryBuilder helper.
40 *
41 * @param stateChangeInput
42 * The input plugin to use. This is required.
43 * @param backend
44 * The backend storage to use. Use "null" here if you want a
45 * state system with no history.
46 * @throws IOException
47 * Is thrown if anything went wrong (usually with the storage
48 * backend)
49 */
50 public HistoryBuilder(IStateChangeInput stateChangeInput,
51 IStateHistoryBackend backend) throws IOException {
52 assert (stateChangeInput != null);
d26f90fd 53 assert (backend != null);
a52fde77 54
d26f90fd
AM
55 sci = stateChangeInput;
56 hb = backend;
57 shs = new StateHistorySystem(hb, true);
a52fde77 58
d26f90fd 59 sci.assignTargetStateSystem(shs);
db5abf97 60 sciThread = new Thread(sci, "Input Plugin"); //$NON-NLS-1$
a52fde77
AM
61 }
62
d26f90fd
AM
63 /**
64 * Factory-style method to open an existing history, you only have to
65 * provide the already-instantiated IStateHistoryBackend object.
66 *
67 * @param hb
68 * The history-backend object
69 * @return A IStateSystemBuilder reference to the new state system. If you
70 * will only run queries on this history, you should *definitely*
71 * cast it to IStateSystemQuerier.
72 * @throws IOException
73 * If there was something wrong.
74 */
75 public static IStateSystemBuilder openExistingHistory(
76 IStateHistoryBackend hb) throws IOException {
77 return new StateHistorySystem(hb, false);
78 }
79
a52fde77
AM
80 @Override
81 public void run() {
db5abf97
AM
82 sciThread.start();
83 }
a52fde77 84
db5abf97
AM
85 /**
86 * Since HistoryBuilder.run() simply starts the processing asynchronously,
87 * you should call .close() when you know the state history is completely
88 * built (or when the user closes the trace, whichever comes first).
89 */
90 public void close() {
a52fde77 91 try {
db5abf97 92 sciThread.join();
a52fde77
AM
93 } catch (InterruptedException e) {
94 e.printStackTrace();
a52fde77
AM
95 }
96 }
97
98 /**
d26f90fd
AM
99 * Return a read/write reference to the state system object that was
100 * created.
101 *
102 * @return Reference to the state system, with access to everything.
103 */
104 public IStateSystemBuilder getStateSystemBuilder() {
105 return shs;
106 }
107
108 /**
109 * Return a read-only reference to the state system object that was created.
a52fde77 110 *
d26f90fd
AM
111 * @return Reference to the state system, but only with the query methods
112 * available.
a52fde77 113 */
d26f90fd
AM
114 public IStateSystemQuerier getStateSystemQuerier() {
115 return shs;
a52fde77
AM
116 }
117
118}
This page took 0.037447 seconds and 5 git commands to generate.