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