Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / request / TmfEventRequest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Alexandre Montplaisir - Consolidated constructors
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.request;
15
16 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
17 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
18 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
19
20 /**
21 * An extension of TmfDataRequest for timestamped events.
22 *
23 * @version 1.0
24 * @author Francois Chouinard
25 */
26 public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEventRequest {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 private final TmfTimeRange fRange; // The requested events time range
33
34 // ------------------------------------------------------------------------
35 // Constructor
36 // ------------------------------------------------------------------------
37
38 /**
39 * Request 'n' events of a given type for the given time range (given
40 * priority). Events are returned in blocks of the given size.
41 *
42 * @param dataType
43 * The requested data type.
44 * @param range
45 * The time range of the requested events. You can use
46 * {@link TmfTimeRange#ETERNITY} to indicate you want to cover
47 * the whole trace.
48 * @param index
49 * The index of the first event to retrieve. You can use '0' to
50 * start at the beginning of the trace.
51 * @param nbRequested
52 * The number of events requested. You can use
53 * {@link TmfEventRequest#ALL_DATA} to indicate you want all
54 * events in the time range.
55 * @param priority
56 * The requested execution priority.
57 * @since 3.0
58 */
59 public TmfEventRequest(Class<? extends ITmfEvent> dataType,
60 TmfTimeRange range,
61 long index,
62 int nbRequested,
63 ExecutionType priority) {
64 super(dataType, index, nbRequested, priority);
65 fRange = range;
66
67 if (TmfCoreTracer.isRequestTraced()) {
68 String type = getClass().getName();
69 type = type.substring(type.lastIndexOf('.') + 1);
70 @SuppressWarnings("nls")
71 String message = "CREATED "
72 + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)")
73 + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested()
74 + " Range=" + getRange()
75 + " DataType=" + getDataType().getSimpleName();
76 TmfCoreTracer.traceRequest(this, message);
77 }
78 }
79
80 // ------------------------------------------------------------------------
81 // Accessors
82 // ------------------------------------------------------------------------
83
84 /**
85 * @return the requested time range
86 * @since 2.0
87 */
88 @Override
89 public TmfTimeRange getRange() {
90 return fRange;
91 }
92
93 // ------------------------------------------------------------------------
94 // Setters
95 // ------------------------------------------------------------------------
96
97 /**
98 * this method is called by the event provider to set the index
99 * corresponding to the time range start time once it is known
100 *
101 * @param index
102 * the start index
103 */
104 @Override
105 public void setStartIndex(int index) {
106 setIndex(index);
107 }
108
109 // ------------------------------------------------------------------------
110 // Object
111 // ------------------------------------------------------------------------
112
113 @Override
114 // All requests have a unique id
115 public int hashCode() {
116 return getRequestId();
117 }
118
119 @Override
120 public boolean equals(Object other) {
121 if (other instanceof TmfEventRequest) {
122 TmfEventRequest request = (TmfEventRequest) other;
123 return super.equals(other) && request.fRange.equals(fRange);
124 }
125 return false;
126 }
127
128 @Override
129 @SuppressWarnings("nls")
130 public String toString() {
131 String name = getClass().getName();
132 int dot = name.lastIndexOf('.');
133 if (dot >= 0) {
134 name = name.substring(dot + 1);
135 }
136 return "[" + name + "(" + getRequestId() + "," + getDataType().getSimpleName() + "," + getExecType()
137 + "," + getRange() + "," + getIndex() + "," + getNbRequested() + ")]";
138 }
139
140 }
This page took 0.035374 seconds and 6 git commands to generate.