Fix a pile of Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / request / TmfCoalescedEventRequest.java
CommitLineData
8c8bf09f
ASL
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
9b749023 3 *
8c8bf09f
ASL
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
9b749023 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
8fd82db5 13package org.eclipse.linuxtools.internal.tmf.core.request;
8c8bf09f 14
4cf201de 15import org.eclipse.linuxtools.internal.tmf.core.Tracer;
72f1e62a 16import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
4df4581d 17import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b 18import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
8fd82db5
FC
19import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
20import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
21import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
22import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
8c8bf09f
ASL
23
24/**
8fd82db5 25 * The TMF coalesced event request
9b749023 26 *
0283f7ff
FC
27 * @param <T> The request event type
28 *
8fd82db5
FC
29 * @version 1.0
30 * @author Francois Chouinard
8c8bf09f 31 */
72f1e62a 32public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedDataRequest<T> implements ITmfEventRequest<T> {
8c8bf09f
ASL
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
550d787e 38 private TmfTimeRange fRange; // The requested events time range
8c8bf09f
ASL
39
40 // ------------------------------------------------------------------------
41 // Constructor
42 // ------------------------------------------------------------------------
43
44 /**
0d9a6d76
FC
45 * Request all the events of a given type (high priority)
46 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 47 *
0d9a6d76 48 * @param dataType the requested data type
8c8bf09f
ASL
49 */
50 public TmfCoalescedEventRequest(Class<T> dataType) {
a4115405 51 this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
cb866e08
FC
52 }
53
0d9a6d76
FC
54 /**
55 * Request all the events of a given type (given priority)
56 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 57 *
0d9a6d76
FC
58 * @param dataType the requested data type
59 * @param priority the requested execution priority
60 */
61 public TmfCoalescedEventRequest(Class<T> dataType, ExecutionType priority) {
62 this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
8c8bf09f
ASL
63 }
64
65 /**
0d9a6d76
FC
66 * Request all the events of a given type for the given time range (high priority)
67 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 68 *
0d9a6d76
FC
69 * @param dataType the requested data type
70 * @param range the time range of the requested events
8c8bf09f
ASL
71 */
72 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range) {
f6b14ce2 73 this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
cb866e08
FC
74 }
75
0d9a6d76
FC
76 /**
77 * Request all the events of a given type for the given time range (given priority)
78 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 79 *
0d9a6d76
FC
80 * @param dataType the requested data type
81 * @param range the time range of the requested events
82 * @param priority the requested execution priority
83 */
84 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, ExecutionType priority) {
85 this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
8c8bf09f
ASL
86 }
87
88 /**
0d9a6d76
FC
89 * Request 'n' events of a given type from the given time range (high priority)
90 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 91 *
0d9a6d76
FC
92 * @param dataType the requested data type
93 * @param range the time range of the requested events
94 * @param nbRequested the number of events requested
8c8bf09f
ASL
95 */
96 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested) {
f6b14ce2 97 this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
cb866e08 98 }
0d9a6d76
FC
99
100 /**
101 * Request 'n' events of a given type for the given time range (given priority)
102 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
9b749023 103 *
0d9a6d76
FC
104 * @param dataType the requested data type
105 * @param range the time range of the requested events
106 * @param nbRequested the number of events requested
107 * @param priority the requested execution priority
108 */
109 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) {
110 this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, priority);
8c8bf09f 111 }
0d9a6d76 112
8c8bf09f 113 /**
0d9a6d76
FC
114 * Request 'n' events of a given type for the given time range (high priority).
115 * Events are returned in blocks of the given size.
9b749023 116 *
0d9a6d76
FC
117 * @param dataType the requested data type
118 * @param range the time range of the requested events
119 * @param nbRequested the number of events requested
120 * @param blockSize the number of events per block
8c8bf09f
ASL
121 */
122 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize) {
4cf201de 123 this(dataType, range, 0, nbRequested, blockSize, ExecutionType.FOREGROUND);
cb866e08
FC
124 }
125
0d9a6d76
FC
126 /**
127 * Request 'n' events of a given type for the given time range (given priority).
128 * Events are returned in blocks of the given size.
9b749023 129 *
0d9a6d76
FC
130 * @param dataType the requested data type
131 * @param range the time range of the requested events
132 * @param nbRequested the number of events requested
133 * @param blockSize the number of events per block
134 * @param priority the requested execution priority
135 */
136 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) {
4cf201de 137 this(dataType, range, 0, nbRequested, blockSize, priority);
8c8bf09f
ASL
138 }
139
0d9a6d76
FC
140 /**
141 * Request 'n' events of a given type for the given time range (given priority).
142 * Events are returned in blocks of the given size.
9b749023 143 *
0d9a6d76
FC
144 * @param dataType the requested data type
145 * @param range the time range of the requested events
146 * @param index the index of the first event to retrieve
147 * @param nbRequested the number of events requested
148 * @param blockSize the number of events per block
149 * @param priority the requested execution priority
150 */
9e0640dc 151 public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
0d9a6d76
FC
152 super(dataType, index, nbRequested, blockSize, priority);
153 fRange = range;
4cf201de
FC
154
155 if (Tracer.isRequestTraced()) {
156 String type = getClass().getName();
157 type = type.substring(type.lastIndexOf('.') + 1);
158 @SuppressWarnings("nls")
9b749023
AM
159 String message = "CREATED "
160 + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)")
161 + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested()
4cf201de
FC
162 + " Range=" + getRange()
163 + " DataType=" + getDataType().getSimpleName();
164 Tracer.traceRequest(this, message);
165 }
a79913eb
FC
166 }
167
8c8bf09f
ASL
168 // ------------------------------------------------------------------------
169 // Management
170 // ------------------------------------------------------------------------
171
923b8517
FC
172 @Override
173 public void addRequest(ITmfDataRequest<T> request) {
174 super.addRequest(request);
175 if (request instanceof ITmfEventRequest<?>) {
176 merge((ITmfEventRequest<T>) request);
177 }
178 }
179
8c8bf09f 180 @Override
2fb2eb37 181 public boolean isCompatible(ITmfDataRequest<T> request) {
4cf201de 182 if (request instanceof ITmfEventRequest<?>) {
923b8517
FC
183 if (super.isCompatible(request)) {
184 return overlaps((ITmfEventRequest<T>) request);
4cf201de 185 }
4cf201de
FC
186 }
187 return false;
8c8bf09f
ASL
188 }
189
923b8517 190 private boolean overlaps(ITmfEventRequest<T> request) {
9b749023
AM
191 ITmfTimestamp startTime = request.getRange().getStartTime();
192 ITmfTimestamp endTime = request.getRange().getEndTime();
923b8517
FC
193 return (startTime.compareTo(endTime) <= 0) && (fRange.getStartTime().compareTo(fRange.getEndTime()) <= 0);
194 }
195
196 private void merge(ITmfEventRequest<T> request) {
9b749023
AM
197 ITmfTimestamp startTime = request.getRange().getStartTime();
198 ITmfTimestamp endTime = request.getRange().getEndTime();
923b8517
FC
199 if (!fRange.contains(startTime) && fRange.getStartTime().compareTo(startTime) > 0) {
200 fRange = new TmfTimeRange(startTime, fRange.getEndTime());
201 }
202 if (!fRange.contains(endTime) && fRange.getEndTime().compareTo(endTime) < 0) {
203 fRange = new TmfTimeRange(fRange.getStartTime(), endTime);
204 }
205 }
206
550d787e
FC
207 // ------------------------------------------------------------------------
208 // ITmfDataRequest
209 // ------------------------------------------------------------------------
210
211 @Override
1b70b6dc
PT
212 public void handleData(T data) {
213 super.handleData(data);
c02a7bea 214 long index = getIndex() + getNbRead() - 1;
1b70b6dc
PT
215 for (ITmfDataRequest<T> request : fRequests) {
216 if (data == null) {
217 request.handleData(null);
218 } else {
c02a7bea
PT
219 long start = request.getIndex();
220 long end = start + request.getNbRequested();
1b70b6dc
PT
221 if (request instanceof TmfEventRequest<?>) {
222 TmfEventRequest<T> req = (TmfEventRequest<T>) request;
c02a7bea 223 if (!req.isCompleted() && index >= start && index < end) {
dfee01ae 224 ITmfTimestamp ts = data.getTimestamp();
1b70b6dc
PT
225 if (req.getRange().contains(ts)) {
226 if (req.getDataType().isInstance(data)) {
227 req.handleData(data);
228 }
229 }
230 }
231 }
232 else {
233 TmfDataRequest<T> req = (TmfDataRequest<T>) request;
c02a7bea 234 if (!req.isCompleted() && index >= start && index < end) {
1b70b6dc
PT
235 if (req.getDataType().isInstance(data)) {
236 req.handleData(data);
237 }
238 }
239 }
240 }
241 }
550d787e
FC
242 }
243
8c8bf09f
ASL
244 // ------------------------------------------------------------------------
245 // ITmfEventRequest
246 // ------------------------------------------------------------------------
247
d4011df2 248 @Override
8c8bf09f
ASL
249 public TmfTimeRange getRange() {
250 return fRange;
251 }
9b749023 252
a79913eb
FC
253 @Override
254 public void setStartIndex(int index) {
255 setIndex(index);
256 }
9b749023 257
2fb2eb37
FC
258 // ------------------------------------------------------------------------
259 // Object
260 // ------------------------------------------------------------------------
261
262 @Override
263 // All requests have a unique id
264 public int hashCode() {
265 return super.hashCode();
266 }
267
268 @Override
269 public boolean equals(Object other) {
270 if (other instanceof TmfCoalescedEventRequest<?>) {
271 TmfCoalescedEventRequest<?> request = (TmfCoalescedEventRequest<?>) other;
272 return (request.getDataType() == getDataType()) &&
273 (request.getIndex() == getIndex()) &&
274 (request.getNbRequested() == getNbRequested()) &&
275 (request.getRange().equals(getRange()));
276 }
277 if (other instanceof TmfCoalescedDataRequest<?>) {
278 return super.equals(other);
279 }
280 return false;
281 }
282
283 @Override
3b38ea61 284 @SuppressWarnings("nls")
2fb2eb37 285 public String toString() {
9b749023 286 return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
a79913eb 287 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
2fb2eb37
FC
288 }
289
8c8bf09f 290}
This page took 0.053967 seconds and 5 git commands to generate.