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
.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
;
21 * <b><u>TmfCoalescedEventRequest</u></b>
24 public class TmfCoalescedEventRequest
<T
extends ITmfEvent
> extends TmfCoalescedDataRequest
<T
> implements ITmfEventRequest
<T
> {
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 private TmfTimeRange fRange
; // The requested events time range
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
37 * Request all the events of a given type (high priority)
38 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
40 * @param dataType the requested data type
42 public TmfCoalescedEventRequest(Class
<T
> dataType
) {
43 this(dataType
, TmfTimeRange
.ETERNITY
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
47 * Request all the events of a given type (given priority)
48 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
50 * @param dataType the requested data type
51 * @param priority the requested execution priority
53 public TmfCoalescedEventRequest(Class
<T
> dataType
, ExecutionType priority
) {
54 this(dataType
, TmfTimeRange
.ETERNITY
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
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).
61 * @param dataType the requested data type
62 * @param range the time range of the requested events
64 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
) {
65 this(dataType
, range
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
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).
72 * @param dataType the requested data type
73 * @param range the time range of the requested events
74 * @param priority the requested execution priority
76 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, ExecutionType priority
) {
77 this(dataType
, range
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
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).
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
88 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
) {
89 this(dataType
, range
, nbRequested
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
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).
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
101 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, ExecutionType priority
) {
102 this(dataType
, range
, nbRequested
, DEFAULT_BLOCK_SIZE
, priority
);
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.
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
114 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
) {
115 this(dataType
, range
, 0, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
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.
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
128 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType priority
) {
129 this(dataType
, range
, 0, nbRequested
, blockSize
, priority
);
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.
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
143 public TmfCoalescedEventRequest(Class
<T
> dataType
, TmfTimeRange range
, long index
, int nbRequested
, int blockSize
, ExecutionType priority
) {
144 super(dataType
, index
, nbRequested
, blockSize
, priority
);
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
);
160 // ------------------------------------------------------------------------
162 // ------------------------------------------------------------------------
165 public void addRequest(ITmfDataRequest
<T
> request
) {
166 super.addRequest(request
);
167 if (request
instanceof ITmfEventRequest
<?
>) {
168 merge((ITmfEventRequest
<T
>) request
);
173 public boolean isCompatible(ITmfDataRequest
<T
> request
) {
174 if (request
instanceof ITmfEventRequest
<?
>) {
175 if (super.isCompatible(request
)) {
176 return overlaps((ITmfEventRequest
<T
>) request
);
182 private boolean overlaps(ITmfEventRequest
<T
> request
) {
183 ITmfTimestamp startTime
= ((ITmfEventRequest
<T
>) request
).getRange().getStartTime();
184 ITmfTimestamp endTime
= ((ITmfEventRequest
<T
>) request
).getRange().getEndTime();
185 return (startTime
.compareTo(endTime
) <= 0) && (fRange
.getStartTime().compareTo(fRange
.getEndTime()) <= 0);
188 private void merge(ITmfEventRequest
<T
> request
) {
189 ITmfTimestamp startTime
= ((ITmfEventRequest
<T
>) request
).getRange().getStartTime();
190 ITmfTimestamp endTime
= ((ITmfEventRequest
<T
>) request
).getRange().getEndTime();
191 if (!fRange
.contains(startTime
) && fRange
.getStartTime().compareTo(startTime
) > 0) {
192 fRange
= new TmfTimeRange(startTime
, fRange
.getEndTime());
194 if (!fRange
.contains(endTime
) && fRange
.getEndTime().compareTo(endTime
) < 0) {
195 fRange
= new TmfTimeRange(fRange
.getStartTime(), endTime
);
199 // ------------------------------------------------------------------------
201 // ------------------------------------------------------------------------
204 public void handleData(T data
) {
205 super.handleData(data
);
206 for (ITmfDataRequest
<T
> request
: fRequests
) {
208 request
.handleData(null);
210 if (request
instanceof TmfEventRequest
<?
>) {
211 TmfEventRequest
<T
> req
= (TmfEventRequest
<T
>) request
;
212 if (!req
.isCompleted() && (getNbRead() > request
.getIndex())) {
213 ITmfTimestamp ts
= data
.getTimestamp();
214 if (req
.getRange().contains(ts
)) {
215 if (req
.getDataType().isInstance(data
)) {
216 req
.handleData(data
);
222 TmfDataRequest
<T
> req
= (TmfDataRequest
<T
>) request
;
223 if (!req
.isCompleted()) {
224 if (req
.getDataType().isInstance(data
)) {
225 req
.handleData(data
);
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
238 public TmfTimeRange
getRange() {
243 public void setStartIndex(int index
) {
247 // ------------------------------------------------------------------------
249 // ------------------------------------------------------------------------
252 // All requests have a unique id
253 public int hashCode() {
254 return super.hashCode();
258 public boolean equals(Object other
) {
259 if (other
instanceof TmfCoalescedEventRequest
<?
>) {
260 TmfCoalescedEventRequest
<?
> request
= (TmfCoalescedEventRequest
<?
>) other
;
261 return (request
.getDataType() == getDataType()) &&
262 (request
.getIndex() == getIndex()) &&
263 (request
.getNbRequested() == getNbRequested()) &&
264 (request
.getRange().equals(getRange()));
266 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
267 return super.equals(other
);
273 @SuppressWarnings("nls")
274 public String
toString() {
275 return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
276 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
This page took 0.037449 seconds and 5 git commands to generate.