Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | + * Copyright (c) 2009, 2010 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 org.eclipse.linuxtools.lttng.TraceDebug; | |
15 | import org.eclipse.linuxtools.lttng.control.LttngCoreProviderFactory; | |
16 | import org.eclipse.linuxtools.lttng.control.LttngSyntheticEventProvider; | |
17 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
18 | import org.eclipse.linuxtools.lttng.model.LTTngTreeNode; | |
19 | import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest; | |
20 | import org.eclipse.linuxtools.lttng.request.IRequestStatusListener; | |
21 | import org.eclipse.linuxtools.lttng.signal.ILttExperimentSelectedListener; | |
22 | import org.eclipse.linuxtools.lttng.signal.StateExperimentListener; | |
23 | import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor; | |
24 | import org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager; | |
25 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
26 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; | |
27 | import org.eclipse.linuxtools.tmf.signal.TmfExperimentUpdatedSignal; | |
28 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; | |
29 | ||
30 | /** | |
31 | * @author alvaro | |
32 | * | |
33 | */ | |
34 | public class StateExperimentManager extends LTTngTreeNode implements | |
35 | ILttExperimentSelectedListener, IStateExperimentManager { | |
36 | ||
37 | // ======================================================================== | |
38 | // Data | |
39 | // ======================================================================= | |
40 | private LTTngTreeNode fSelectedExperiment = null; // one selected experiment | |
41 | // supported | |
42 | private final StateExperimentListener fexperimentListener; | |
43 | private boolean fwaitForCompletion = false; | |
44 | ||
45 | ||
46 | // ======================================================================== | |
47 | // Constructors | |
48 | // ======================================================================= | |
49 | public StateExperimentManager(Long id, String name) { | |
50 | super(id, null, name, null); | |
51 | fexperimentListener = new StateExperimentListener("Experiment Manager", | |
52 | this); | |
53 | } | |
54 | ||
55 | ||
56 | // ======================================================================== | |
57 | // Methods | |
58 | // ======================================================================= | |
59 | ||
60 | /* (non-Javadoc) | |
61 | * @see org.eclipse.linuxtools.lttng.state.experiment.IStateExperimentManager#readExperimentTimeWindow(org.eclipse.linuxtools.tmf.event.TmfTimeRange, java.lang.String, org.eclipse.linuxtools.lttng.state.IStateDataRequestListener) | |
62 | */ | |
63 | public ILttngSyntEventRequest readExperimentTimeWindow(TmfTimeRange trange, | |
64 | Object source, IRequestStatusListener listener, | |
65 | ITransEventProcessor processor) { | |
66 | ||
67 | ILttngSyntEventRequest request = null; | |
68 | ||
69 | // validate | |
70 | if (fSelectedExperiment != null) { | |
71 | // Get all trace manager nodes | |
72 | LTTngTreeNode[] traceMgrs = fSelectedExperiment.getChildren(); | |
73 | ||
74 | if (traceMgrs != null && traceMgrs.length > 0) { | |
75 | IStateTraceManager traceManager; | |
76 | // Trigger one request per trace | |
77 | for (LTTngTreeNode traceNode : traceMgrs) { | |
78 | traceManager = (IStateTraceManager) traceNode; | |
79 | request = traceManager.executeDataRequest(trange, source, | |
80 | listener, | |
81 | processor); | |
82 | } | |
83 | } | |
84 | } else { | |
85 | if (fSelectedExperiment == null) { | |
86 | TraceDebug.debug("No experiment selected"); | |
87 | } | |
88 | } | |
89 | ||
90 | return request; | |
91 | } | |
92 | ||
93 | /* (non-Javadoc) | |
94 | * @see org.eclipse.linuxtools.lttng.state.experiment.IStateExperimentManager#readExperiment(java.lang.String, org.eclipse.linuxtools.lttng.state.IStateDataRequestListener) | |
95 | */ | |
96 | @SuppressWarnings("unchecked") | |
97 | public void readExperiment(Object source, IRequestStatusListener listener, | |
98 | ITransEventProcessor processor) { | |
99 | // validate | |
100 | if (fSelectedExperiment != null) { | |
101 | TmfExperiment<LttngEvent> experiment = (TmfExperiment<LttngEvent>) fSelectedExperiment | |
102 | .getValue(); | |
103 | TmfTimeRange trange = experiment.getTimeRange(); | |
104 | readExperimentTimeWindow(trange, source, listener, processor); | |
105 | } else { | |
106 | TraceDebug.debug("No selected experiment available"); | |
107 | } | |
108 | } | |
109 | ||
110 | ||
111 | ||
112 | /* | |
113 | * (non-Javadoc) | |
114 | * | |
115 | * @see | |
116 | * org.eclipse.linuxtools.lttng.state.experiment.IStateExperimentManager | |
117 | * #experimentSelected_prep | |
118 | * (org.eclipse.linuxtools.tmf.experiment.TmfExperiment) | |
119 | */ | |
120 | public void experimentSelected_prep(TmfExperiment<LttngEvent> experiment) { | |
121 | LTTngTreeNode experimentNode = null; | |
122 | if (experiment != null) { | |
123 | experimentNode = getChildByName(experiment.getName()); | |
124 | // keep experiment if already loaded with the same value | |
125 | if (experimentNode != null | |
126 | && experimentNode.getValue() != experiment) { | |
127 | // rebuild the experiment nodes from scratch | |
128 | removeChild(experimentNode); | |
129 | experimentNode = null; | |
130 | } | |
131 | ||
132 | // Make sure all traces involved have a corresponding state manager | |
133 | // and | |
134 | // state system to request its initial data | |
135 | if (experimentNode == null) { | |
136 | // Create the new experiment tree node | |
137 | experimentNode = new LTTngTreeNode(getNextUniqueId(), this, | |
138 | experiment.getName(), experiment); | |
139 | // add the new experiment to this children list | |
140 | addChild(experimentNode); | |
141 | } | |
142 | ||
143 | // Make sure the traces exists in the tree | |
144 | ITmfTrace[] rtraces = experiment.getTraces(); | |
145 | String traceName; | |
146 | LTTngTreeNode traceStateManagerNode; | |
147 | // StateStacksHandler | |
148 | for (ITmfTrace rtrace : rtraces) { | |
149 | traceName = rtrace.getName(); | |
150 | traceStateManagerNode = experimentNode.getChildByName(traceName); | |
151 | // Node does not exist for this experiment, so needs to be | |
152 | // created | |
153 | if (traceStateManagerNode == null) { | |
154 | traceStateManagerNode = StateManagerFactory.getManager( | |
155 | rtrace, experimentNode); | |
156 | experimentNode.addChild(traceStateManagerNode); | |
157 | } | |
158 | } | |
159 | ||
160 | // Reset event provider to handle requests for the new experiment | |
161 | LttngSyntheticEventProvider synEventProvider = LttngCoreProviderFactory | |
162 | .getEventProvider(); | |
163 | synEventProvider.reset(experimentNode); | |
164 | ||
165 | // preserve the selected experiment | |
166 | fSelectedExperiment = experimentNode; | |
167 | } | |
168 | } | |
169 | ||
170 | /* | |
171 | * (non-Javadoc) | |
172 | * | |
173 | * @see org.eclipse.linuxtools.lttng.signal.ILttExperimentSelectedListener# | |
174 | * experimentSelected(java.lang.Object, | |
175 | * org.eclipse.linuxtools.tmf.experiment.TmfExperiment) | |
176 | */ | |
177 | public void experimentSelected(Object source, | |
178 | TmfExperiment<LttngEvent> experiment) { | |
179 | // validate | |
180 | if (experiment == null) { | |
181 | return; | |
182 | } | |
183 | ||
184 | LTTngTreeNode experimentNode = getChildByName(experiment.getName()); | |
185 | if (experimentNode != null) { | |
186 | // get the trace manager nodes | |
187 | LTTngTreeNode[] traceNodes = experimentNode.getChildren(); | |
188 | for (LTTngTreeNode traceStateManagerNode : traceNodes) { | |
189 | // The trace node needs to perform its first data request | |
190 | // for this experiment with the main goal of building its | |
191 | // checkpoints | |
192 | if (traceStateManagerNode instanceof ILttExperimentSelectedListener) { | |
193 | // no need to provide the trace to the trace manager | |
194 | ((ILttExperimentSelectedListener) traceStateManagerNode).experimentUpdated( | |
195 | new TmfExperimentUpdatedSignal(source, experiment, null), fwaitForCompletion); | |
196 | } | |
197 | } | |
198 | } | |
199 | } | |
200 | ||
201 | /* | |
202 | * (non-Javadoc) | |
203 | * | |
204 | * @see org.eclipse.linuxtools.lttng.signal.ILttExperimentSelectedListener# | |
205 | * experimentUpdated | |
206 | * (org.eclipse.linuxtools.tmf.signal.TmfExperimentUpdatedSignal, boolean) | |
207 | */ | |
208 | public void experimentUpdated(TmfExperimentUpdatedSignal signal, boolean wait) { | |
209 | // NOTE: This represents the end of TMF indexing for a trace, however | |
210 | // the node was already existing and the state system check points are | |
211 | // already requested and built upon selection. | |
212 | // No action for the time being | |
213 | } | |
214 | ||
215 | ||
216 | /** | |
217 | * @return the SelectedExperiment tree node | |
218 | */ | |
219 | public LTTngTreeNode getSelectedExperiment() { | |
220 | return fSelectedExperiment; | |
221 | } | |
222 | ||
223 | /* (non-Javadoc) | |
224 | * @see org.eclipse.linuxtools.lttng.state.experiment.IStateExperimentManager#getExperimentTimeRange() | |
225 | */ | |
226 | @SuppressWarnings("unchecked") | |
227 | public TmfTimeRange getExperimentTimeRange() { | |
228 | TmfTimeRange timeRangeResult = null; | |
229 | if (fSelectedExperiment != null) { | |
230 | timeRangeResult = ((TmfExperiment<LttngEvent>) fSelectedExperiment | |
231 | .getValue()).getTimeRange(); | |
232 | } | |
233 | return timeRangeResult; | |
234 | } | |
235 | ||
236 | /* | |
237 | * (non-Javadoc) | |
238 | * | |
239 | * @see java.lang.Object#finalize() | |
240 | */ | |
241 | protected void finalize() { | |
242 | fexperimentListener.dispose(); | |
243 | } | |
244 | ||
245 | ||
246 | /* | |
247 | * (non-Javadoc) | |
248 | * | |
249 | * @see | |
250 | * org.eclipse.linuxtools.lttng.state.experiment.IStateExperimentManager | |
251 | * #waitForComplete(boolean) | |
252 | */ | |
253 | public void waitForCompletion(boolean wait) { | |
254 | fwaitForCompletion = wait; | |
255 | } | |
256 | ||
257 | } |