1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
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
10 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.statesystem
.core
.backend
;
16 import java
.io
.IOException
;
18 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
19 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.InMemoryBackend
;
20 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.NullBackend
;
21 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.HistoryTreeBackend
;
22 import org
.eclipse
.tracecompass
.internal
.statesystem
.core
.backend
.historytree
.ThreadedHistoryTreeBackend
;
25 * Factory for the various types {@link IStateHistoryBackend} supplied by this
28 * @author Alexandre Montplaisir
32 public final class StateHistoryBackendFactory
{
34 private StateHistoryBackendFactory() {}
37 * Create a new null-backend, which will not store any history intervals
38 * (only the current state can be queried).
41 * The ID for this state system
42 * @return The state system backend
44 public static IStateHistoryBackend
createNullBackend(String ssid
) {
45 return new NullBackend(ssid
);
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.
53 * The ID for this state system
55 * The start time of the state system and backend
56 * @return The state system backend
58 public static IStateHistoryBackend
createInMemoryBackend(String ssid
, long startTime
) {
59 return new InMemoryBackend(ssid
, startTime
);
63 * Create a new backend using a History Tree. This backend stores all its
66 * By specifying a 'queueSize' parameter, the implementation that runs in a
67 * separate thread can be used.
70 * The state system's id
72 * The filename/location where to store the state history (Should
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
79 * The earliest time stamp that will be stored in the history
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
85 * @return The state system backend
87 * Thrown if we can't create the file for some reason
89 public static IStateHistoryBackend
createHistoryTreeBackendNewFile(String ssid
,
90 File stateFile
, int providerVersion
, long startTime
, int queueSize
) throws IOException
{
92 return new ThreadedHistoryTreeBackend(ssid
, stateFile
, providerVersion
, startTime
, queueSize
);
94 return new HistoryTreeBackend(ssid
, stateFile
, providerVersion
, startTime
);
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
103 * The state system's id
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.
114 public static IStateHistoryBackend
createHistoryTreeBackendExistingFile(String ssid
, File stateFile
,
115 int providerVersion
) throws IOException
{
116 return new HistoryTreeBackend(ssid
, stateFile
, providerVersion
);