1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.state
.experiment
;
14 import java
.util
.HashMap
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.IStateDataRequestListener
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateManager
;
19 import org
.eclipse
.linuxtools
.tmf
.component
.TmfComponent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
22 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfExperiment
;
23 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfExperimentSelectedSignal
;
29 public class StateExperimentManager
extends TmfComponent
{
31 // ========================================================================
33 // =======================================================================
35 private final Map
<String
, StateManager
> managersByID
= new HashMap
<String
, StateManager
>();
36 private TmfExperiment fExperiment
= null; // one experiment supported
38 // ========================================================================
40 // =======================================================================
43 * package level constructor, creation from factory
45 StateExperimentManager() {
49 // ========================================================================
51 // =======================================================================
54 * Return the Map of unique id to Manager instance
58 public Map
<String
, StateManager
> getManagersByID() {
63 * Read all available traces from the nearest checkpoint from start position
64 * to the end of a specified time range
68 * @param transactionID
71 public void readExperimentTimeWindow(TmfTimeRange trange
,
72 String transactionID
, IStateDataRequestListener listener
) {
73 if (fExperiment
!= null) {
74 String id
= fExperiment
.getExperimentId();
75 StateManager manager
= managersByID
.get(id
);
76 if (manager
!= null) {
77 // TODO: A loop to request data for each trace needs to be used
78 // here when multiple traces are supported.
79 manager
.executeDataRequest(trange
, transactionID
, listener
);
84 public void readExperiment(String transactionID
,
85 IStateDataRequestListener listener
) {
86 // Need someone to listen to the updates as well as an fExperiment
88 if (listener
!= null && fExperiment
!= null) {
89 TmfTimeRange trange
= fExperiment
.getTimeRange();
90 String experimentId
= fExperiment
.getExperimentId();
92 // FIXME: there should be an id field available at the trace level
93 // to be fixed with the support of multiple files.
94 // We also need to iterate over the traces in the Experiment and
95 // execute a data Request on each of them
96 // This is also on hold till the request can be performed at a trace
98 // ITmfTrace[] fTraces = fExperiment.getTraces();
99 // for (int i=0; i < fTraces.length; i++) {
100 StateManager manager
= StateManagerFactory
.getManager(experimentId
);
101 manager
.executeDataRequest(trange
, transactionID
, listener
);
110 * org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEventListener#handleEvent
111 * (org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEvent)
114 public void experimentSelected(TmfExperimentSelectedSignal signal
) {
115 // TmfExperiment experiment = signal.getExperiment();
116 // ITmfTrace[] traces = experiment.getTraces();
117 // for (ITmfTrace trace : traces) {
120 if (signal
!= null) {
121 fExperiment
= signal
.getExperiment();
122 traceSelected(fExperiment
);
127 * A new Experiment selected, notification received from the framework
128 * Notify the new log selection to the state handling managers
132 private void traceSelected(TmfExperiment experiment
) {
133 // TODO: Re-factor when multiple traces are supported
134 // traceId, as well as when the request can be specified at the trace
136 // For the moment it does work for only one trace per experiment.
137 String experimentId
= experiment
.getExperimentId();
138 StateManager manager
= StateManagerFactory
.getManager(experimentId
);
139 // TODO: clearAllData shall not be applied to all manager calls below
140 // since that would clean all data loaded within previous iterations in
141 // the future loop. i.e. It can be applied to first manager in the loop.
142 boolean clearAllData
= true;
143 manager
.setTraceSelection(experiment
, clearAllData
);
149 public TmfTimeRange
getExperimentTimeRange() {
150 TmfTimeRange timeRangeResult
= null;
151 if (fExperiment
!= null) {
152 timeRangeResult
= fExperiment
.getTimeRange();
154 return timeRangeResult
;