1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.request
;
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
;
20 * An extension of TmfDataRequest for timestamped events.
23 * @author Francois Chouinard
25 @SuppressWarnings("deprecation")
26 public abstract class TmfEventRequest
extends TmfDataRequest
implements ITmfEventRequest
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private final TmfRangeFilter fRangeFilter
; // The requested events time range
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 * Request all the events of a given type (high priority)
40 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
42 * @param dataType the requested data type
44 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
) {
45 this(dataType
, TmfTimeRange
.ETERNITY
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
49 * Request all the events of a given type (given priority)
50 * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
52 * @param dataType the requested data type
53 * @param priority the requested execution priority
55 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, ExecutionType priority
) {
56 this(dataType
, TmfTimeRange
.ETERNITY
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
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).
63 * @param dataType the requested data type
64 * @param range the time range of the requested events
66 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
) {
67 this(dataType
, range
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
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).
74 * @param dataType the requested data type
75 * @param range the time range of the requested events
76 * @param priority the requested execution priority
78 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, ExecutionType priority
) {
79 this(dataType
, range
, 0, ALL_DATA
, DEFAULT_BLOCK_SIZE
, priority
);
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).
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
90 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, int nbRequested
) {
91 this(dataType
, range
, 0, nbRequested
, DEFAULT_BLOCK_SIZE
, ExecutionType
.FOREGROUND
);
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).
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
103 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, int nbRequested
, ExecutionType priority
) {
104 this(dataType
, range
, 0, nbRequested
, DEFAULT_BLOCK_SIZE
, priority
);
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.
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
116 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
) {
117 this(dataType
, range
, 0, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
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.
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
130 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, long index
, int nbRequested
, int blockSize
) {
131 this(dataType
, range
, index
, nbRequested
, blockSize
, ExecutionType
.FOREGROUND
);
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.
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
144 public TmfEventRequest(Class
<?
extends ITmfEvent
> dataType
, TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType priority
) {
145 this(dataType
, range
, 0, nbRequested
, blockSize
, priority
);
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.
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
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
);
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
);
177 // ------------------------------------------------------------------------
179 // ------------------------------------------------------------------------
182 * @return the requested time range
185 public TmfTimeRange
getRange() {
186 return fRangeFilter
.getTimeRange();
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
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
197 * @param index the start index
200 public void setStartIndex(int index
) {
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
209 // All requests have a unique id
210 public int hashCode() {
211 return getRequestId();
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());
224 @SuppressWarnings("nls")
225 public String
toString() {
226 return "[TmfEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
227 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";