1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
;
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
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.TraceDebug
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
.DataRequestState
.RequestState
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
23 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
28 * Abstract class used as a base for views handling specific time range data
32 * The class handles a single element queue of data requests, and a list of
33 * requests in progress i.e. request can be triggered from different sources
34 * e.g. opening a file as well as a new selected time window
40 public abstract class AbsTimeUpdateView
extends TmfView
implements
41 IStateDataRequestListener
{
43 // ========================================================================
45 // ========================================================================
46 private DataRequestState reqState
= new DataRequestState();
47 private String viewID
= "";
49 // ========================================================================
51 // ========================================================================
52 public AbsTimeUpdateView(String viewID
) {
56 // ========================================================================
58 // ========================================================================
62 * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener#
63 * processingStarted(org.eclipse.linuxtools.lttng.state.StateDataRequest)
66 public synchronized void processingStarted(RequestStartedSignal signal
) {
67 StateDataRequest request
= signal
.getRequest();
68 if (request
!= null) {
69 // Check if a newer request is in the queue
70 TmfTimeRange newerReq
= reqState
.peekQueued();
71 if (newerReq
== null) {
72 reqState
.setState(DataRequestState
.RequestState
.BUSY
);
73 reqState
.setCurrentRequest(request
);
77 StateManager smanager
= request
.getStateManager();
78 // Clear the children on the Processes related to this
80 // Leave the GUI in charge of the updated data.
81 String traceId
= smanager
.getEventLog().getName();
82 ModelUpdatePrep(traceId
);
84 // clean up any possible pending request
87 // Start the new request.
88 StateManagerFactory
.getExperimentManager()
89 .readExperimentTimeWindow(newerReq
, viewID
, this);
97 * @seeorg.eclipse.linuxtools.lttng.state.IStateDataRequestListener#
98 * processingCompleted(org.eclipse.linuxtools.lttng.state.StateDataRequest)
101 public void processingCompleted(RequestCompletedSignal signal
) {
102 StateDataRequest request
= signal
.getRequest();
104 if (request
== null) {
107 synchronized (this) {
108 reqState
.setCurrentRequest(null);
113 // No data refresh actions for cancelled requests.
114 if (request
.isCancelled() || request
.isFailed()) {
116 requestStateUpdate();
118 if (TraceDebug
.isDEBUG()) {
119 TmfTimeRange trange
= request
.getRange();
120 if (request
.isCancelled()) {
121 TraceDebug
.debug("Request cancelled "
122 + trange
.getStartTime() + "-" + trange
.getEndTime()
123 + " Handled Events: " + request
.getNumOfEvents());
124 } else if (request
.isFailed()) {
125 TraceDebug
.debug("Request Failed " + trange
.getStartTime()
126 + "-" + trange
.getEndTime() + " Handled Events: "
127 + request
.getNumOfEvents());
133 ModelUpdateComplete(request
);
134 requestStateUpdate();
139 * Evaluates the need to either send a new data request or queue the request
140 * till next available opportunity. One element queue to keep the latest
145 public synchronized void dataRequest(TmfTimeRange trange
) {
146 if (trange
!= null) {
147 // cancelPendingRequests();
148 StateDataRequest currentRequest
= reqState
.getCurrentRequest();
149 // If a request is ongoing queue the new request
150 if (reqState
.getState().equals(RequestState
.BUSY
)) {
151 reqState
.setQueued(trange
);
152 currentRequest
= reqState
.getCurrentRequest();
153 if (currentRequest
!= null) {
154 currentRequest
.cancel();
157 // Set the state to busy
158 reqState
.setState(DataRequestState
.RequestState
.BUSY
);
160 // no request is ongoing, proceed with request
161 StateManagerFactory
.getExperimentManager()
162 .readExperimentTimeWindow(trange
, viewID
, this);
169 * Check for pending request an either send a new request or change the
172 private synchronized void requestStateUpdate() {
173 // Check if a new time range update is waiting to be processed
174 TmfTimeRange queuedRequest
= reqState
.popQueued();
175 if (queuedRequest
!= null) {
176 // Trigger the pending request
177 StateManagerFactory
.getExperimentManager()
178 .readExperimentTimeWindow(queuedRequest
, viewID
, this);
180 // All requests cancelled and no more pending requests
181 reqState
.setState(RequestState
.IDLE
);
187 * Request the Time Analysis widget to enable or disable the wait cursor
188 * e.g. data request in progress or data request completed
192 protected abstract void waitCursor(boolean waitInd
);
195 * View preparation to override the current local information related to the
200 public abstract void ModelUpdatePrep(String traceId
);
203 * Actions taken by the view to refresh its widget(s) with the updated data
208 public abstract void ModelUpdateComplete(StateDataRequest request
);