1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.statesystem
;
16 import java
.util
.HashMap
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
26 * Abstract analysis module to generate a state system. It is a base class that
27 * can be used as a shortcut by analysis who just need to build a single state
28 * system with a state provider.
30 * Analysis implementing this class should only need to provide a state system
31 * and optionally a backend (default to NULL) and, if required, a filename
32 * (defaults to the analysis'ID)
34 * @author Geneviève Bastien
37 public abstract class TmfStateSystemAnalysisModule
extends TmfAbstractAnalysisModule
38 implements ITmfStateSystemAnalysisModule
{
40 private ITmfStateSystem fStateSystem
= null;
41 private static final String EXTENSION
= ".ht"; //$NON-NLS-1$
44 * State system backend types
46 * @author Geneviève Bastien
48 protected enum StateSystemBackendType
{
49 /** Full history in file */
51 /** In memory state system */
55 /** State system backed with partial history */
60 * Get the state provider for this analysis module
62 * @return the state provider
65 protected abstract ITmfStateProvider
createStateProvider();
68 * Get the state system backend type used by this module
70 * @return The {@link StateSystemBackendType}
72 protected abstract StateSystemBackendType
getBackendType();
75 * Get the supplementary file name where to save this state system. The
76 * default is the ID of the analysis followed by the extension.
78 * @return The supplementary file name
80 protected String
getSsFileName() {
81 return getId() + EXTENSION
;
85 * Get the state system generated by this analysis
87 * @return The state system
89 public ITmfStateSystem
getStateSystem() {
94 protected boolean executeAnalysis(final IProgressMonitor monitor
) {
96 final ITmfStateProvider htInput
= createStateProvider();
98 /* FIXME: State systems should make use of the monitor, to be cancelled */
100 /* Get the state system according to backend */
101 StateSystemBackendType backend
= getBackendType();
105 directory
= TmfTraceManager
.getSupplementaryFileDir(getTrace());
106 final File htFile
= new File(directory
+ getSsFileName());
107 fStateSystem
= TmfStateSystemFactory
.newFullHistory(htFile
, htInput
, true);
110 directory
= TmfTraceManager
.getSupplementaryFileDir(getTrace());
111 final File htPartialFile
= new File(directory
+ getSsFileName());
112 fStateSystem
= TmfStateSystemFactory
.newPartialHistory(htPartialFile
, htInput
, true);
115 fStateSystem
= TmfStateSystemFactory
.newInMemHistory(htInput
, true);
118 fStateSystem
= TmfStateSystemFactory
.newNullHistory(htInput
);
123 } catch (TmfTraceException e
) {
130 protected void canceling() {
132 * FIXME: I guess that will do to cancel the state system building, but
133 * it may be preferable to just tell the state system and he will handle
134 * himself how to cancel its work
136 fStateSystem
.dispose();
140 public Map
<String
, ITmfStateSystem
> getStateSystems() {
141 Map
<String
, ITmfStateSystem
> map
= new HashMap
<>();
142 map
.put(getId(), fStateSystem
);