Commit | Line | Data |
---|---|---|
5d10d135 | 1 | /******************************************************************************* |
88144d4a | 2 | * Copyright (c) 2009 Ericsson |
5d10d135 ASL |
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 | ||
9aae0442 ASL |
14 | import java.util.HashMap; |
15 | import java.util.Map; | |
16 | ||
e31e01e8 | 17 | import org.eclipse.linuxtools.lttng.event.LttngEvent; |
88144d4a ASL |
18 | import org.eclipse.linuxtools.lttng.state.IStateDataRequestListener; |
19 | import org.eclipse.linuxtools.lttng.state.StateManager; | |
20 | import org.eclipse.linuxtools.tmf.component.TmfComponent; | |
5d10d135 | 21 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
e31e01e8 FC |
22 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
23 | import org.eclipse.linuxtools.tmf.experiment.TmfExperimentSelectedSignal; | |
88144d4a | 24 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
5d10d135 ASL |
25 | |
26 | /** | |
27 | * @author alvaro | |
28 | * | |
29 | */ | |
88144d4a | 30 | public class StateExperimentManager extends TmfComponent { |
5d10d135 ASL |
31 | |
32 | // ======================================================================== | |
33 | // Data | |
34 | // ======================================================================= | |
88144d4a ASL |
35 | |
36 | private final Map<String, StateManager> managersByID = new HashMap<String, StateManager>(); | |
e31e01e8 | 37 | private TmfExperiment<LttngEvent> fExperiment = null; // one experiment supported |
5d10d135 ASL |
38 | |
39 | // ======================================================================== | |
40 | // Constructors | |
41 | // ======================================================================= | |
5d10d135 | 42 | |
88144d4a ASL |
43 | /** |
44 | * package level constructor, creation from factory | |
45 | */ | |
46 | StateExperimentManager() { | |
47 | super(); | |
48 | } | |
5d10d135 ASL |
49 | |
50 | // ======================================================================== | |
51 | // Methods | |
52 | // ======================================================================= | |
53 | ||
88144d4a ASL |
54 | /** |
55 | * Return the Map of unique id to Manager instance | |
5d10d135 | 56 | * |
88144d4a | 57 | * @return |
5d10d135 | 58 | */ |
88144d4a ASL |
59 | public Map<String, StateManager> getManagersByID() { |
60 | return managersByID; | |
5d10d135 ASL |
61 | } |
62 | ||
88144d4a ASL |
63 | /** |
64 | * Read all available traces from the nearest checkpoint from start position | |
65 | * to the end of a specified time range | |
5d10d135 | 66 | * |
88144d4a ASL |
67 | * @param trange |
68 | * @param obs | |
69 | * @param transactionID | |
70 | * @param display | |
5d10d135 | 71 | */ |
58c60db3 | 72 | public void readExperimentTimeWindow(TmfTimeRange trange, |
88144d4a | 73 | String transactionID, IStateDataRequestListener listener) { |
41dc35d0 FC |
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); | |
81 | } | |
5d10d135 | 82 | } |
88144d4a | 83 | } |
5d10d135 | 84 | |
88144d4a ASL |
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(); | |
dfaf8391 FC |
91 | String experimentId = fExperiment.getExperimentId(); |
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 | // } | |
5d10d135 ASL |
104 | } |
105 | } | |
88144d4a | 106 | |
5d10d135 ASL |
107 | /* |
108 | * (non-Javadoc) | |
109 | * | |
88144d4a ASL |
110 | * @see |
111 | * org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEventListener#handleEvent | |
112 | * (org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEvent) | |
5d10d135 | 113 | */ |
e31e01e8 | 114 | @SuppressWarnings("unchecked") |
88144d4a ASL |
115 | @TmfSignalHandler |
116 | public void experimentSelected(TmfExperimentSelectedSignal signal) { | |
117 | // TmfExperiment experiment = signal.getExperiment(); | |
118 | // ITmfTrace[] traces = experiment.getTraces(); | |
119 | // for (ITmfTrace trace : traces) { | |
120 | // | |
121 | // } | |
122 | if (signal != null) { | |
e31e01e8 | 123 | fExperiment = (TmfExperiment<LttngEvent>) signal.getExperiment(); |
88144d4a ASL |
124 | traceSelected(fExperiment); |
125 | } | |
5d10d135 ASL |
126 | } |
127 | ||
5d10d135 | 128 | /** |
d712a5f3 FC |
129 | * A new Experiment selected, notification received from the framework |
130 | * Notify the new log selection to the state handling managers | |
88144d4a ASL |
131 | * |
132 | * @param experiment | |
5d10d135 | 133 | */ |
e31e01e8 | 134 | private void traceSelected(TmfExperiment<LttngEvent> experiment) { |
d712a5f3 | 135 | // TODO: Re-factor when multiple traces are supported |
88144d4a ASL |
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.getExperimentId(); | |
140 | StateManager manager = StateManagerFactory.getManager(experimentId); | |
d712a5f3 FC |
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); | |
5d10d135 ASL |
146 | } |
147 | ||
88144d4a ASL |
148 | /** |
149 | * @return | |
5d10d135 | 150 | */ |
5d10d135 ASL |
151 | public TmfTimeRange getExperimentTimeRange() { |
152 | TmfTimeRange timeRangeResult = null; | |
88144d4a ASL |
153 | if (fExperiment != null) { |
154 | timeRangeResult = fExperiment.getTimeRange(); | |
5d10d135 ASL |
155 | } |
156 | return timeRangeResult; | |
157 | } | |
158 | ||
e31e01e8 | 159 | } |