[Bug292967] Second part of request coalescing + unit tests + minor fixes.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / experiment / StateExperimentManager.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.state.experiment;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
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;
25
26 /**
27 * @author alvaro
28 *
29 */
30 public class StateExperimentManager extends TmfComponent {
31
32 // ========================================================================
33 // Data
34 // =======================================================================
35
36 private final Map<String, StateManager> managersByID = new HashMap<String, StateManager>();
37 private TmfExperiment<LttngEvent> fExperiment = null; // one experiment supported
38
39 // ========================================================================
40 // Constructors
41 // =======================================================================
42
43 /**
44 * package level constructor, creation from factory
45 */
46 StateExperimentManager() {
47 super("StateExperimentManager");
48 }
49
50 // ========================================================================
51 // Methods
52 // =======================================================================
53
54 /**
55 * Return the Map of unique id to Manager instance
56 *
57 * @return
58 */
59 public Map<String, StateManager> getManagersByID() {
60 return managersByID;
61 }
62
63 /**
64 * Read all available traces from the nearest checkpoint from start position
65 * to the end of a specified time range
66 *
67 * @param trange
68 * @param obs
69 * @param transactionID
70 * @param display
71 */
72 public void readExperimentTimeWindow(TmfTimeRange trange,
73 String transactionID, IStateDataRequestListener listener) {
74 if (fExperiment != null) {
75 String id = fExperiment.getName();
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);
81 }
82 }
83 }
84
85 public void readExperiment(String transactionID,
86 IStateDataRequestListener listener) {
87 // Need someone to listen to the updates as well as an fExperiment
88 // loaded.
89 if (listener != null && fExperiment != null) {
90 TmfTimeRange trange = fExperiment.getTimeRange();
91 String experimentId = fExperiment.getName();
92
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
98 // level.
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);
103 // }
104 }
105 }
106
107 /*
108 * (non-Javadoc)
109 *
110 * @see
111 * org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEventListener#handleEvent
112 * (org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEvent)
113 */
114 @SuppressWarnings("unchecked")
115 @TmfSignalHandler
116 public void experimentSelected(TmfExperimentSelectedSignal<LttngEvent> signal) {
117 // TmfExperiment experiment = signal.getExperiment();
118 // ITmfTrace[] traces = experiment.getTraces();
119 // for (ITmfTrace trace : traces) {
120 //
121 // }
122 if (signal != null) {
123 fExperiment = (TmfExperiment<LttngEvent>) signal.getExperiment();
124 traceSelected(fExperiment);
125 }
126 }
127
128 /**
129 * A new Experiment selected, notification received from the framework
130 * Notify the new log selection to the state handling managers
131 *
132 * @param experiment
133 */
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
137 // level
138 // For the moment it does work for only one trace per experiment.
139 String experimentId = experiment.getName();
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);
146 }
147
148 /**
149 * @return
150 */
151 public TmfTimeRange getExperimentTimeRange() {
152 TmfTimeRange timeRangeResult = null;
153 if (fExperiment != null) {
154 timeRangeResult = fExperiment.getTimeRange();
155 }
156 return timeRangeResult;
157 }
158
159 }
This page took 0.046272 seconds and 6 git commands to generate.