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 java
.util
.Vector
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
20 * <b><u>TmfCoalescedDataRequest</u></b>
23 public class TmfCoalescedDataRequest
<T
extends ITmfEvent
> extends TmfDataRequest
<T
> {
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
30 * The list of coalesced requests
32 protected Vector
<ITmfDataRequest
<T
>> fRequests
= new Vector
<ITmfDataRequest
<T
>>();
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 * Request all the events of a given type (high priority)
40 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
42 * @param dataType the requested data type
44 public TmfCoalescedDataRequest(Class
<T
> dataType
) {
45 this(dataType
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
49 * Request all the events of a given type (given priority)
50 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
52 * @param dataType the requested data type
53 * @param priority the requested execution priority
55 public TmfCoalescedDataRequest(Class
<T
> dataType
, ExecutionType priority
) {
56 this(dataType
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
60 * Request all the events of a given type from the given index (high priority)
61 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
63 * @param dataType the requested data type
64 * @param index the index of the first event to retrieve
66 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
) {
67 this(dataType
, index
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
71 * Request all the events of a given type from the given index (given priority)
72 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
74 * @param dataType the requested data type
75 * @param index the index of the first event to retrieve
76 * @param priority the requested execution priority
78 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, ExecutionType priority
) {
79 this(dataType
, index
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
83 * Request 'n' events of a given type from the given index (high priority)
84 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
86 * @param dataType the requested data type
87 * @param index the index of the first event to retrieve
88 * @param nbRequested the number of events requested
90 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
) {
91 this(dataType
, index
, nbRequested
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
95 * Request 'n' events of a given type from the given index (given priority)
96 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
98 * @param dataType the requested data type
99 * @param index the index of the first event to retrieve
100 * @param nbRequested the number of events requested
101 * @param priority the requested execution priority
103 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, ExecutionType priority
) {
104 this(dataType
, index
, nbRequested
, DEFAULT_BLOCK_SIZE
, priority
);
108 * Request 'n' events of a given type from the given index (high priority).
109 * Events are returned in blocks of the given size.
111 * @param dataType the requested data type
112 * @param index the index of the first event to retrieve
113 * @param nbRequested the number of events requested
114 * @param blockSize the number of events per block
116 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, int blockSize
) {
117 super(dataType
, index
, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
121 * Request 'n' events of a given type from the given index (given priority).
122 * Events are returned in blocks of the given size.
124 * @param dataType the requested data type
125 * @param index the index of the first event to retrieve
126 * @param nbRequested the number of events requested
127 * @param blockSize the number of events per block
128 * @param priority the requested execution priority
130 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, int blockSize
, ExecutionType priority
) {
131 super(dataType
, index
, nbRequested
, blockSize
, priority
);
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
138 public void addRequest(ITmfDataRequest
<T
> request
) {
139 fRequests
.add(request
);
142 public boolean isCompatible(ITmfDataRequest
<T
> request
) {
144 boolean ok
= request
.getIndex() == getIndex();
145 ok
&= request
.getNbRequested() == getNbRequested();
146 ok
&= request
.getExecType() == getExecType();
151 @SuppressWarnings("nls")
152 public String
getSubRequestIds() {
153 StringBuffer result
= new StringBuffer("[");
154 for (int i
= 0; i
< fRequests
.size(); i
++) {
155 if (i
!= 0) result
.append(", ");
156 result
.append(fRequests
.get(i
).getRequestId());
159 return result
.toString();
162 // ------------------------------------------------------------------------
164 // ------------------------------------------------------------------------
167 public void handleData(T data
) {
168 super.handleData(data
);
169 // Don't call sub-requests handleData() unless this is a
170 // TmfCoalescedDataRequest; extended classes should call
171 // the sub-requests handleData().
172 if (getClass() == TmfCoalescedDataRequest
.class) {
173 for (ITmfDataRequest
<T
> request
: fRequests
) {
174 if (!request
.isCompleted()) {
175 if (request
.getDataType().isInstance(data
)) {
176 request
.handleData(data
);
184 public void start() {
185 for (ITmfDataRequest
<T
> request
: fRequests
) {
186 if (!request
.isCompleted()) {
195 for (ITmfDataRequest
<T
> request
: fRequests
) {
196 if (!request
.isCompleted()) {
205 for (ITmfDataRequest
<T
> request
: fRequests
) {
212 public void cancel() {
213 for (ITmfDataRequest
<T
> request
: fRequests
) {
214 if (!request
.isCompleted()) {
222 public boolean isCompleted() {
223 // Firstly, check if coalescing request is completed
224 if (super.isCompleted()) {
228 // Secondly, check if all sub-requests are finished
229 if (fRequests
.size() > 0) {
230 // If all sub requests are completed the coalesced request is
231 // treated as completed, too.
232 for (ITmfDataRequest
<T
> request
: fRequests
) {
233 if (!request
.isCompleted()) {
240 // Coalescing request is not finished if there are no sub-requests
245 public boolean isCancelled() {
246 // Firstly, check if coalescing request is canceled
247 if (super.isCancelled()) {
251 // Secondly, check if all sub-requests are canceled
252 if (fRequests
.size() > 0) {
253 // If all sub requests are canceled the coalesced request is
254 // treated as completed, too.
255 for (ITmfDataRequest
<T
> request
: fRequests
) {
256 if (!request
.isCancelled()) {
263 // Coalescing request is not canceled if there are no sub-requests
269 // ------------------------------------------------------------------------
271 // ------------------------------------------------------------------------
274 // All requests have a unique id
275 public int hashCode() {
276 return super.hashCode();
280 public boolean equals(Object other
) {
281 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
282 TmfCoalescedDataRequest
<?
> request
= (TmfCoalescedDataRequest
<?
>) other
;
283 return (request
.getDataType() == getDataType()) &&
284 (request
.getIndex() == getIndex()) &&
285 (request
.getNbRequested() == getNbRequested() &&
286 (request
.getExecType() == getExecType()));
292 @SuppressWarnings("nls")
293 public String
toString() {
294 return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
295 + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
This page took 0.036651 seconds and 5 git commands to generate.