42fde555fa6a46bafb16eb0bb6860c170afe1761
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.request
;
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 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
25 * The TMF coalesced event request
28 * @author Francois Chouinard
30 public class TmfCoalescedEventRequest
<T
extends ITmfEvent
> extends TmfCoalescedDataRequest
<T
> implements ITmfEventRequest
<T
> {
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private TmfTimeRange fRange
; // The requested events time range
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * Request all the events of a given type (high priority)
44 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
46 * @param dataType the requested data type
48 public TmfCoalescedEventRequest(Class
<T
> dataType
) {
49 this(dataType
, TmfTimeRange
.ETERNITY
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
53 * Request all the events of a given type (given priority)
54 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
56 * @param dataType the requested data type
57 * @param priority the requested execution priority
59 public TmfCoalescedEventRequest(Class
<T
> dataType
, ExecutionType priority
) {
60 this(dataType
, TmfTimeRange
.ETERNITY
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
64 * Request all the events of a given type for the given time range (high priority)
65 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
67 * @param dataType the requested data type
68 * @param range the time range of the requested events
70 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
) {
71 this(dataType
, range
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
75 * Request all the events of a given type for the given time range (given priority)
76 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
78 * @param dataType the requested data type
79 * @param range the time range of the requested events
80 * @param priority the requested execution priority
82 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, ExecutionType priority
) {
83 this(dataType
, range
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
87 * Request 'n' events of a given type from the given time range (high priority)
88 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
90 * @param dataType the requested data type
91 * @param range the time range of the requested events
92 * @param nbRequested the number of events requested
94 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
) {
95 this(dataType
, range
, nbRequested
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
99 * Request 'n' events of a given type for the given time range (given priority)
100 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
102 * @param dataType the requested data type
103 * @param range the time range of the requested events
104 * @param nbRequested the number of events requested
105 * @param priority the requested execution priority
107 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, ExecutionType priority
) {
108 this(dataType
, range
, nbRequested
, DEFAULT_BLOCK_SIZE
, priority
);
112 * Request 'n' events of a given type for the given time range (high priority).
113 * Events are returned in blocks of the given size.
115 * @param dataType the requested data type
116 * @param range the time range of the requested events
117 * @param nbRequested the number of events requested
118 * @param blockSize the number of events per block
120 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
) {
121 this(dataType
, range
, 0, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
125 * Request 'n' events of a given type for the given time range (given priority).
126 * Events are returned in blocks of the given size.
128 * @param dataType the requested data type
129 * @param range the time range of the requested events
130 * @param nbRequested the number of events requested
131 * @param blockSize the number of events per block
132 * @param priority the requested execution priority
134 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType priority
) {
135 this(dataType
, range
, 0, nbRequested
, blockSize
, priority
);
139 * Request 'n' events of a given type for the given time range (given priority).
140 * Events are returned in blocks of the given size.
142 * @param dataType the requested data type
143 * @param range the time range of the requested events
144 * @param index the index of the first event to retrieve
145 * @param nbRequested the number of events requested
146 * @param blockSize the number of events per block
147 * @param priority the requested execution priority
149 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, long index
, int nbRequested
, int blockSize
, ExecutionType priority
) {
150 super(dataType
, index
, nbRequested
, blockSize
, priority
);
153 if (Tracer
.isRequestTraced()) {
154 String type
= getClass().getName();
155 type
= type
.substring(type
.lastIndexOf('.') + 1);
156 @SuppressWarnings("nls")
157 String message
= "CREATED "
158 + (getExecType() == ITmfDataRequest
.ExecutionType
.BACKGROUND ?
"(BG)" : "(FG)")
159 + " Type=" + type
+ " Index=" + getIndex() + " NbReq=" + getNbRequested()
160 + " Range=" + getRange()
161 + " DataType=" + getDataType().getSimpleName();
162 Tracer
.traceRequest(this, message
);
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
171 public void addRequest(ITmfDataRequest
<T
> request
) {
172 super.addRequest(request
);
173 if (request
instanceof ITmfEventRequest
<?
>) {
174 merge((ITmfEventRequest
<T
>) request
);
179 public boolean isCompatible(ITmfDataRequest
<T
> request
) {
180 if (request
instanceof ITmfEventRequest
<?
>) {
181 if (super.isCompatible(request
)) {
182 return overlaps((ITmfEventRequest
<T
>) request
);
188 private boolean overlaps(ITmfEventRequest
<T
> request
) {
189 ITmfTimestamp startTime
= request
.getRange().getStartTime();
190 ITmfTimestamp endTime
= request
.getRange().getEndTime();
191 return (startTime
.compareTo(endTime
) <= 0) && (fRange
.getStartTime().compareTo(fRange
.getEndTime()) <= 0);
194 private void merge(ITmfEventRequest
<T
> request
) {
195 ITmfTimestamp startTime
= request
.getRange().getStartTime();
196 ITmfTimestamp endTime
= request
.getRange().getEndTime();
197 if (!fRange
.contains(startTime
) && fRange
.getStartTime().compareTo(startTime
) > 0) {
198 fRange
= new TmfTimeRange(startTime
, fRange
.getEndTime());
200 if (!fRange
.contains(endTime
) && fRange
.getEndTime().compareTo(endTime
) < 0) {
201 fRange
= new TmfTimeRange(fRange
.getStartTime(), endTime
);
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
210 public void handleData(T data
) {
211 super.handleData(data
);
212 for (ITmfDataRequest
<T
> request
: fRequests
) {
214 request
.handleData(null);
216 if (request
instanceof TmfEventRequest
<?
>) {
217 TmfEventRequest
<T
> req
= (TmfEventRequest
<T
>) request
;
218 if (!req
.isCompleted() && (getNbRead() > request
.getIndex())) {
219 ITmfTimestamp ts
= data
.getTimestamp();
220 if (req
.getRange().contains(ts
)) {
221 if (req
.getDataType().isInstance(data
)) {
222 req
.handleData(data
);
228 TmfDataRequest
<T
> req
= (TmfDataRequest
<T
>) request
;
229 if (!req
.isCompleted()) {
230 if (req
.getDataType().isInstance(data
)) {
231 req
.handleData(data
);
239 // ------------------------------------------------------------------------
241 // ------------------------------------------------------------------------
244 public TmfTimeRange
getRange() {
249 public void setStartIndex(int index
) {
253 // ------------------------------------------------------------------------
255 // ------------------------------------------------------------------------
258 // All requests have a unique id
259 public int hashCode() {
260 return super.hashCode();
264 public boolean equals(Object other
) {
265 if (other
instanceof TmfCoalescedEventRequest
<?
>) {
266 TmfCoalescedEventRequest
<?
> request
= (TmfCoalescedEventRequest
<?
>) other
;
267 return (request
.getDataType() == getDataType()) &&
268 (request
.getIndex() == getIndex()) &&
269 (request
.getNbRequested() == getNbRequested()) &&
270 (request
.getRange().equals(getRange()));
272 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
273 return super.equals(other
);
279 @SuppressWarnings("nls")
280 public String
toString() {
281 return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
282 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
This page took 0.035471 seconds and 4 git commands to generate.