tmf: Move timestamps to their own package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / component / TmfEventProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 * Francois Chouinard - Replace background requests by pre-emptable requests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.component;
15
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.request.ITmfDataRequest;
20 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
21 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
22
23 /**
24 * An extension of TmfDataProvider timestamped events providers.
25 *
26 * @author Francois Chouinard
27 * @version 1.1
28 */
29 public abstract class TmfEventProvider extends TmfDataProvider {
30
31 // ------------------------------------------------------------------------
32 // Constructors
33 // ------------------------------------------------------------------------
34
35 /**
36 * Default constructor
37 */
38 public TmfEventProvider() {
39 super();
40 }
41
42 @Override
43 public void init(String name, Class<? extends ITmfEvent> type) {
44 super.init(name, type);
45 }
46
47 /**
48 * Standard constructor
49 *
50 * @param name
51 * The name of the provider
52 * @param type
53 * The type of handled events
54 */
55 public TmfEventProvider(String name, Class<? extends ITmfEvent> type) {
56 super(name, type);
57 }
58
59 /**
60 * Standard constructor which also sets the queue size
61 *
62 * @param name
63 * The name of the provider
64 * @param type
65 * The type of handled events
66 * @param queueSize
67 * The size of the queue
68 */
69 public TmfEventProvider(String name, Class<? extends ITmfEvent> type, int queueSize) {
70 super(name, type, queueSize);
71 }
72
73 /**
74 * Copy constructor
75 *
76 * @param other
77 * The other TmfEventProvider to copy
78 */
79 public TmfEventProvider(TmfEventProvider other) {
80 super(other);
81 }
82
83 // ------------------------------------------------------------------------
84 // TmfDataProvider
85 // ------------------------------------------------------------------------
86
87 @Override
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;
93 }
94 return requestCompleted;
95 }
96
97 @Override
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$
107 }
108 fPendingCoalescedRequests.add(coalescedRequest);
109 } else {
110 super.newCoalescedDataRequest(request);
111 }
112 }
113
114 }
This page took 0.031715 seconds and 5 git commands to generate.