2010-09-17 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug325662
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / request / TmfCoalescedDataRequest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.request;
14
15 import java.util.Vector;
16
17 import org.eclipse.linuxtools.tmf.event.TmfData;
18
19 /**
20 * <b><u>TmfCoalescedDataRequest</u></b>
21 * <p>
22 * TODO: Implement me. Please.
23 */
24 public class TmfCoalescedDataRequest<T extends TmfData> extends TmfDataRequest<T> {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 protected Vector<ITmfDataRequest<T>> fRequests = new Vector<ITmfDataRequest<T>>();
31
32 // ------------------------------------------------------------------------
33 // Constructor
34 // ------------------------------------------------------------------------
35
36 /**
37 * Default constructor
38 */
39 public TmfCoalescedDataRequest(Class<T> dataType) {
40 this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
41 }
42
43 public TmfCoalescedDataRequest(Class<T> dataType, ExecutionType execType) {
44 this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, execType);
45 }
46
47 /**
48 * @param nbRequested
49 */
50 public TmfCoalescedDataRequest(Class<T> dataType, int index) {
51 this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
52 }
53
54 public TmfCoalescedDataRequest(Class<T> dataType, int index, ExecutionType execType) {
55 this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, execType);
56 }
57
58 /**
59 * @param index
60 * @param nbRequested
61 */
62 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested) {
63 this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
64 }
65
66 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, ExecutionType execType) {
67 this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, execType);
68 }
69
70 /**
71 * @param index
72 * @param nbRequested
73 * @param blockSize
74 */
75 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize) {
76 super(dataType, index, nbRequested, blockSize, ExecutionType.FOREGROUND);
77 }
78
79 public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize, ExecutionType execType) {
80 super(dataType, index, nbRequested, blockSize, execType);
81 }
82
83 // ------------------------------------------------------------------------
84 // Management
85 // ------------------------------------------------------------------------
86
87 public void addRequest(ITmfDataRequest<T> request) {
88 fRequests.add(request);
89 }
90
91 public boolean isCompatible(ITmfDataRequest<T> request) {
92
93 boolean ok = request.getIndex() == getIndex();
94 ok &= request.getNbRequested() == getNbRequested();
95 ok &= request.getExecType() == getExecType();
96
97 return ok;
98 }
99
100 // ------------------------------------------------------------------------
101 // ITmfDataRequest
102 // ------------------------------------------------------------------------
103
104 @Override
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 request.handleData(data);
113 }
114 }
115 }
116
117 @Override
118 public void done() {
119 for (ITmfDataRequest<T> request : fRequests) {
120 request.done();
121 }
122 super.done();
123 }
124
125 @Override
126 public void fail() {
127 for (ITmfDataRequest<T> request : fRequests) {
128 request.fail();
129 }
130 super.fail();
131 }
132
133 @Override
134 public void cancel() {
135 for (ITmfDataRequest<T> request : fRequests) {
136 request.cancel();
137 }
138 super.cancel();
139 }
140
141 // ------------------------------------------------------------------------
142 // Object
143 // ------------------------------------------------------------------------
144
145 @Override
146 // All requests have a unique id
147 public int hashCode() {
148 return super.hashCode();
149 }
150
151 @Override
152 public boolean equals(Object other) {
153 if (other instanceof TmfCoalescedDataRequest<?>) {
154 TmfCoalescedDataRequest<?> request = (TmfCoalescedDataRequest<?>) other;
155 return (request.getDataType() == getDataType()) &&
156 (request.getIndex() == getIndex()) &&
157 (request.getNbRequested() == getNbRequested() &&
158 (request.getExecType() == getExecType()));
159 }
160 return false;
161 }
162
163 @Override
164 public String toString() {
165 return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
166 + "," + getIndex() + "," + getNbRequested() + ")]";
167 }
168
169 }
This page took 0.034851 seconds and 5 git commands to generate.