2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / request / LttngSyntEventRequest.java
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
56 this(range, offset, nbEvents, maxBlockSize, listener, experimentTimeRange, processor, ExecutionType.FOREGROUND);
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);
71 fExperimentTimeRange = experimentTimeRange;
72 addListener(listener);
73
74 fprocessor = processor;
75 }
76
77 /**
78 * @param listener
79 */
80 public void addListener(IRequestStatusListener listener) {
81 if (listener != null && !listeners.contains(listener)) {
82 listeners.add(listener);
83 }
84 }
85
86 /**
87 * @param listener
88 */
89 public void removeListner(IRequestStatusListener listener) {
90 if (listener != null) {
91 listeners.remove(listener);
92 }
93 }
94
95 // ========================================================================
96 // Methods
97 // =======================================================================
98 /* (non-Javadoc)
99 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#startRequestInd(org.eclipse.linuxtools.tmf.experiment.TmfExperiment, boolean)
100 */
101 @Override
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 @Override
111 public void notifyCompletion() {
112 // Notify specific state views
113 for (IRequestStatusListener listener : listeners) {
114 listener.processingCompleted(new RequestCompletedSignal(this));
115 }
116 }
117
118 /* (non-Javadoc)
119 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#notifyStarting()
120 */
121 @Override
122 public void notifyStarting() {
123 for (IRequestStatusListener listener : listeners) {
124 listener.processingStarted(new RequestStartedSignal(this));
125 }
126 }
127
128 /* (non-Javadoc)
129 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#getExperimentTimeRange()
130 */
131 @Override
132 public TmfTimeRange getExperimentTimeRange() {
133 return fExperimentTimeRange;
134 }
135
136 /*
137 * (non-Javadoc)
138 *
139 * @see
140 * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#setSynEventCount
141 * (java.lang.Long)
142 */
143 @Override
144 public synchronized void setSynEventCount(Long numOfEvents) {
145 this.feventCount = numOfEvents;
146 }
147
148 /*
149 * (non-Javadoc)
150 *
151 * @see
152 * org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest#getEventCount
153 * ()
154 */
155 @Override
156 public synchronized Long getSynEventCount() {
157 return feventCount;
158 }
159
160 /* (non-Javadoc)
161 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#setclearDataInd(boolean)
162 */
163 @Override
164 public void setclearDataInd(boolean clearAllData) {
165 this.clearDataInd = clearAllData;
166 }
167
168 /* (non-Javadoc)
169 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#isclearDataInd()
170 */
171 @Override
172 public boolean isclearDataInd() {
173 return clearDataInd;
174 }
175
176 /* (non-Javadoc)
177 * @see org.eclipse.linuxtools.lttng.request.ILttngEventRequest#handleData()
178 */
179 @Override
180 public void handleData(LttngSyntheticEvent event) {
181 super.handleData(event);
182 }
183
184
185 /*
186 * (non-Javadoc)
187 *
188 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleCompleted()
189 */
190 @Override
191 public void handleCompleted() {
192 // notify listeners
193 notifyCompletion();
194 super.handleCompleted();
195 }
196
197 /**
198 * @return the source
199 */
200 @Override
201 public Object getSource() {
202 return fsource;
203 }
204
205 /**
206 * @param source
207 */
208 @Override
209 public void setSource(Object source) {
210 this.fsource = source;
211 }
212
213 /**
214 * @return the event processor associated to this request
215 */
216 public ITransEventProcessor getProcessor() {
217 return fprocessor;
218 }
219 }
This page took 0.038621 seconds and 5 git commands to generate.