Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 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.request; | |
13 | ||
14 | import java.util.Vector; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent; | |
17 | import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor; | |
18 | import org.eclipse.linuxtools.tmf.component.TmfEventProvider; | |
19 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
20 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
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 | */ | |
29 | public class LttngSyntEventRequest extends TmfEventRequest<LttngSyntheticEvent> | |
30 | implements ILttngSyntEventRequest { | |
31 | ||
32 | // ======================================================================== | |
33 | // Data | |
34 | // ======================================================================= | |
35 | private Vector<IRequestStatusListener> listeners = new Vector<IRequestStatusListener>(); | |
36 | private Long feventCount = 0L; | |
37 | private boolean clearDataInd = false; | |
38 | private TmfTimeRange fExperimentTimeRange = null; | |
39 | private Object fsource = null; | |
40 | private final ITransEventProcessor fprocessor; | |
41 | ||
42 | // ======================================================================== | |
43 | // Constructors | |
44 | // ======================================================================= | |
45 | /** | |
46 | * @param range | |
47 | * @param offset | |
48 | * @param nbEvents | |
49 | * @param maxBlockSize | |
50 | * @param listener | |
51 | */ | |
52 | public LttngSyntEventRequest(TmfTimeRange range, long offset, int nbEvents, | |
53 | int maxBlockSize, IRequestStatusListener listener, | |
54 | TmfTimeRange experimentTimeRange, ITransEventProcessor processor) { | |
55 | ||
9b635e61 FC |
56 | this(range, offset, nbEvents, maxBlockSize, listener, experimentTimeRange, processor, ExecutionType.SHORT); |
57 | } | |
58 | ||
59 | /** | |
60 | * @param range | |
61 | * @param offset | |
62 | * @param nbEvents | |
63 | * @param maxBlockSize | |
64 | * @param listener | |
65 | */ | |
66 | public LttngSyntEventRequest(TmfTimeRange range, long offset, int nbEvents, | |
67 | int maxBlockSize, IRequestStatusListener listener, | |
68 | TmfTimeRange experimentTimeRange, ITransEventProcessor processor, ExecutionType execType) { | |
69 | ||
70 | super(LttngSyntheticEvent.class, range, nbEvents, maxBlockSize, execType); | |
5d10d135 ASL |
71 | //super(0, nbEvents, maxBlockSize); |
72 | fExperimentTimeRange = experimentTimeRange; | |
73 | addListener(listener); | |
74 | ||
75 | fprocessor = processor; | |
76 | } | |
77 | ||
78 | /** | |
79 | * @param listener | |
80 | */ | |
81 | public void addListener(IRequestStatusListener listener) { | |
82 | if (listener != null && !listeners.contains(listener)) { | |
83 | listeners.add(listener); | |
84 | } | |
85 | } | |
86 | ||
87 | /** | |
88 | * @param listener | |
89 | */ | |
90 | public void removeListner(IRequestStatusListener listener) { | |
91 | if (listener != null) { | |
92 | listeners.remove(listener); | |
93 | } | |
94 | } | |
95 | ||
96 | // ======================================================================== | |
97 | // Methods | |
98 | // ======================================================================= | |
99 | /* (non-Javadoc) | |
100 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#startRequestInd(org.eclipse.linuxtools.tmf.experiment.TmfExperiment, boolean) | |
101 | */ | |
102 | public void startRequestInd(TmfEventProvider<LttngSyntheticEvent> provider) { | |
103 | // trigger the start to process this request | |
104 | provider.sendRequest(this); | |
105 | } | |
106 | ||
107 | /* (non-Javadoc) | |
108 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#notifyCompletion() | |
109 | */ | |
110 | public void notifyCompletion() { | |
111 | // Notify specific state views | |
112 | for (IRequestStatusListener listener : listeners) { | |
113 | listener.processingCompleted(new RequestCompletedSignal(this)); | |
114 | } | |
115 | } | |
116 | ||
117 | /* (non-Javadoc) | |
118 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#notifyStarting() | |
119 | */ | |
120 | public void notifyStarting() { | |
121 | for (IRequestStatusListener listener : listeners) { | |
122 | listener.processingStarted(new RequestStartedSignal(this)); | |
123 | } | |
124 | } | |
125 | ||
126 | /* (non-Javadoc) | |
127 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#getExperimentTimeRange() | |
128 | */ | |
129 | public TmfTimeRange getExperimentTimeRange() { | |
130 | return fExperimentTimeRange; | |
131 | } | |
132 | ||
133 | /* | |
134 | * (non-Javadoc) | |
135 | * | |
136 | * @see | |
137 | * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#setSynEventCount | |
138 | * (java.lang.Long) | |
139 | */ | |
140 | public synchronized void setSynEventCount(Long numOfEvents) { | |
141 | this.feventCount = numOfEvents; | |
142 | } | |
143 | ||
144 | /* | |
145 | * (non-Javadoc) | |
146 | * | |
147 | * @see | |
148 | * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#getEventCount | |
149 | * () | |
150 | */ | |
550d787e | 151 | public synchronized Long getSynEventCount() { |
5d10d135 ASL |
152 | return feventCount; |
153 | } | |
154 | ||
155 | /* (non-Javadoc) | |
156 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#setclearDataInd(boolean) | |
157 | */ | |
158 | public void setclearDataInd(boolean clearAllData) { | |
159 | this.clearDataInd = clearAllData; | |
160 | } | |
161 | ||
162 | /* (non-Javadoc) | |
163 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#isclearDataInd() | |
164 | */ | |
165 | public boolean isclearDataInd() { | |
166 | return clearDataInd; | |
167 | } | |
168 | ||
169 | /* (non-Javadoc) | |
170 | * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#handleData() | |
171 | */ | |
172 | @Override | |
173 | public void handleData() { | |
174 | } | |
175 | ||
176 | ||
177 | /* | |
178 | * (non-Javadoc) | |
179 | * | |
180 | * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleCompleted() | |
181 | */ | |
550d787e | 182 | @Override |
5d10d135 ASL |
183 | public void handleCompleted() { |
184 | // notify listeners | |
185 | notifyCompletion(); | |
186 | super.handleCompleted(); | |
187 | } | |
188 | ||
189 | /** | |
190 | * @return the source | |
191 | */ | |
192 | public Object getSource() { | |
193 | return fsource; | |
194 | } | |
195 | ||
196 | /** | |
197 | * @param source | |
198 | */ | |
199 | public void setSource(Object source) { | |
200 | this.fsource = source; | |
201 | } | |
202 | ||
203 | /** | |
204 | * @return the event processor associated to this request | |
205 | */ | |
206 | public ITransEventProcessor getProcessor() { | |
207 | return fprocessor; | |
208 | } | |
209 | } |