tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / latency / model / LatencyController.java
CommitLineData
fbd124dd
BH
1/*******************************************************************************
2 * Copyright (c) 2011 Ericsson
0c32e4c5 3 *
fbd124dd
BH
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
0c32e4c5 8 *
fbd124dd
BH
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
638eac44 13package org.eclipse.linuxtools.internal.lttng.ui.views.latency.model;
fbd124dd
BH
14
15import org.eclipse.core.runtime.ListenerList;
fbd124dd
BH
16import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
17import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
fbd124dd 18import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
e0752744
FC
19import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
20import org.eclipse.linuxtools.tmf.ui.views.distribution.model.IBaseDistributionModel;
21import org.eclipse.linuxtools.tmf.ui.views.histogram.IHistogramDataModel;
fbd124dd
BH
22
23/**
24 * <b><u>LatencyController</u></b>
25 * <p>
26 */
27public class LatencyController {
0c32e4c5 28
fbd124dd
BH
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 private static LatencyController fInstance = null;
0c32e4c5 34
fbd124dd 35 private LatencyEventRequest fEventRequest;
0c32e4c5
AM
36
37 private TmfEventProvider fProvider;
38
fbd124dd
BH
39 private final ListenerList fModels;
40
41 // ------------------------------------------------------------------------
42 // Constructor
43 // ------------------------------------------------------------------------
44
45 private LatencyController() {
46 fModels = new ListenerList();
47 }
48
49 // ------------------------------------------------------------------------
50 // Accessors
51 // ------------------------------------------------------------------------
52 public static LatencyController getInstance() {
53 if (fInstance == null) {
54 fInstance = new LatencyController();
55 }
56 return fInstance;
57 }
0c32e4c5 58
fbd124dd
BH
59 // ------------------------------------------------------------------------
60 // Operations
61 // ------------------------------------------------------------------------
62
63 /**
64 * Refresh all registered models
0c32e4c5 65 *
fbd124dd
BH
66 * @param provider - TmfEventProvider to request data from
67 * @param timeRange - time range of request
68 */
0c32e4c5 69 public void refreshModels(TmfEventProvider provider, TmfTimeRange timeRange) {
fbd124dd
BH
70 // save provider
71 fProvider = provider;
72 if (fProvider != null) {
73 if (fEventRequest != null && !fEventRequest.isCompleted()) {
74 fEventRequest.cancel();
75 }
76 clear();
77 fEventRequest = new LatencyEventRequest(this, timeRange, ExecutionType.FOREGROUND);
78 fProvider.sendRequest((TmfDataRequest)fEventRequest);
79 }
80 }
81
82 /**
83 * Refreshes registered models by re-sending previous request to saved provider
84 */
85 public void refreshModels() {
86 if (fProvider != null && fEventRequest != null) {
87 refreshModels(fProvider, fEventRequest.getRange());
88 }
89 }
90
91 /**
92 * Clear all models
93 */
94 public void clear() {
95 Object models[] = fModels.getListeners();
0c32e4c5 96
fbd124dd
BH
97 for (int i = 0; i < models.length; i++) {
98 ((IBaseDistributionModel)models[i]).clear();
99 }
100 }
0c32e4c5 101
fbd124dd
BH
102 /**
103 * Dispose of controller
104 */
105 public void dispose() {
106 if (fEventRequest != null && !fEventRequest.isCompleted()) {
107 fEventRequest.cancel();
108 }
109 fProvider = null;
110 }
0c32e4c5 111
fbd124dd
BH
112 /**
113 * Register given model.
114 * @param model - model to register
115 */
116 public void registerModel(IBaseDistributionModel model) {
117 fModels.add(model);
118 }
0c32e4c5 119
fbd124dd
BH
120 /**
121 * Deregister given model.
0c32e4c5 122 *
fbd124dd
BH
123 * @param model - model to deregister
124 */
125 public void deregisterModel(IBaseDistributionModel model) {
126 fModels.remove(model);
127 }
0c32e4c5 128
fbd124dd
BH
129 /**
130 * Handle data of event request and pass it information to the registered models
0c32e4c5 131 *
fbd124dd
BH
132 * @param eventCount - event count
133 * @param timestamp - start timestamp of latency calculation
134 * @param latency - latency value (startTimestamp - endTimestamp)
135 */
136 public void handleData(int eventCount, long timestamp, long latency) {
137 Object[] models = fModels.getListeners();
138 for (int i = 0; i < models.length; i++) {
139 IBaseDistributionModel model = (IBaseDistributionModel)models[i];
140 if (model instanceof IHistogramDataModel) {
141 ((IHistogramDataModel)model).countEvent(eventCount, latency);
142 } else if (model instanceof IGraphDataModel) {
143 ((IGraphDataModel)model).countEvent(eventCount, timestamp, latency);
144 }
145 }
146 }
147
148 /**
149 * Handle complete indication from request.
150 */
151 public void handleCompleted() {
152 Object[] models = fModels.getListeners();
153 for (int i = 0; i < models.length; i++) {
154 ((IBaseDistributionModel)models[i]).complete();
155 }
156 }
157
158 /**
159 * Handle cancel indication from request.
160 */
161 public void handleCancel() {
162 clear();
163 }
0c32e4c5 164
fbd124dd
BH
165 /**
166 * Set event provider for refresh.
0c32e4c5 167 *
fbd124dd
BH
168 * @param provider
169 */
0c32e4c5 170 public void setEventProvider(TmfEventProvider provider) {
fbd124dd
BH
171 fProvider = provider;
172 }
0c32e4c5 173
fbd124dd
BH
174 /**
175 * Set current event time in model(s).
0c32e4c5 176 *
fbd124dd
BH
177 * @param timestamp
178 */
179 public void setCurrentEventTime(long timestamp) {
180 Object[] models = fModels.getListeners();
181 for (int i = 0; i < models.length; i++) {
182 IBaseDistributionModel model = (IBaseDistributionModel)models[i];
183 if (model instanceof LatencyGraphModel) {
184 ((LatencyGraphModel)model).setCurrentEventNotifyListeners(timestamp);
185 }
186 }
187 }
188}
This page took 0.03625 seconds and 5 git commands to generate.