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