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
.request
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfData
;
20 * <b><u>TmfCoalescedDataRequest</u></b>
22 * TODO: Implement me. Please.
24 public class TmfCoalescedDataRequest
<T
extends TmfData
> extends TmfDataRequest
<T
> {
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 protected Vector
<ITmfDataRequest
<T
>> fRequests
= new Vector
<ITmfDataRequest
<T
>>();
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
39 public TmfCoalescedDataRequest(Class
<T
> dataType
) {
40 this(dataType
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
43 public TmfCoalescedDataRequest(Class
<T
> dataType
, ExecutionType execType
) {
44 this(dataType
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, execType
);
50 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
) {
51 this(dataType
, index
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
54 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, ExecutionType execType
) {
55 this(dataType
, index
, ALL_DATA
, DEFAULT_BLOCK_SIZE
, execType
);
62 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
) {
63 this(dataType
, index
, nbRequested
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
66 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, ExecutionType execType
) {
67 this(dataType
, index
, nbRequested
, DEFAULT_BLOCK_SIZE
, execType
);
75 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, int blockSize
) {
76 super(dataType
, index
, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
79 public TmfCoalescedDataRequest(Class
<T
> dataType
, int index
, int nbRequested
, int blockSize
, ExecutionType execType
) {
80 super(dataType
, index
, nbRequested
, blockSize
, execType
);
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
87 public void addRequest(ITmfDataRequest
<T
> request
) {
88 fRequests
.add(request
);
91 public boolean isCompatible(ITmfDataRequest
<T
> request
) {
93 boolean ok
= request
.getIndex() == getIndex();
94 ok
&= request
.getNbRequested() == getNbRequested();
95 ok
&= request
.getExecType() == getExecType();
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public void handleData(T data
) {
106 super.handleData(data
);
107 // Don't call sub-requests handleData() unless this is a
108 // TmfCoalescedDataRequest; extended classes should call
109 // the sub-requests handleData().
110 if (getClass() == TmfCoalescedDataRequest
.class) {
111 for (ITmfDataRequest
<T
> request
: fRequests
) {
112 if (!request
.isCompleted()) {
113 request
.handleData(data
);
120 public void start() {
121 for (ITmfDataRequest
<T
> request
: fRequests
) {
122 if (!request
.isCompleted()) {
131 for (ITmfDataRequest
<T
> request
: fRequests
) {
132 if (!request
.isCompleted()) {
141 for (ITmfDataRequest
<T
> request
: fRequests
) {
148 public void cancel() {
149 for (ITmfDataRequest
<T
> request
: fRequests
) {
150 if (!request
.isCompleted()) {
158 public boolean isCompleted() {
159 // Firstly, check if coalescing request is completed
160 if (super.isCompleted()) {
164 // Secondly, check if all sub-requests are finished
165 if (fRequests
.size() > 0) {
166 // If all sub requests are completed the coalesced request is
167 // treated as completed, too.
168 for (ITmfDataRequest
<T
> request
: fRequests
) {
169 if (!request
.isCompleted()) {
176 // Coalescing request is not finished if there are no sub-requests
181 public boolean isCancelled() {
182 // Firstly, check if coalescing request is canceled
183 if (super.isCancelled()) {
187 // Secondly, check if all sub-requests are canceled
188 if (fRequests
.size() > 0) {
189 // If all sub requests are canceled the coalesced request is
190 // treated as completed, too.
191 for (ITmfDataRequest
<T
> request
: fRequests
) {
192 if (!request
.isCancelled()) {
199 // Coalescing request is not canceled if there are no sub-requests
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
210 // All requests have a unique id
211 public int hashCode() {
212 return super.hashCode();
216 public boolean equals(Object other
) {
217 if (other
instanceof TmfCoalescedDataRequest
<?
>) {
218 TmfCoalescedDataRequest
<?
> request
= (TmfCoalescedDataRequest
<?
>) other
;
219 return (request
.getDataType() == getDataType()) &&
220 (request
.getIndex() == getIndex()) &&
221 (request
.getNbRequested() == getNbRequested() &&
222 (request
.getExecType() == getExecType()));
228 public String
toString() {
229 return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
230 + "," + getIndex() + "," + getNbRequested() + ")]";
This page took 0.03715 seconds and 5 git commands to generate.