Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
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 | ||
2fb2eb37 | 30 | protected Vector<ITmfDataRequest<T>> fRequests = new Vector<ITmfDataRequest<T>>(); |
8c8bf09f ASL |
31 | |
32 | // ------------------------------------------------------------------------ | |
33 | // Constructor | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | /** | |
37 | * Default constructor | |
38 | */ | |
39 | public TmfCoalescedDataRequest(Class<T> dataType) { | |
f6b14ce2 | 40 | this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
cb866e08 FC |
41 | } |
42 | ||
43 | public TmfCoalescedDataRequest(Class<T> dataType, ExecutionType execType) { | |
44 | this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, execType); | |
8c8bf09f ASL |
45 | } |
46 | ||
47 | /** | |
48 | * @param nbRequested | |
49 | */ | |
50 | public TmfCoalescedDataRequest(Class<T> dataType, int index) { | |
f6b14ce2 | 51 | this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
cb866e08 FC |
52 | } |
53 | ||
54 | public TmfCoalescedDataRequest(Class<T> dataType, int index, ExecutionType execType) { | |
55 | this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, execType); | |
8c8bf09f ASL |
56 | } |
57 | ||
58 | /** | |
59 | * @param index | |
60 | * @param nbRequested | |
61 | */ | |
62 | public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested) { | |
f6b14ce2 | 63 | this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
cb866e08 FC |
64 | } |
65 | ||
66 | public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, ExecutionType execType) { | |
67 | this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, execType); | |
8c8bf09f ASL |
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) { | |
f6b14ce2 | 76 | super(dataType, index, nbRequested, blockSize, ExecutionType.FOREGROUND); |
cb866e08 FC |
77 | } |
78 | ||
79 | public TmfCoalescedDataRequest(Class<T> dataType, int index, int nbRequested, int blockSize, ExecutionType execType) { | |
80 | super(dataType, index, nbRequested, blockSize, execType); | |
8c8bf09f ASL |
81 | } |
82 | ||
83 | // ------------------------------------------------------------------------ | |
84 | // Management | |
85 | // ------------------------------------------------------------------------ | |
86 | ||
2fb2eb37 | 87 | public void addRequest(ITmfDataRequest<T> request) { |
8c8bf09f ASL |
88 | fRequests.add(request); |
89 | } | |
90 | ||
f9673903 | 91 | public boolean isCompatible(ITmfDataRequest<T> request) { |
8c8bf09f | 92 | |
f9673903 FC |
93 | boolean ok = request.getIndex() == getIndex(); |
94 | ok &= request.getNbRequested() == getNbRequested(); | |
95 | ok &= request.getExecType() == getExecType(); | |
8c8bf09f ASL |
96 | |
97 | return ok; | |
98 | } | |
99 | ||
100 | // ------------------------------------------------------------------------ | |
101 | // ITmfDataRequest | |
102 | // ------------------------------------------------------------------------ | |
103 | ||
104 | @Override | |
f9673903 FC |
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 | } | |
8c8bf09f ASL |
115 | } |
116 | ||
f9673903 FC |
117 | @Override |
118 | public void done() { | |
2fb2eb37 FC |
119 | for (ITmfDataRequest<T> request : fRequests) { |
120 | request.done(); | |
8c8bf09f | 121 | } |
2fb2eb37 | 122 | super.done(); |
8c8bf09f ASL |
123 | } |
124 | ||
125 | @Override | |
f9673903 | 126 | public void fail() { |
2fb2eb37 FC |
127 | for (ITmfDataRequest<T> request : fRequests) { |
128 | request.fail(); | |
8c8bf09f | 129 | } |
2fb2eb37 | 130 | super.fail(); |
8c8bf09f ASL |
131 | } |
132 | ||
133 | @Override | |
f9673903 | 134 | public void cancel() { |
2fb2eb37 FC |
135 | for (ITmfDataRequest<T> request : fRequests) { |
136 | request.cancel(); | |
8c8bf09f | 137 | } |
2fb2eb37 | 138 | super.cancel(); |
8c8bf09f ASL |
139 | } |
140 | ||
2fb2eb37 FC |
141 | // ------------------------------------------------------------------------ |
142 | // Object | |
143 | // ------------------------------------------------------------------------ | |
8c8bf09f ASL |
144 | |
145 | @Override | |
2fb2eb37 FC |
146 | // All requests have a unique id |
147 | public int hashCode() { | |
148 | return super.hashCode(); | |
8c8bf09f ASL |
149 | } |
150 | ||
151 | @Override | |
2fb2eb37 FC |
152 | public boolean equals(Object other) { |
153 | if (other instanceof TmfCoalescedDataRequest<?>) { | |
154 | TmfCoalescedDataRequest<?> request = (TmfCoalescedDataRequest<?>) other; | |
cb866e08 FC |
155 | return (request.getDataType() == getDataType()) && |
156 | (request.getIndex() == getIndex()) && | |
157 | (request.getNbRequested() == getNbRequested() && | |
158 | (request.getExecType() == getExecType())); | |
2fb2eb37 FC |
159 | } |
160 | return false; | |
8c8bf09f ASL |
161 | } |
162 | ||
163 | @Override | |
2fb2eb37 FC |
164 | public String toString() { |
165 | return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName() | |
f9673903 | 166 | + "," + getIndex() + "," + getNbRequested() + ")]"; |
8c8bf09f ASL |
167 | } |
168 | ||
169 | } |