1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 * Francois Chouinard - Replace background requests by pre-emptable requests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.component
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.TmfCoreTracer
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.request
.TmfCoalescedEventRequest
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
24 * An extension of TmfDataProvider timestamped events providers.
26 * @author Francois Chouinard
29 public abstract class TmfEventProvider
extends TmfDataProvider
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
38 public TmfEventProvider() {
43 public void init(String name
, Class
<?
extends ITmfEvent
> type
) {
44 super.init(name
, type
);
48 * Standard constructor
51 * The name of the provider
53 * The type of handled events
55 public TmfEventProvider(String name
, Class
<?
extends ITmfEvent
> type
) {
60 * Standard constructor which also sets the queue size
63 * The name of the provider
65 * The type of handled events
67 * The size of the queue
69 public TmfEventProvider(String name
, Class
<?
extends ITmfEvent
> type
, int queueSize
) {
70 super(name
, type
, queueSize
);
77 * The other TmfEventProvider to copy
79 public TmfEventProvider(TmfEventProvider other
) {
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 public boolean isCompleted(ITmfDataRequest request
, ITmfEvent data
, int nbRead
) {
89 boolean requestCompleted
= super.isCompleted(request
, data
, nbRead
);
90 if (!requestCompleted
&& request
instanceof ITmfEventRequest
) {
91 ITmfTimestamp endTime
= ((ITmfEventRequest
) request
).getRange().getEndTime();
92 return data
.getTimestamp().compareTo(endTime
, false) > 0;
94 return requestCompleted
;
98 protected synchronized void newCoalescedDataRequest(ITmfDataRequest request
) {
99 if (request
instanceof ITmfEventRequest
) {
100 ITmfEventRequest eventRequest
= (ITmfEventRequest
) request
;
101 TmfCoalescedEventRequest coalescedRequest
= new TmfCoalescedEventRequest(eventRequest
.getDataType(), eventRequest
.getRange(),
102 eventRequest
.getIndex(), eventRequest
.getNbRequested(), eventRequest
.getBlockSize(), eventRequest
.getExecType());
103 coalescedRequest
.addRequest(eventRequest
);
104 if (TmfCoreTracer
.isRequestTraced()) {
105 TmfCoreTracer
.traceRequest(request
, "COALESCED with " + coalescedRequest
.getRequestId()); //$NON-NLS-1$
106 TmfCoreTracer
.traceRequest(coalescedRequest
, "now contains " + coalescedRequest
.getSubRequestIds()); //$NON-NLS-1$
108 fPendingCoalescedRequests
.add(coalescedRequest
);
110 super.newCoalescedDataRequest(request
);