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 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.request; |
8c8bf09f | 14 | |
90891c08 | 15 | import org.eclipse.linuxtools.internal.tmf.core.Tracer; |
72f1e62a | 16 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
6c13869b | 17 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
8c8bf09f ASL |
18 | |
19 | /** | |
20 | * <b><u>TmfEventRequest</u></b> | |
21 | * <p> | |
22 | * Implement me. Please. | |
23 | */ | |
72f1e62a | 24 | public abstract class TmfEventRequest<T extends ITmfEvent> extends TmfDataRequest<T> implements ITmfEventRequest<T> { |
8c8bf09f ASL |
25 | |
26 | // ------------------------------------------------------------------------ | |
27 | // Attributes | |
28 | // ------------------------------------------------------------------------ | |
29 | ||
30 | private final TmfTimeRange fRange; // The requested events time range | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Constructors | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | /** | |
0d9a6d76 FC |
37 | * Request all the events of a given type (high priority) |
38 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
39 | * | |
40 | * @param dataType the requested data type | |
8c8bf09f | 41 | */ |
951d134a | 42 | public TmfEventRequest(Class<T> dataType) { |
a4115405 | 43 | this(dataType, TmfTimeRange.ETERNITY, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
550d787e FC |
44 | } |
45 | ||
0d9a6d76 FC |
46 | /** |
47 | * Request all the events of a given type (given priority) | |
48 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
49 | * | |
50 | * @param dataType the requested data type | |
51 | * @param priority the requested execution priority | |
52 | */ | |
53 | public TmfEventRequest(Class<T> dataType, ExecutionType priority) { | |
54 | this(dataType, TmfTimeRange.ETERNITY, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, priority); | |
8c8bf09f ASL |
55 | } |
56 | ||
57 | /** | |
0d9a6d76 FC |
58 | * Request all the events of a given type for the given time range (high priority) |
59 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
60 | * | |
61 | * @param dataType the requested data type | |
62 | * @param range the time range of the requested events | |
8c8bf09f | 63 | */ |
951d134a | 64 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range) { |
a79913eb | 65 | this(dataType, range, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
550d787e FC |
66 | } |
67 | ||
0d9a6d76 FC |
68 | /** |
69 | * Request all the events of a given type for the given time range (given priority) | |
70 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
71 | * | |
72 | * @param dataType the requested data type | |
73 | * @param range the time range of the requested events | |
74 | * @param priority the requested execution priority | |
75 | */ | |
76 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, ExecutionType priority) { | |
77 | this(dataType, range, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, priority); | |
8c8bf09f ASL |
78 | } |
79 | ||
80 | /** | |
0d9a6d76 FC |
81 | * Request 'n' events of a given type from the given time range (high priority) |
82 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
83 | * | |
84 | * @param dataType the requested data type | |
85 | * @param range the time range of the requested events | |
86 | * @param nbRequested the number of events requested | |
8c8bf09f | 87 | */ |
951d134a | 88 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested) { |
a79913eb | 89 | this(dataType, range, 0, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND); |
550d787e FC |
90 | } |
91 | ||
0d9a6d76 FC |
92 | /** |
93 | * Request 'n' events of a given type for the given time range (given priority) | |
94 | * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE). | |
95 | * | |
96 | * @param dataType the requested data type | |
97 | * @param range the time range of the requested events | |
98 | * @param nbRequested the number of events requested | |
99 | * @param priority the requested execution priority | |
100 | */ | |
101 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) { | |
102 | this(dataType, range, 0, nbRequested, DEFAULT_BLOCK_SIZE, priority); | |
8c8bf09f ASL |
103 | } |
104 | ||
105 | /** | |
0d9a6d76 FC |
106 | * Request 'n' events of a given type for the given time range (high priority). |
107 | * Events are returned in blocks of the given size. | |
108 | * | |
109 | * @param dataType the requested data type | |
110 | * @param range the time range of the requested events | |
111 | * @param nbRequested the number of events requested | |
112 | * @param blockSize the number of events per block | |
8c8bf09f | 113 | */ |
951d134a | 114 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize) { |
a79913eb | 115 | this(dataType, range, 0, nbRequested, blockSize, ExecutionType.FOREGROUND); |
550d787e FC |
116 | } |
117 | ||
7e6347b0 FC |
118 | /** |
119 | * Request 'n' events of a given type for the given time range (high priority). | |
120 | * Events are returned in blocks of the given size. | |
121 | * | |
122 | * @param dataType the requested data type | |
123 | * @param range the time range of the requested events | |
124 | * @param index the index of the first event to retrieve | |
125 | * @param nbRequested the number of events requested | |
126 | * @param blockSize the number of events per block | |
127 | */ | |
128 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int index, int nbRequested, int blockSize) { | |
129 | this(dataType, range, index, nbRequested, blockSize, ExecutionType.FOREGROUND); | |
130 | } | |
131 | ||
0d9a6d76 FC |
132 | /** |
133 | * Request 'n' events of a given type for the given time range (given priority). | |
134 | * Events are returned in blocks of the given size. | |
135 | * | |
136 | * @param dataType the requested data type | |
137 | * @param range the time range of the requested events | |
138 | * @param nbRequested the number of events requested | |
139 | * @param blockSize the number of events per block | |
140 | * @param priority the requested execution priority | |
141 | */ | |
142 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) { | |
143 | this(dataType, range, 0, nbRequested, blockSize, priority); | |
a79913eb FC |
144 | } |
145 | ||
0d9a6d76 FC |
146 | /** |
147 | * Request 'n' events of a given type for the given time range (given priority). | |
148 | * Events are returned in blocks of the given size. | |
149 | * | |
150 | * @param dataType the requested data type | |
151 | * @param range the time range of the requested events | |
152 | * @param index the index of the first event to retrieve | |
153 | * @param nbRequested the number of events requested | |
154 | * @param blockSize the number of events per block | |
155 | * @param priority the requested execution priority | |
156 | */ | |
157 | public TmfEventRequest(Class<T> dataType, TmfTimeRange range, int index, int nbRequested, int blockSize, ExecutionType priority) { | |
158 | super(dataType, index, nbRequested, blockSize, priority); | |
8c8bf09f | 159 | fRange = range; |
90891c08 FC |
160 | |
161 | if (Tracer.isRequestTraced()) { | |
162 | String type = getClass().getName(); | |
163 | type = type.substring(type.lastIndexOf('.') + 1); | |
164 | @SuppressWarnings("nls") | |
165 | String message = "CREATED " | |
166 | + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)") | |
4cf201de FC |
167 | + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested() |
168 | + " Range=" + getRange() | |
90891c08 FC |
169 | + " DataType=" + getDataType().getSimpleName(); |
170 | Tracer.traceRequest(this, message); | |
171 | } | |
8c8bf09f ASL |
172 | } |
173 | ||
174 | // ------------------------------------------------------------------------ | |
175 | // Accessors | |
176 | // ------------------------------------------------------------------------ | |
177 | ||
178 | /** | |
179 | * @return the requested time range | |
180 | */ | |
d4011df2 FC |
181 | @Override |
182 | public TmfTimeRange getRange() { | |
8c8bf09f ASL |
183 | return fRange; |
184 | } | |
185 | ||
a79913eb FC |
186 | // ------------------------------------------------------------------------ |
187 | // Setters | |
188 | // ------------------------------------------------------------------------ | |
189 | ||
190 | /** | |
191 | * this method is called by the event provider to set the index corresponding | |
192 | * to the time range start time once it is known | |
0d9a6d76 FC |
193 | * |
194 | * @param index the start index | |
a79913eb FC |
195 | */ |
196 | @Override | |
197 | public void setStartIndex(int index) { | |
198 | setIndex(index); | |
199 | } | |
200 | ||
2fb2eb37 FC |
201 | // ------------------------------------------------------------------------ |
202 | // Object | |
203 | // ------------------------------------------------------------------------ | |
204 | ||
205 | @Override | |
206 | // All requests have a unique id | |
207 | public int hashCode() { | |
208 | return getRequestId(); | |
209 | } | |
210 | ||
211 | @Override | |
212 | public boolean equals(Object other) { | |
213 | if (other instanceof TmfEventRequest<?>) { | |
214 | TmfEventRequest<?> request = (TmfEventRequest<?>) other; | |
215 | return super.equals(other) && request.fRange.equals(fRange); | |
216 | } | |
217 | return false; | |
218 | } | |
219 | ||
220 | @Override | |
3b38ea61 | 221 | @SuppressWarnings("nls") |
2fb2eb37 FC |
222 | public String toString() { |
223 | return "[TmfEventRequest(" + getRequestId() + "," + getDataType().getSimpleName() | |
a79913eb | 224 | + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]"; |
2fb2eb37 FC |
225 | } |
226 | ||
8c8bf09f | 227 | } |