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