And some formatting fixes.
Change-Id: I9c8b51694ee82b4b55aa0d98b873cfda17625cf2
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14978
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Hudson CI
import org.eclipse.linuxtools.internal.tmf.core.request.TmfCoalescedDataRequest;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
import org.eclipse.linuxtools.tmf.tests.stubs.request.TmfDataRequestStub;
import org.junit.Before;
import org.junit.Test;
@Before
public void setUp() {
TmfDataRequest.reset();
- fRequest1 = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
- fRequest2 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 100, 200);
- fRequest3 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 200);
- fRequest4 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 300);
+ fRequest1 = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
+ fRequest2 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 100, 200, ExecutionType.FOREGROUND);
+ fRequest3 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 200, ExecutionType.FOREGROUND);
+ fRequest4 = new TmfCoalescedDataRequest(ITmfEvent.class, 20, 200, 300, ExecutionType.FOREGROUND);
- fRequest1b = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
- fRequest1c = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ fRequest1b = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
+ fRequest1c = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
fRequestCount = fRequest1c.getRequestId() + 1;
}
private static TmfCoalescedDataRequest setupTestRequest(final boolean[] flags) {
- TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200) {
+ TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND) {
@Override
public void handleCompleted() {
super.handleCompleted();
}
// ------------------------------------------------------------------------
- // Constructors
+ // Constructor
// ------------------------------------------------------------------------
- @Test
- public void testTmfCoalescedDataRequest() {
- TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getIndex", 0, request.getIndex());
- assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
- @Test
- public void testTmfCoalescedDataRequestIndex() {
- TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getIndex", 10, request.getIndex());
- assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
- @Test
- public void testTmfCoalescedDataRequestIndexNbRequested() {
- TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getIndex", 10, request.getIndex());
- assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
@Test
public void testTmfCoalescedDataRequestIndexNbEventsBlocksize() {
- TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest request = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
assertEquals("getRequestId", fRequestCount++, request.getRequestId());
assertEquals("getDataType", ITmfEvent.class, request.getDataType());
@Test
public void testIsCompatible() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request1 = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200);
TmfDataRequest request2 = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200);
TmfDataRequest request3 = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200);
@Test
public void testAddRequest1() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 10, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest2() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest3() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 4, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest4() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 5, 5, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest5() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 15, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest6() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 100, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest7() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 110, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Test
public void testAddRequest8() {
- TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200);
+ TmfCoalescedDataRequest coalescedRequest = new TmfCoalescedDataRequest(ITmfEvent.class, 10, 100, 200, ExecutionType.FOREGROUND);
TmfDataRequest request = new TmfDataRequestStub(ITmfEvent.class, 111, 100, 200);
assertTrue("isCompatible", coalescedRequest.isCompatible(request));
@Before
public void setUp() {
TmfDataRequest.reset();
- fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200);
- fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 100, 200);
- fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 200);
- fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 200, 300);
+ fRequest1 = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND);
+ fRequest2 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 100, 200, ExecutionType.FOREGROUND);
+ fRequest3 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, 200, ExecutionType.FOREGROUND);
+ fRequest4 = new TmfCoalescedEventRequest(ITmfEvent.class, range2, 0, 200, 300, ExecutionType.FOREGROUND);
- fRequest1b = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200);
- fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200);
+ fRequest1b = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND);
+ fRequest1c = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND);
fRequestCount = fRequest1c.getRequestId() + 1;
}
private TmfCoalescedEventRequest setupTestRequest(final boolean[] flags) {
- TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200) {
+ TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND) {
@Override
public void handleCompleted() {
super.handleCompleted();
}
// ------------------------------------------------------------------------
- // Constructors
+ // Constructor
// ------------------------------------------------------------------------
- @Test
- public void testTmfCoalescedEventRequest() {
- TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getRange", range1, request.getRange());
- assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
- @Test
- public void testTmfCoalescedEventRequestIndex() {
- TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getRange", range1, request.getRange());
- assertEquals("getNbRequestedEvents", TmfDataRequest.ALL_DATA, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
- public void testTmfCoalescedEventRequestIndexNbRequested() {
- TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100);
-
- assertEquals("getRequestId", fRequestCount++, request.getRequestId());
- assertEquals("getDataType", ITmfEvent.class, request.getDataType());
-
- assertEquals("getRange", range1, request.getRange());
- assertEquals("getNbRequestedEvents", 100, request.getNbRequested());
-
- assertFalse("isCompleted", request.isCompleted());
- assertFalse("isFailed", request.isFailed());
- assertFalse("isCancelled", request.isCancelled());
-
- assertEquals("getNbRead", 0, request.getNbRead());
- }
-
@Test
public void testTmfCoalescedEventRequestIndexNbEventsBlocksize() {
- TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200);
+ TmfCoalescedEventRequest request = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND);
assertEquals("getRequestId", fRequestCount++, request.getRequestId());
assertEquals("getDataType", ITmfEvent.class, request.getDataType());
@Test
public void testEqualsSuper() {
TmfCoalescedDataRequest dataRequest1 = new TmfCoalescedDataRequest(
- fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested());
+ fRequest1.getDataType(),
+ fRequest1.getIndex(),
+ fRequest1.getNbRequested(),
+ TmfDataRequest.DEFAULT_BLOCK_SIZE,
+ ExecutionType.FOREGROUND);
TmfCoalescedDataRequest dataRequest2 = new TmfCoalescedDataRequest(
- fRequest1.getDataType(), fRequest1.getIndex(), fRequest1.getNbRequested());
+ fRequest1.getDataType(),
+ fRequest1.getIndex(),
+ fRequest1.getNbRequested(),
+ TmfDataRequest.DEFAULT_BLOCK_SIZE,
+ ExecutionType.FOREGROUND);
TmfCoalescedDataRequest dataRequest3 = new TmfCoalescedDataRequest(
- fRequest3.getDataType(), fRequest3.getIndex(), fRequest3.getNbRequested());
+ fRequest3.getDataType(),
+ fRequest3.getIndex(),
+ fRequest3.getNbRequested(),
+ TmfDataRequest.DEFAULT_BLOCK_SIZE,
+ ExecutionType.FOREGROUND);
assertTrue("equals", fRequest1.equals(dataRequest2));
assertTrue("equals", fRequest2.equals(dataRequest1));
@Test
public void testIsCompatible() {
- TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 100, 200);
+ TmfCoalescedEventRequest coalescedRequest = new TmfCoalescedEventRequest(ITmfEvent.class, range1, 0, 100, 200, ExecutionType.FOREGROUND);
TmfEventRequest req1 = new TmfEventRequestStub(ITmfEvent.class, range1, 100, 200);
TmfEventRequest req2 = new TmfEventRequestStub(ITmfEvent.class, range2, 100, 200);
TmfEventRequest req3 = new TmfEventRequestStub(ITmfEvent.class, range1, 101, 200);
package org.eclipse.linuxtools.internal.tmf.core.request;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
// Attributes
// ------------------------------------------------------------------------
- /**
- * The list of coalesced requests
- */
- protected Vector<ITmfDataRequest> fRequests = new Vector<ITmfDataRequest>();
+ /**
+ * The list of coalesced requests
+ */
+ protected final List<ITmfDataRequest> fRequests = new ArrayList<ITmfDataRequest>();
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
- /**
- * Request all the events of a given type (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType) {
- this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request all the events of a given type (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param priority the requested execution priority
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, ExecutionType priority) {
- this(dataType, 0, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request all the events of a given type from the given index (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index) {
- this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request all the events of a given type from the given index (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- * @param priority the requested execution priority
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, ExecutionType priority) {
- this(dataType, index, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request 'n' events of a given type from the given index (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- * @param nbRequested the number of events requested
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested) {
- this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request 'n' events of a given type from the given index (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- * @param nbRequested the number of events requested
- * @param priority the requested execution priority
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, ExecutionType priority) {
- this(dataType, index, nbRequested, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request 'n' events of a given type from the given index (high priority).
- * Events are returned in blocks of the given size.
- *
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- * @param nbRequested the number of events requested
- * @param blockSize the number of events per block
- */
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, int blockSize) {
- super(ITmfEvent.class, index, nbRequested, blockSize, ExecutionType.FOREGROUND);
- }
-
/**
* Request 'n' events of a given type from the given index (given priority).
* Events are returned in blocks of the given size.
*
- * @param dataType the requested data type
- * @param index the index of the first event to retrieve
- * @param nbRequested the number of events requested
- * @param blockSize the number of events per block
- * @param priority the requested execution priority
+ * @param dataType
+ * The requested data type
+ * @param index
+ * The index of the first event to retrieve. Use '0' to start at
+ * the beginning.
+ * @param nbRequested
+ * The number of events requested. You can use
+ * {@link TmfDataRequest#ALL_DATA} to request all events.
+ * @param blockSize
+ * The number of events per block. You can use
+ * {@link TmfDataRequest#DEFAULT_BLOCK_SIZE} to use a default
+ * value.
+ * @param priority
+ * The requested execution priority
*/
- public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, int blockSize, ExecutionType priority) {
+ public TmfCoalescedDataRequest(Class<? extends ITmfEvent> dataType,
+ long index,
+ int nbRequested,
+ int blockSize,
+ ExecutionType priority) {
super(ITmfEvent.class, index, nbRequested, blockSize, priority);
}
/**
* Add a request to this one.
*
- * @param request The request to add
+ * @param request
+ * The request to add
*/
public void addRequest(ITmfDataRequest request) {
fRequests.add(request);
fIndex = start;
}
if ((request.getNbRequested() == TmfDataRequest.ALL_DATA) ||
- (fNbRequested == TmfDataRequest.ALL_DATA))
+ (fNbRequested == TmfDataRequest.ALL_DATA))
{
fNbRequested = TmfDataRequest.ALL_DATA;
} else {
}
}
- /**
- * @return The list of IDs of the sub-requests
- */
- @SuppressWarnings("nls")
+ /**
+ * @return The list of IDs of the sub-requests
+ */
+ @SuppressWarnings("nls")
public String getSubRequestIds() {
- StringBuffer result = new StringBuffer("[");
- for (int i = 0; i < fRequests.size(); i++) {
- if (i != 0) {
+ StringBuffer result = new StringBuffer("[");
+ for (int i = 0; i < fRequests.size(); i++) {
+ if (i != 0) {
result.append(", ");
}
- result.append(fRequests.get(i).getRequestId());
- }
- result.append("]");
- return result.toString();
- }
+ result.append(fRequests.get(i).getRequestId());
+ }
+ result.append("]");
+ return result.toString();
+ }
// ------------------------------------------------------------------------
// ITmfDataRequest
// ------------------------------------------------------------------------
@Override
- public void handleData(ITmfEvent data) {
- super.handleData(data);
- // Don't call sub-requests handleData() unless this is a
- // TmfCoalescedDataRequest; extended classes should call
- // the sub-requests handleData().
- if (getClass() == TmfCoalescedDataRequest.class) {
- long index = getIndex() + getNbRead() - 1;
- for (ITmfDataRequest request : fRequests) {
- if (!request.isCompleted()) {
+ public void handleData(ITmfEvent data) {
+ super.handleData(data);
+ // Don't call sub-requests handleData() unless this is a
+ // TmfCoalescedDataRequest; extended classes should call
+ // the sub-requests handleData().
+ if (getClass() == TmfCoalescedDataRequest.class) {
+ long index = getIndex() + getNbRead() - 1;
+ for (ITmfDataRequest request : fRequests) {
+ if (!request.isCompleted()) {
if (request.getDataType().isInstance(data)) {
long start = request.getIndex();
long end = start + request.getNbRequested();
super.start();
}
- @Override
+ @Override
public void done() {
- for (ITmfDataRequest request : fRequests) {
- if (!request.isCompleted()) {
- request.done();
- }
- }
- super.done();
+ for (ITmfDataRequest request : fRequests) {
+ if (!request.isCompleted()) {
+ request.done();
+ }
+ }
+ super.done();
}
@Override
public void fail() {
- for (ITmfDataRequest request : fRequests) {
- request.fail();
- }
- super.fail();
+ for (ITmfDataRequest request : fRequests) {
+ request.fail();
+ }
+ super.fail();
}
@Override
public void cancel() {
- for (ITmfDataRequest request : fRequests) {
- if (!request.isCompleted()) {
- request.cancel();
- }
- }
- super.cancel();
+ for (ITmfDataRequest request : fRequests) {
+ if (!request.isCompleted()) {
+ request.cancel();
+ }
+ }
+ super.cancel();
}
@Override
}
-
// ------------------------------------------------------------------------
// Object
// ------------------------------------------------------------------------
@Override
// All requests have a unique id
public int hashCode() {
- return super.hashCode();
+ return super.hashCode();
}
@Override
public boolean equals(Object other) {
- if (other instanceof TmfCoalescedDataRequest) {
- TmfCoalescedDataRequest request = (TmfCoalescedDataRequest) other;
- return (request.getDataType() == getDataType()) &&
- (request.getIndex() == getIndex()) &&
- (request.getNbRequested() == getNbRequested() &&
- (request.getExecType() == getExecType()));
- }
- return false;
+ if (other instanceof TmfCoalescedDataRequest) {
+ TmfCoalescedDataRequest request = (TmfCoalescedDataRequest) other;
+ return (request.getDataType() == getDataType()) &&
+ (request.getIndex() == getIndex()) &&
+ (request.getNbRequested() == getNbRequested() &&
+ (request.getExecType() == getExecType()));
+ }
+ return false;
}
@Override
@SuppressWarnings("nls")
public String toString() {
- return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
- + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
+ return "[TmfCoalescedDataRequest(" + getRequestId() + "," + getDataType().getSimpleName()
+ + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
}
}
// Attributes
// ------------------------------------------------------------------------
- private TmfTimeRange fRange; // The requested events time range
+ private TmfTimeRange fRange; // The requested events time range
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
/**
- * Request all the events of a given type (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
+ * Request 'n' events of a given type for the given time range (given
+ * priority). Events are returned in blocks of the given size.
*
- * @param dataType the requested data type
+ * @param dataType
+ * The requested data type
+ * @param range
+ * The range of the request. You can use
+ * {@link TmfTimeRange#ETERNITY} to request all events.
+ * @param index
+ * The index of the first event to retrieve. Use '0' to start at
+ * the beginning.
+ * @param nbRequested
+ * The number of events requested. You can use
+ * {@link TmfDataRequest#ALL_DATA} to request all events.
+ * @param blockSize
+ * The number of events per block. You can use
+ * {@link TmfDataRequest#DEFAULT_BLOCK_SIZE} to use a default
+ * value.
+ * @param priority
+ * The requested execution priority
*/
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType) {
- this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request all the events of a given type (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param priority the requested execution priority
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, ExecutionType priority) {
- this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request all the events of a given type for the given time range (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range) {
- this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request all the events of a given type for the given time range (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param priority the requested execution priority
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, ExecutionType priority) {
- this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request 'n' events of a given type from the given time range (high priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param nbRequested the number of events requested
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested) {
- this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request 'n' events of a given type for the given time range (given priority)
- * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param nbRequested the number of events requested
- * @param priority the requested execution priority
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) {
- this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, priority);
- }
-
- /**
- * Request 'n' events of a given type for the given time range (high priority).
- * Events are returned in blocks of the given size.
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param nbRequested the number of events requested
- * @param blockSize the number of events per block
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize) {
- this(dataType, range, 0, nbRequested, blockSize, ExecutionType.FOREGROUND);
- }
-
- /**
- * Request 'n' events of a given type for the given time range (given priority).
- * Events are returned in blocks of the given size.
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param nbRequested the number of events requested
- * @param blockSize the number of events per block
- * @param priority the requested execution priority
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) {
- this(dataType, range, 0, nbRequested, blockSize, priority);
- }
-
- /**
- * Request 'n' events of a given type for the given time range (given priority).
- * Events are returned in blocks of the given size.
- *
- * @param dataType the requested data type
- * @param range the time range of the requested events
- * @param index the index of the first event to retrieve
- * @param nbRequested the number of events requested
- * @param blockSize the number of events per block
- * @param priority the requested execution priority
- */
- public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
+ public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType,
+ TmfTimeRange range,
+ long index,
+ int nbRequested,
+ int blockSize,
+ ExecutionType priority) {
super(ITmfEvent.class, index, nbRequested, blockSize, priority);
fRange = range;
}
}
- @Override
- public boolean isCompatible(ITmfDataRequest request) {
- if (request instanceof ITmfEventRequest) {
- if (super.isCompatible(request)) {
- return overlaps((ITmfEventRequest) request);
- }
- }
- return false;
- }
+ @Override
+ public boolean isCompatible(ITmfDataRequest request) {
+ if (request instanceof ITmfEventRequest) {
+ if (super.isCompatible(request)) {
+ return overlaps((ITmfEventRequest) request);
+ }
+ }
+ return false;
+ }
private boolean overlaps(ITmfEventRequest request) {
ITmfTimestamp startTime = request.getRange().getStartTime();
- ITmfTimestamp endTime = request.getRange().getEndTime();
+ ITmfTimestamp endTime = request.getRange().getEndTime();
return (startTime.compareTo(endTime) <= 0) && (fRange.getStartTime().compareTo(fRange.getEndTime()) <= 0);
}
private void merge(ITmfEventRequest request) {
ITmfTimestamp startTime = request.getRange().getStartTime();
- ITmfTimestamp endTime = request.getRange().getEndTime();
+ ITmfTimestamp endTime = request.getRange().getEndTime();
if (!fRange.contains(startTime) && fRange.getStartTime().compareTo(startTime) > 0) {
fRange = new TmfTimeRange(startTime, fRange.getEndTime());
}
// ITmfEventRequest
// ------------------------------------------------------------------------
- @Override
- public TmfTimeRange getRange() {
- return fRange;
- }
+ @Override
+ public TmfTimeRange getRange() {
+ return fRange;
+ }
- @Override
- public void setStartIndex(int index) {
- setIndex(index);
- }
+ @Override
+ public void setStartIndex(int index) {
+ setIndex(index);
+ }
// ------------------------------------------------------------------------
// Object
@Override
// All requests have a unique id
public int hashCode() {
- return super.hashCode();
+ return super.hashCode();
}
@Override
public boolean equals(Object other) {
- if (other instanceof TmfCoalescedEventRequest) {
- TmfCoalescedEventRequest request = (TmfCoalescedEventRequest) other;
- return (request.getDataType() == getDataType()) &&
- (request.getIndex() == getIndex()) &&
- (request.getNbRequested() == getNbRequested()) &&
- (request.getRange().equals(getRange()));
- }
- if (other instanceof TmfCoalescedDataRequest) {
- return super.equals(other);
- }
- return false;
+ if (other instanceof TmfCoalescedEventRequest) {
+ TmfCoalescedEventRequest request = (TmfCoalescedEventRequest) other;
+ return (request.getDataType() == getDataType()) &&
+ (request.getIndex() == getIndex()) &&
+ (request.getNbRequested() == getNbRequested()) &&
+ (request.getRange().equals(getRange()));
+ }
+ if (other instanceof TmfCoalescedDataRequest) {
+ return super.equals(other);
+ }
+ return false;
}
@Override
@SuppressWarnings("nls")
public String toString() {
- return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
- + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
+ return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
+ + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
}
}