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