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 | ||
13 | package org.eclipse.linuxtools.tmf.component; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
2fb2eb37 FC |
17 | import org.eclipse.linuxtools.tmf.request.ITmfDataRequest; |
18 | import org.eclipse.linuxtools.tmf.request.ITmfEventRequest; | |
951d134a | 19 | import org.eclipse.linuxtools.tmf.request.TmfCoalescedEventRequest; |
8c8bf09f ASL |
20 | |
21 | /** | |
22 | * <b><u>TmfEventProvider</u></b> | |
23 | * <p> | |
24 | * Implement me. Please. | |
25 | */ | |
26 | public abstract class TmfEventProvider<T extends TmfEvent> extends TmfDataProvider<T> { | |
27 | ||
fc6ccf6f FC |
28 | public TmfEventProvider(Class<T> type) { |
29 | super("TmfEventProvider", type); | |
8c8bf09f ASL |
30 | } |
31 | ||
fc6ccf6f FC |
32 | public TmfEventProvider(Class<T> type, int queueSize) { |
33 | super("TmfEventProvider", type, queueSize); | |
8c8bf09f | 34 | } |
fc6ccf6f | 35 | |
8c8bf09f | 36 | @Override |
2fb2eb37 | 37 | public boolean isCompleted(ITmfDataRequest<T> request, T data, int nbRead) { |
8c8bf09f | 38 | boolean dataRequestCompleted = super.isCompleted(request, data, nbRead); |
2fb2eb37 FC |
39 | if (!dataRequestCompleted && request instanceof ITmfEventRequest<?> && data != null) { |
40 | TmfTimestamp endTime = ((ITmfEventRequest<?>) request).getRange().getEndTime(); | |
8c8bf09f ASL |
41 | return data.getTimestamp().compareTo(endTime, false) > 0; |
42 | } | |
43 | return dataRequestCompleted; | |
44 | } | |
45 | ||
951d134a | 46 | @Override |
2fb2eb37 FC |
47 | protected synchronized void newCoalescedDataRequest(ITmfDataRequest<T> request) { |
48 | if (request instanceof ITmfEventRequest<?>) { | |
49 | ITmfEventRequest<T> eventRequest = (ITmfEventRequest<T>) request; | |
951d134a FC |
50 | TmfCoalescedEventRequest<T> coalescedRequest = |
51 | new TmfCoalescedEventRequest<T>(fType, eventRequest.getRange(), eventRequest.getNbRequested(), eventRequest.getBlockize()); | |
52 | coalescedRequest.addRequest(eventRequest); | |
53 | fPendingCoalescedRequests.add(coalescedRequest); | |
54 | } | |
54d55ced FC |
55 | else { |
56 | super.newCoalescedDataRequest(request); | |
57 | } | |
951d134a FC |
58 | } |
59 | ||
8c8bf09f | 60 | } |