common: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / statesystem / core / backend / StateHistoryBackendFactory.java
CommitLineData
0306a843
AM
1/*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
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 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
12
13package org.eclipse.tracecompass.statesystem.core.backend;
14
15import java.io.File;
16import java.io.IOException;
17
18import org.eclipse.jdt.annotation.NonNullByDefault;
19import org.eclipse.tracecompass.internal.statesystem.core.backend.InMemoryBackend;
20import org.eclipse.tracecompass.internal.statesystem.core.backend.NullBackend;
21import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTreeBackend;
22import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.ThreadedHistoryTreeBackend;
23
24/**
25 * Factory for the various types {@link IStateHistoryBackend} supplied by this
26 * plugin.
27 *
28 * @author Alexandre Montplaisir
29 * @since 1.0
30 */
31@NonNullByDefault
32public final class StateHistoryBackendFactory {
33
34 private StateHistoryBackendFactory() {}
35
36 /**
37 * Create a new null-backend, which will not store any history intervals
38 * (only the current state can be queried).
39 *
40 * @param ssid
41 * The ID for this state system
42 * @return The state system backend
43 */
44 public static IStateHistoryBackend createNullBackend(String ssid) {
45 return new NullBackend(ssid);
46 }
47
48 /**
49 * Create a new in-memory backend. This backend will store all the history
50 * intervals in memory, so it should not be used for anything serious.
51 *
52 * @param ssid
53 * The ID for this state system
54 * @param startTime
55 * The start time of the state system and backend
56 * @return The state system backend
57 */
58 public static IStateHistoryBackend createInMemoryBackend(String ssid, long startTime) {
59 return new InMemoryBackend(ssid, startTime);
60 }
61
62 /**
63 * Create a new backend using a History Tree. This backend stores all its
64 * intervals on disk.
65 *
66 * By specifying a 'queueSize' parameter, the implementation that runs in a
67 * separate thread can be used.
68 *
69 * @param ssid
70 * The state system's id
71 * @param stateFile
72 * The filename/location where to store the state history (Should
73 * end in .ht)
74 * @param providerVersion
75 * Version of of the state provider. We will only try to reopen
76 * existing files if this version matches the one in the
77 * framework.
78 * @param startTime
79 * The earliest time stamp that will be stored in the history
80 * @param queueSize
81 * The size of the interval insertion queue between the receiver
82 * and writer threads. 2000 - 10000 usually works well. If 0 is
83 * specified, no queue is used and the writes happen in the same
84 * thread.
85 * @return The state system backend
86 * @throws IOException
87 * Thrown if we can't create the file for some reason
88 */
89 public static IStateHistoryBackend createHistoryTreeBackendNewFile(String ssid,
f6d24a71 90 File stateFile, int providerVersion, long startTime, int queueSize) throws IOException {
0306a843 91 if (queueSize > 0) {
f6d24a71 92 return new ThreadedHistoryTreeBackend(ssid, stateFile, providerVersion, startTime, queueSize);
0306a843
AM
93 }
94 return new HistoryTreeBackend(ssid, stateFile, providerVersion, startTime);
95 }
96
97 /**
98 * Create a new History Tree backend, but attempt to open an existing file
99 * on disk. If the file cannot be found or recognized, an IOException will
100 * be thrown.
101 *
102 * @param ssid
103 * The state system's id
104 * @param stateFile
105 * Filename/location of the history we want to load
106 * @param providerVersion
107 * Expected version of of the state provider plugin.
108 * @return The state system backend
109 * @throws IOException
110 * If we can't read the file, if it doesn't exist, is not
111 * recognized, or if the version of the file does not match the
112 * expected providerVersion.
113 */
114 public static IStateHistoryBackend createHistoryTreeBackendExistingFile(String ssid, File stateFile,
115 int providerVersion) throws IOException {
116 return new HistoryTreeBackend(ssid, stateFile, providerVersion);
117 }
118}
This page took 0.032655 seconds and 5 git commands to generate.