Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
8035003b | 2 | * Copyright (c) 2009 Ericsson |
6e512b93 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.ui.views.common; | |
13 | ||
8035003b ASL |
14 | import org.eclipse.linuxtools.lttng.state.IStateDataRequestListener; |
15 | import org.eclipse.linuxtools.lttng.state.RequestCompletedSignal; | |
16 | import org.eclipse.linuxtools.lttng.state.RequestStartedSignal; | |
17 | import org.eclipse.linuxtools.lttng.state.StateDataRequest; | |
18 | import org.eclipse.linuxtools.lttng.state.StateManager; | |
19 | import org.eclipse.linuxtools.lttng.state.experiment.StateManagerFactory; | |
6e512b93 | 20 | import org.eclipse.linuxtools.lttng.ui.TraceDebug; |
41dc35d0 | 21 | import org.eclipse.linuxtools.lttng.ui.views.common.DataRequestState.RequestState; |
6e512b93 | 22 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
63eecb47 | 23 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
6e512b93 | 24 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
6e512b93 | 25 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
6e512b93 ASL |
26 | |
27 | /** | |
28 | * <p> | |
29 | * Abstract class used as a base for views handling specific time range data | |
30 | * requests | |
31 | * </p> | |
32 | * <p> | |
8035003b ASL |
33 | * The class handles a single element queue of data requests, and a list of |
34 | * requests in progress i.e. request can be triggered from different sources | |
35 | * e.g. opening a file as well as a new selected time window | |
6e512b93 ASL |
36 | * </p> |
37 | * | |
38 | * @author alvaro | |
39 | * | |
40 | */ | |
41 | public abstract class AbsTimeUpdateView extends TmfView implements | |
8035003b | 42 | IStateDataRequestListener { |
6e512b93 ASL |
43 | |
44 | // ======================================================================== | |
45 | // Data | |
46 | // ======================================================================== | |
41dc35d0 | 47 | private DataRequestState reqState = new DataRequestState(); |
8035003b | 48 | private String viewID = ""; |
6e512b93 ASL |
49 | |
50 | // ======================================================================== | |
51 | // Constructor | |
52 | // ======================================================================== | |
53 | public AbsTimeUpdateView(String viewID) { | |
8035003b | 54 | this.viewID = viewID; |
6e512b93 ASL |
55 | } |
56 | ||
57 | // ======================================================================== | |
58 | // Methods | |
59 | // ======================================================================== | |
60 | /* | |
61 | * (non-Javadoc) | |
62 | * | |
63 | * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener# | |
64 | * processingStarted(org.eclipse.linuxtools.lttng.state.StateDataRequest) | |
65 | */ | |
66 | @TmfSignalHandler | |
67 | public synchronized void processingStarted(RequestStartedSignal signal) { | |
8035003b | 68 | StateDataRequest request = signal.getRequest(); |
6e512b93 | 69 | if (request != null) { |
41dc35d0 FC |
70 | // Check if a newer request is in the queue |
71 | TmfTimeRange newerReq = reqState.peekQueued(); | |
72 | if (newerReq == null) { | |
73 | reqState.setState(DataRequestState.RequestState.BUSY); | |
74 | reqState.setCurrentRequest(request); | |
75 | ||
76 | waitCursor(true); | |
77 | ||
78 | StateManager smanager = request.getStateManager(); | |
79 | // Clear the children on the Processes related to this | |
80 | // manager. | |
81 | // Leave the GUI in charge of the updated data. | |
82 | String traceId = smanager.getEventLog().getName(); | |
83 | ModelUpdatePrep(traceId); | |
84 | } else { | |
85 | // clean up any possible pending request | |
86 | request.cancel(); | |
87 | ||
88 | // Start the new request. | |
89 | StateManagerFactory.getExperimentManager() | |
90 | .readExperimentTimeWindow(newerReq, viewID, this); | |
8035003b | 91 | } |
6e512b93 ASL |
92 | } |
93 | } | |
94 | ||
95 | /* | |
96 | * (non-Javadoc) | |
97 | * | |
98 | * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener# | |
99 | * processingCompleted(org.eclipse.linuxtools.lttng.state.StateDataRequest) | |
100 | */ | |
101 | @TmfSignalHandler | |
63eecb47 | 102 | public synchronized void processingCompleted(RequestCompletedSignal signal) { |
8035003b | 103 | StateDataRequest request = signal.getRequest(); |
6e512b93 ASL |
104 | |
105 | if (request == null) { | |
106 | return; | |
8035003b | 107 | } else { |
63eecb47 | 108 | reqState.setCurrentRequest(null); |
6e512b93 | 109 | |
8035003b | 110 | } |
6e512b93 ASL |
111 | |
112 | // No data refresh actions for cancelled requests. | |
113 | if (request.isCancelled() || request.isFailed()) { | |
41dc35d0 FC |
114 | |
115 | requestStateUpdate(); | |
116 | ||
6e512b93 ASL |
117 | if (TraceDebug.isDEBUG()) { |
118 | TmfTimeRange trange = request.getRange(); | |
119 | if (request.isCancelled()) { | |
120 | TraceDebug.debug("Request cancelled " | |
121 | + trange.getStartTime() + "-" + trange.getEndTime() | |
8035003b | 122 | + " Handled Events: " + request.getNumOfEvents()); |
6e512b93 ASL |
123 | } else if (request.isFailed()) { |
124 | TraceDebug.debug("Request Failed " + trange.getStartTime() | |
125 | + "-" + trange.getEndTime() + " Handled Events: " | |
8035003b | 126 | + request.getNumOfEvents()); |
6e512b93 ASL |
127 | } |
128 | } | |
129 | ||
130 | return; | |
131 | } else { | |
8035003b | 132 | ModelUpdateComplete(request); |
41dc35d0 | 133 | requestStateUpdate(); |
6e512b93 ASL |
134 | } |
135 | } | |
136 | ||
137 | /** | |
8035003b ASL |
138 | * Evaluates the need to either send a new data request or queue the request |
139 | * till next available opportunity. One element queue to keep the latest | |
140 | * request only. | |
6e512b93 | 141 | * |
8035003b | 142 | * @param trange |
6e512b93 | 143 | */ |
8035003b | 144 | public synchronized void dataRequest(TmfTimeRange trange) { |
41dc35d0 FC |
145 | if (trange != null) { |
146 | // cancelPendingRequests(); | |
147 | StateDataRequest currentRequest = reqState.getCurrentRequest(); | |
148 | // If a request is ongoing queue the new request | |
149 | if (reqState.getState().equals(RequestState.BUSY)) { | |
150 | reqState.setQueued(trange); | |
151 | currentRequest = reqState.getCurrentRequest(); | |
152 | if (currentRequest != null) { | |
153 | currentRequest.cancel(); | |
63eecb47 FC |
154 | } else { |
155 | TraceDebug | |
156 | .debug("Exception : State busy but current request is null"); | |
41dc35d0 FC |
157 | } |
158 | } else { | |
159 | // Set the state to busy | |
160 | reqState.setState(DataRequestState.RequestState.BUSY); | |
161 | waitCursor(true); | |
63eecb47 FC |
162 | if (TraceDebug.isDEBUG()) { |
163 | TraceDebug | |
164 | .debug("Requesting data: " + trange.getStartTime() | |
165 | + "-" + trange.getEndTime()); | |
166 | } | |
41dc35d0 FC |
167 | // no request is ongoing, proceed with request |
168 | StateManagerFactory.getExperimentManager() | |
169 | .readExperimentTimeWindow(trange, viewID, this); | |
6e512b93 | 170 | |
41dc35d0 | 171 | } |
6e512b93 ASL |
172 | } |
173 | } | |
174 | ||
175 | /** | |
41dc35d0 FC |
176 | * Check for pending request an either send a new request or change the |
177 | * state to idle | |
6e512b93 | 178 | */ |
8035003b | 179 | private synchronized void requestStateUpdate() { |
41dc35d0 FC |
180 | // Check if a new time range update is waiting to be processed |
181 | TmfTimeRange queuedRequest = reqState.popQueued(); | |
182 | if (queuedRequest != null) { | |
183 | // Trigger the pending request | |
63eecb47 FC |
184 | if (TraceDebug.isDEBUG()) { |
185 | TmfTimestamp start = queuedRequest.getStartTime(); | |
186 | TmfTimestamp end = queuedRequest.getEndTime(); | |
187 | TraceDebug.debug("New request about to start: " + start + "-" | |
188 | + end); | |
189 | } | |
190 | ||
41dc35d0 FC |
191 | StateManagerFactory.getExperimentManager() |
192 | .readExperimentTimeWindow(queuedRequest, viewID, this); | |
193 | } else { | |
194 | // All requests cancelled and no more pending requests | |
63eecb47 | 195 | TraceDebug.debug("No requests pending in the queue"); |
41dc35d0 | 196 | reqState.setState(RequestState.IDLE); |
8035003b | 197 | waitCursor(false); |
6e512b93 | 198 | } |
6e512b93 ASL |
199 | } |
200 | ||
201 | /** | |
202 | * Request the Time Analysis widget to enable or disable the wait cursor | |
203 | * e.g. data request in progress or data request completed | |
204 | * | |
205 | * @param waitInd | |
206 | */ | |
8035003b | 207 | protected abstract void waitCursor(boolean waitInd); |
6e512b93 ASL |
208 | |
209 | /** | |
8035003b ASL |
210 | * View preparation to override the current local information related to the |
211 | * given traceId | |
6e512b93 | 212 | * |
8035003b | 213 | * @param traceId |
6e512b93 | 214 | */ |
41dc35d0 | 215 | public abstract void ModelUpdatePrep(String traceId); |
6e512b93 ASL |
216 | |
217 | /** | |
218 | * Actions taken by the view to refresh its widget(s) with the updated data | |
219 | * model | |
220 | * | |
221 | * @param request | |
6e512b93 | 222 | */ |
8035003b | 223 | public abstract void ModelUpdateComplete(StateDataRequest request); |
6e512b93 | 224 | } |