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