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
.event
.LttngEvent
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.IStateDataRequestListener
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.StateManager
;
20 import org
.eclipse
.linuxtools
.tmf
.component
.TmfComponent
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
22 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
23 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperimentSelectedSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
30 public class StateExperimentManager
extends TmfComponent
{
32 // ========================================================================
34 // =======================================================================
36 private final Map
<String
, StateManager
> managersByID
= new HashMap
<String
, StateManager
>();
37 private TmfExperiment
<LttngEvent
> fExperiment
= null; // one experiment supported
39 // ========================================================================
41 // =======================================================================
44 * package level constructor, creation from factory
46 StateExperimentManager() {
50 // ========================================================================
52 // =======================================================================
55 * Return the Map of unique id to Manager instance
59 public Map
<String
, StateManager
> getManagersByID() {
64 * Read all available traces from the nearest checkpoint from start position
65 * to the end of a specified time range
69 * @param transactionID
72 public void readExperimentTimeWindow(TmfTimeRange trange
,
73 String transactionID
, IStateDataRequestListener listener
) {
74 if (fExperiment
!= null) {
75 String id
= fExperiment
.getExperimentId();
76 StateManager manager
= managersByID
.get(id
);
77 if (manager
!= null) {
78 // TODO: A loop to request data for each trace needs to be used
79 // here when multiple traces are supported.
80 manager
.executeDataRequest(trange
, transactionID
, listener
);
85 public void readExperiment(String transactionID
,
86 IStateDataRequestListener listener
) {
87 // Need someone to listen to the updates as well as an fExperiment
89 if (listener
!= null && fExperiment
!= null) {
90 TmfTimeRange trange
= fExperiment
.getTimeRange();
91 String experimentId
= fExperiment
.getExperimentId();
93 // FIXME: there should be an id field available at the trace level
94 // to be fixed with the support of multiple files.
95 // We also need to iterate over the traces in the Experiment and
96 // execute a data Request on each of them
97 // This is also on hold till the request can be performed at a trace
99 // ITmfTrace[] fTraces = fExperiment.getTraces();
100 // for (int i=0; i < fTraces.length; i++) {
101 StateManager manager
= StateManagerFactory
.getManager(experimentId
);
102 manager
.executeDataRequest(trange
, transactionID
, listener
);
111 * org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEventListener#handleEvent
112 * (org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEvent)
114 @SuppressWarnings("unchecked")
116 public void experimentSelected(TmfExperimentSelectedSignal signal
) {
117 // TmfExperiment experiment = signal.getExperiment();
118 // ITmfTrace[] traces = experiment.getTraces();
119 // for (ITmfTrace trace : traces) {
122 if (signal
!= null) {
123 fExperiment
= (TmfExperiment
<LttngEvent
>) signal
.getExperiment();
124 traceSelected(fExperiment
);
129 * A new Experiment selected, notification received from the framework
130 * Notify the new log selection to the state handling managers
134 private void traceSelected(TmfExperiment
<LttngEvent
> experiment
) {
135 // TODO: Re-factor when multiple traces are supported
136 // traceId, as well as when the request can be specified at the trace
138 // For the moment it does work for only one trace per experiment.
139 String experimentId
= experiment
.getExperimentId();
140 StateManager manager
= StateManagerFactory
.getManager(experimentId
);
141 // TODO: clearAllData shall not be applied to all manager calls below
142 // since that would clean all data loaded within previous iterations in
143 // the future loop. i.e. It can be applied to first manager in the loop.
144 boolean clearAllData
= true;
145 manager
.setTraceSelection(experiment
, clearAllData
);
151 public TmfTimeRange
getExperimentTimeRange() {
152 TmfTimeRange timeRangeResult
= null;
153 if (fExperiment
!= null) {
154 timeRangeResult
= fExperiment
.getTimeRange();
156 return timeRangeResult
;