Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
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; | |
13 | ||
88144d4a ASL |
14 | import java.util.Vector; |
15 | ||
e31e01e8 | 16 | import org.eclipse.linuxtools.lttng.event.LttngEvent; |
88144d4a | 17 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
e31e01e8 FC |
18 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
19 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
88144d4a | 20 | import org.eclipse.linuxtools.tmf.signal.TmfSignalManager; |
5d10d135 ASL |
21 | |
22 | /** | |
23 | * This class is an extension of Data Request which includes specific references | |
24 | * i.e. a status listener to indicate the start and end of the request | |
25 | * | |
26 | * @author alvaro | |
27 | * | |
28 | */ | |
e31e01e8 FC |
29 | public class StateDataRequest extends TmfEventRequest<LttngEvent> { |
30 | ||
5d10d135 | 31 | // ======================================================================== |
88144d4a | 32 | // Data |
5d10d135 | 33 | // ======================================================================= |
88144d4a ASL |
34 | private Vector<IStateDataRequestListener> listeners = new Vector<IStateDataRequestListener>(); |
35 | private String transactionId = ""; /* optional user's attribute */ | |
36 | private StateManager manager = null; | |
37 | private long numOfEvents = 0; | |
38 | private boolean broadcast = false; | |
d712a5f3 | 39 | private boolean clearDataInd = false; |
e31e01e8 | 40 | |
5d10d135 | 41 | // ======================================================================== |
88144d4a | 42 | // Constructors |
5d10d135 | 43 | // ======================================================================= |
88144d4a ASL |
44 | /** |
45 | * @param range | |
46 | * @param offset | |
47 | * @param nbEvents | |
48 | * @param maxBlockSize | |
49 | * @param listener | |
50 | */ | |
51 | public StateDataRequest(TmfTimeRange range, long offset, int nbEvents, | |
52 | int maxBlockSize, IStateDataRequestListener listener, | |
53 | StateManager manager) { | |
28b94d61 | 54 | |
e31e01e8 | 55 | super(LttngEvent.class, range, nbEvents, maxBlockSize); |
28b94d61 | 56 | //super(0, nbEvents, maxBlockSize); |
88144d4a ASL |
57 | this.manager = manager; |
58 | if (listener != null && !listeners.contains(listener)) { | |
59 | listeners.add(listener); | |
60 | } | |
61 | } | |
62 | ||
63 | /** | |
64 | * @param range | |
65 | * @param offset | |
66 | * @param nbEvents | |
67 | * @param maxBlockSize | |
68 | * @param listener | |
69 | * @param transactionID | |
70 | * optional use by user application | |
71 | */ | |
72 | public StateDataRequest(TmfTimeRange range, long offset, int nbEvents, | |
73 | int maxBlockSize, IStateDataRequestListener listener, | |
74 | String transactionID, StateManager manager) { | |
75 | ||
76 | this(range, offset, nbEvents, maxBlockSize, listener, manager); | |
77 | this.transactionId = transactionID; | |
78 | } | |
79 | ||
5d10d135 | 80 | // ======================================================================== |
88144d4a | 81 | // Methods |
5d10d135 | 82 | // ======================================================================= |
88144d4a ASL |
83 | |
84 | /** | |
85 | * Trigger the start to process this request right after the notification to | |
86 | * the interested listeners | |
87 | * | |
88 | * @param experiment | |
89 | * @param broadcast | |
90 | * true: All views, false: only to registered listeners | |
91 | */ | |
951d134a | 92 | public void startRequestInd(TmfExperiment<LttngEvent> experiment, boolean broadcast) { |
88144d4a ASL |
93 | if (broadcast) { |
94 | // Notify all state views. | |
95 | this.broadcast = broadcast; | |
96 | TmfSignalManager.dispatchSignal(new RequestStartedSignal(this)); | |
97 | } else { | |
98 | // Notify specific state views | |
99 | for (IStateDataRequestListener listener : listeners) { | |
100 | listener.processingStarted(new RequestStartedSignal(this)); | |
101 | } | |
102 | } | |
103 | ||
104 | // trigger the start to process this request | |
951d134a | 105 | experiment.sendRequest(this); |
88144d4a ASL |
106 | } |
107 | ||
108 | /** | |
109 | * to be called by the handleCompletion in superclass method, notifies the | |
110 | * interested listeners. i.e. if the request start indicated broadcast, the | |
111 | * completion will also be broadcasted otherwise only registered listeners | |
112 | * will be notified. | |
113 | */ | |
114 | public void notifyCompletion() { | |
115 | if (broadcast) { | |
116 | // Notify all state views. | |
117 | TmfSignalManager.dispatchSignal(new RequestCompletedSignal(this)); | |
118 | } else { | |
119 | // Notify specific state views | |
120 | for (IStateDataRequestListener listener : listeners) { | |
121 | listener.processingCompleted(new RequestCompletedSignal(this)); | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | public void notifyStarting() { | |
127 | for (IStateDataRequestListener listener : listeners) { | |
128 | listener.processingStarted(new RequestStartedSignal(this)); | |
129 | } | |
130 | } | |
131 | ||
132 | public String getTransactionId() { | |
133 | return transactionId; | |
134 | } | |
135 | ||
136 | public StateManager getStateManager() { | |
137 | return this.manager; | |
138 | } | |
139 | ||
140 | // public IStateDataRequestListener getListener() { | |
141 | // return listener; | |
5d10d135 | 142 | // } |
88144d4a ASL |
143 | |
144 | public void addListener(IStateDataRequestListener listener) { | |
145 | if (!listeners.contains(listener)) { | |
146 | listeners.add(listener); | |
147 | } | |
148 | } | |
149 | ||
150 | public void removeListener(IStateDataRequestListener listener) { | |
151 | if (listener != null) { | |
152 | listeners.remove(listener); | |
153 | } | |
154 | } | |
155 | ||
156 | /** | |
157 | * @param numOfEvents | |
158 | * the numOfEvents to set | |
159 | */ | |
160 | public void setNumOfEvents(long numOfEvents) { | |
161 | this.numOfEvents = numOfEvents; | |
162 | } | |
163 | ||
164 | /** | |
165 | * @return the numOfEvents | |
166 | */ | |
167 | public long getNumOfEvents() { | |
168 | return numOfEvents; | |
169 | } | |
d712a5f3 FC |
170 | |
171 | /** | |
172 | * @param clearAllData | |
173 | * indicates the need to clear all previous data e.g. a new | |
174 | * experiment selection | |
175 | */ | |
176 | public void setclearDataInd(boolean clearAllData) { | |
177 | this.clearDataInd = clearAllData; | |
178 | } | |
179 | ||
180 | /** | |
181 | * Returns indication - clearing of all existing data model is required e.g | |
182 | * from the selection of a new experiment | |
183 | * | |
184 | * @return | |
185 | */ | |
186 | public boolean isclearDataInd() { | |
187 | return clearDataInd; | |
188 | } | |
951d134a FC |
189 | |
190 | @Override | |
191 | public void handleData() { | |
192 | } | |
e31e01e8 | 193 | } |