5d1ad858f4b69f6d8a334c3310d609ed35e1d7eb
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();
147 //ok &= request.getDataType() == getDataType();
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
157 public void handleData(T data
) {
158 super.handleData(data
);
159 // Don't call sub-requests handleData() unless this is a
160 // TmfCoalescedDataRequest; extended classes should call
161 // the sub-requests handleData().
162 if (getClass() == TmfCoalescedDataRequest
.class) {
163 for (ITmfDataRequest
<T
> request
: fRequests
) {
164 if (!request
.isCompleted()) {
165 if (request
.getDataType().isInstance(data
)) {
166 request
.handleData(data
);
174 public void start() {
175 for (ITmfDataRequest
<T
> request
: fRequests
) {
176 if (!request
.isCompleted()) {
185 for (ITmfDataRequest
<T
> request
: fRequests
) {
186 if (!request
.isCompleted()) {
195 for (ITmfDataRequest
<T
> request
: fRequests
) {
202 public void cancel() {
203 for (ITmfDataRequest
<T
> request
: fRequests
) {
204 if (!request
.isCompleted()) {
212 public boolean isCompleted() {
213 // Firstly, check if coalescing request is completed
214 if (super.isCompleted()) {
218 // Secondly, check if all sub-requests are finished
219 if (fRequests
.size() > 0) {
220 // If all sub requests are completed the coalesced request is
221 // treated as completed, too.
222 for (ITmfDataRequest
<T
> request
: fRequests
) {
223 if (!request
.isCompleted()) {
230 // Coalescing request is not finished if there are no sub-requests
235 public boolean isCancelled() {
236 // Firstly, check if coalescing request is canceled
237 if (super.isCancelled()) {
241 // Secondly, check if all sub-requests are canceled
242 if (fRequests
.size() > 0) {
243 // If all sub requests are canceled the coalesced request is
244 // treated as completed, too.
245 for (ITmfDataRequest
<T
> request
: fRequests
) {
246 if (!request
.isCancelled()) {
253 // Coalescing request is not canceled if there are no sub-requests
259 // ------------------------------------------------------------------------
261 // ------------------------------------------------------------------------
264 // All requests have a unique id
265 public int hashCode() {
266 return super.hashCode();
270 public boolean equals(Object other
) {
271 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
272 TmfCoalescedDataRequest
<?
> request
= (TmfCoalescedDataRequest
<?
>) other
;
273 return (request
.getDataType() == getDataType()) &&
274 (request
.getIndex() == getIndex()) &&
275 (request
.getNbRequested() == getNbRequested() &&
276 (request
.getExecType() == getExecType()));
282 @SuppressWarnings("nls")
283 public String
toString() {
284 return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
285 + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
This page took 0.047318 seconds and 5 git commands to generate.