Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2013 Ericsson |
0283f7ff | 3 | * |
8c8bf09f ASL |
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 | |
0283f7ff | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
7184fc40 | 11 | * Alexandre Montplaisir - Consolidated constructors |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.request; |
8c8bf09f | 15 | |
5500a7f0 | 16 | import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer; |
72f1e62a | 17 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
3bd46eef | 18 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
8c8bf09f ASL |
19 | |
20 | /** | |
8fd82db5 | 21 | * An extension of TmfDataRequest for timestamped events. |
0283f7ff | 22 | * |
8fd82db5 FC |
23 | * @version 1.0 |
24 | * @author Francois Chouinard | |
8c8bf09f | 25 | */ |
6256d8ad | 26 | public abstract class TmfEventRequest extends TmfDataRequest implements ITmfEventRequest { |
8c8bf09f ASL |
27 | |
28 | // ------------------------------------------------------------------------ | |
29 | // Attributes | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
7184fc40 | 32 | private final TmfTimeRange fRange; // The requested events time range |
8c8bf09f ASL |
33 | |
34 | // ------------------------------------------------------------------------ | |
7184fc40 | 35 | // Constructor |
8c8bf09f ASL |
36 | // ------------------------------------------------------------------------ |
37 | ||
38 | /** | |
7184fc40 AM |
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. | |
0283f7ff | 41 | * |
7184fc40 AM |
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. | |
7184fc40 AM |
55 | * @param priority |
56 | * The requested execution priority. | |
672a642a | 57 | * @since 3.0 |
0d9a6d76 | 58 | */ |
7184fc40 AM |
59 | public TmfEventRequest(Class<? extends ITmfEvent> dataType, |
60 | TmfTimeRange range, | |
61 | long index, | |
62 | int nbRequested, | |
7184fc40 | 63 | ExecutionType priority) { |
672a642a | 64 | super(dataType, index, nbRequested, priority); |
7184fc40 | 65 | fRange = range; |
90891c08 | 66 | |
5500a7f0 | 67 | if (TmfCoreTracer.isRequestTraced()) { |
90891c08 FC |
68 | String type = getClass().getName(); |
69 | type = type.substring(type.lastIndexOf('.') + 1); | |
70 | @SuppressWarnings("nls") | |
0283f7ff FC |
71 | String message = "CREATED " |
72 | + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)") | |
73 | + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested() | |
4cf201de | 74 | + " Range=" + getRange() |
90891c08 | 75 | + " DataType=" + getDataType().getSimpleName(); |
5500a7f0 | 76 | TmfCoreTracer.traceRequest(this, message); |
90891c08 | 77 | } |
8c8bf09f ASL |
78 | } |
79 | ||
80 | // ------------------------------------------------------------------------ | |
81 | // Accessors | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
84 | /** | |
85 | * @return the requested time range | |
3bd46eef | 86 | * @since 2.0 |
8c8bf09f | 87 | */ |
d4011df2 | 88 | @Override |
7184fc40 | 89 | public TmfTimeRange getRange() { |
5419a136 | 90 | return fRange; |
8c8bf09f ASL |
91 | } |
92 | ||
a79913eb FC |
93 | // ------------------------------------------------------------------------ |
94 | // Setters | |
95 | // ------------------------------------------------------------------------ | |
96 | ||
97 | /** | |
7184fc40 AM |
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 | |
0283f7ff | 100 | * |
7184fc40 AM |
101 | * @param index |
102 | * the start index | |
a79913eb FC |
103 | */ |
104 | @Override | |
7184fc40 AM |
105 | public void setStartIndex(int index) { |
106 | setIndex(index); | |
a79913eb FC |
107 | } |
108 | ||
2fb2eb37 FC |
109 | // ------------------------------------------------------------------------ |
110 | // Object | |
111 | // ------------------------------------------------------------------------ | |
112 | ||
113 | @Override | |
114 | // All requests have a unique id | |
115 | public int hashCode() { | |
7184fc40 | 116 | return getRequestId(); |
2fb2eb37 FC |
117 | } |
118 | ||
119 | @Override | |
120 | public boolean equals(Object other) { | |
7184fc40 AM |
121 | if (other instanceof TmfEventRequest) { |
122 | TmfEventRequest request = (TmfEventRequest) other; | |
123 | return super.equals(other) && request.fRange.equals(fRange); | |
124 | } | |
125 | return false; | |
2fb2eb37 FC |
126 | } |
127 | ||
128 | @Override | |
3b38ea61 | 129 | @SuppressWarnings("nls") |
2fb2eb37 | 130 | public String toString() { |
b1b156f3 PT |
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() | |
672a642a | 137 | + "," + getRange() + "," + getIndex() + "," + getNbRequested() + ")]"; |
2fb2eb37 FC |
138 | } |
139 | ||
8c8bf09f | 140 | } |