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
, int 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 boolean isCompatible(ITmfDataRequest
<T
> request
) {
166 if (request
instanceof ITmfEventRequest
<?
>) {
167 boolean ok
= super.isCompatible(request
);
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);
173 if (!fRange
.contains(startTime
) && fRange
.getStartTime().compareTo(startTime
) > 0) {
174 fRange
= new TmfTimeRange(startTime
, fRange
.getEndTime());
176 if (!fRange
.contains(endTime
) && fRange
.getEndTime().compareTo(endTime
) < 0) {
177 fRange
= new TmfTimeRange(fRange
.getStartTime(), endTime
);
186 // ------------------------------------------------------------------------
188 // ------------------------------------------------------------------------
191 public void handleData(T data
) {
192 super.handleData(data
);
193 for (ITmfDataRequest
<T
> request
: fRequests
) {
195 request
.handleData(null);
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
);
209 TmfDataRequest
<T
> req
= (TmfDataRequest
<T
>) request
;
210 if (!req
.isCompleted()) {
211 if (req
.getDataType().isInstance(data
)) {
212 req
.handleData(data
);
220 // ------------------------------------------------------------------------
222 // ------------------------------------------------------------------------
225 public TmfTimeRange
getRange() {
230 public void setStartIndex(int index
) {
234 // ------------------------------------------------------------------------
236 // ------------------------------------------------------------------------
239 // All requests have a unique id
240 public int hashCode() {
241 return super.hashCode();
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()));
253 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
254 return super.equals(other
);
260 @SuppressWarnings("nls")
261 public String
toString() {
262 return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
263 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
This page took 0.03561 seconds and 5 git commands to generate.