Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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: | |
1f506a43 | 10 | * Francois Chouinard - Initial API and implementation |
8c8bf09f ASL |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.tmf.event; | |
14 | ||
2c8610f7 FC |
15 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; |
16 | ||
8c8bf09f ASL |
17 | /** |
18 | * <b><u>TmfEvent</u></b> | |
19 | * <p> | |
1f506a43 | 20 | * The basic event structure in the TMF. In its canonical form, an event has: |
8c8bf09f ASL |
21 | * <ul> |
22 | * <li> a normalized timestamp | |
23 | * <li> a source (reporter) | |
24 | * <li> a type | |
25 | * <li> a content | |
26 | * </ul> | |
27 | * For convenience, a free-form reference field is also provided. It could be | |
28 | * used as e.g. a location marker in the event stream to distinguish between | |
29 | * otherwise identical events. | |
28b94d61 FC |
30 | * |
31 | * Notice that for performance reasons TmfEvent is NOT immutable. If a copy | |
cbd4ad82 | 32 | * of the event is needed, use the copy constructor. |
8c8bf09f | 33 | */ |
f9673903 | 34 | public class TmfEvent extends TmfData implements Cloneable { |
8c8bf09f | 35 | |
36548af3 FC |
36 | // ------------------------------------------------------------------------ |
37 | // Constants | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
12c155f5 FC |
40 | public static final TmfEvent NullEvent = new TmfEvent(); |
41 | ||
cbd4ad82 | 42 | // ------------------------------------------------------------------------ |
8c8bf09f | 43 | // Attributes |
cbd4ad82 | 44 | // ------------------------------------------------------------------------ |
8c8bf09f | 45 | |
4bf17f4a | 46 | protected ITmfTrace<?> fParentTrace; |
2c8610f7 | 47 | protected long fEventRank; |
28b94d61 FC |
48 | protected TmfTimestamp fEffectiveTimestamp; |
49 | protected TmfTimestamp fOriginalTimestamp; | |
50 | protected TmfEventSource fSource; | |
51 | protected TmfEventType fType; | |
52 | protected TmfEventReference fReference; | |
8c8bf09f | 53 | |
12c155f5 FC |
54 | // Content requires a reference to the parent event so it is initialized |
55 | // using setContent() | |
56 | protected TmfEventContent fContent; | |
28b94d61 | 57 | |
cbd4ad82 | 58 | // ------------------------------------------------------------------------ |
8c8bf09f | 59 | // Constructors |
cbd4ad82 | 60 | // ------------------------------------------------------------------------ |
8c8bf09f | 61 | |
2c8610f7 | 62 | /** |
4bf17f4a | 63 | * @param trace the parent trace |
2c8610f7 FC |
64 | * @param originalTS the original timestamp |
65 | * @param effectiveTS the effective timestamp | |
66 | * @param source the event source (generator) | |
67 | * @param type the event type | |
68 | * @param reference a free-form reference field | |
69 | */ | |
4bf17f4a | 70 | public TmfEvent(ITmfTrace<?> trace, long rank, TmfTimestamp originalTS, TmfTimestamp effectiveTS, |
2c8610f7 FC |
71 | TmfEventSource source, TmfEventType type, TmfEventReference reference) |
72 | { | |
73 | fParentTrace = trace; | |
74 | fEventRank = rank; | |
75 | fOriginalTimestamp = originalTS; | |
76 | fEffectiveTimestamp = effectiveTS; | |
77 | fSource = source; | |
78 | fType = type; | |
79 | fReference = reference; | |
80 | } | |
81 | ||
8c8bf09f | 82 | /** |
cbd4ad82 FC |
83 | * @param originalTS the original timestamp |
84 | * @param effectiveTS the effective timestamp | |
85 | * @param source the event source (generator) | |
86 | * @param type the event type | |
87 | * @param reference a free-form reference field | |
8c8bf09f | 88 | */ |
28b94d61 FC |
89 | public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, |
90 | TmfEventSource source, TmfEventType type, TmfEventReference reference) | |
8c8bf09f | 91 | { |
2c8610f7 | 92 | this(null, -1, originalTS, effectiveTS, source, type, reference); |
1f506a43 FC |
93 | } |
94 | ||
4bf17f4a | 95 | /** |
96 | * @param trace the parent trace | |
97 | * @param timestamp the effective timestamp | |
98 | * @param source the event source (generator) | |
99 | * @param type the event type | |
100 | * @param reference a free-form reference field | |
101 | */ | |
102 | public TmfEvent(ITmfTrace<?> parentTrace, TmfTimestamp timestamp, TmfEventSource source, | |
103 | TmfEventType type, TmfEventReference reference) | |
104 | { | |
105 | this(parentTrace, -1, timestamp, timestamp, source, type, reference); | |
106 | } | |
107 | ||
1f506a43 | 108 | /** |
cbd4ad82 FC |
109 | * @param timestamp the effective timestamp |
110 | * @param source the event source (generator) | |
111 | * @param type the event type | |
112 | * @param reference a free-form reference field | |
1f506a43 FC |
113 | */ |
114 | public TmfEvent(TmfTimestamp timestamp, TmfEventSource source, | |
28b94d61 | 115 | TmfEventType type, TmfEventReference reference) |
1f506a43 | 116 | { |
2c8610f7 | 117 | this(null, -1, timestamp, timestamp, source, type, reference); |
4e3aa37d FC |
118 | } |
119 | ||
120 | /** | |
cbd4ad82 | 121 | * Copy constructor |
28b94d61 | 122 | * |
cbd4ad82 | 123 | * @param other the original event |
4e3aa37d | 124 | */ |
28b94d61 | 125 | public TmfEvent(TmfEvent other) { |
cbd4ad82 FC |
126 | if (other == null) |
127 | throw new IllegalArgumentException(); | |
2c8610f7 FC |
128 | fParentTrace = other.fParentTrace; |
129 | fEventRank = other.fEventRank; | |
cbd4ad82 FC |
130 | fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp); |
131 | fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp); | |
132 | fSource = new TmfEventSource(other.fSource); | |
133 | fType = new TmfEventType(other.fType); | |
134 | fContent = new TmfEventContent(other.fContent); | |
135 | fReference = new TmfEventReference(other.fReference); | |
28b94d61 FC |
136 | } |
137 | ||
12c155f5 FC |
138 | public TmfEvent() { |
139 | } | |
36548af3 | 140 | |
12c155f5 FC |
141 | @Override |
142 | public boolean isNullRef() { | |
143 | return this == NullEvent; | |
144 | } | |
8c8bf09f | 145 | |
12c155f5 | 146 | // ------------------------------------------------------------------------ |
8c8bf09f | 147 | // Accessors |
cbd4ad82 | 148 | // ------------------------------------------------------------------------ |
8c8bf09f | 149 | |
2c8610f7 FC |
150 | /** |
151 | * @return the parent trace | |
152 | */ | |
4bf17f4a | 153 | public ITmfTrace<?> getParentTrace() { |
2c8610f7 FC |
154 | return fParentTrace; |
155 | } | |
156 | ||
157 | /** | |
158 | * @return the event rank | |
159 | */ | |
160 | public long getEventRank() { | |
161 | return fEventRank; | |
162 | } | |
163 | ||
12c155f5 FC |
164 | /** |
165 | * @return the effective event timestamp | |
166 | */ | |
167 | public TmfTimestamp getTimestamp() { | |
168 | return fEffectiveTimestamp; | |
169 | } | |
1f506a43 | 170 | |
12c155f5 FC |
171 | /** |
172 | * @return the original event timestamp | |
173 | */ | |
174 | public TmfTimestamp getOriginalTimestamp() { | |
175 | return fOriginalTimestamp; | |
176 | } | |
8c8bf09f | 177 | |
12c155f5 FC |
178 | /** |
179 | * @return the event source | |
180 | */ | |
181 | public TmfEventSource getSource() { | |
182 | return fSource; | |
183 | } | |
8c8bf09f | 184 | |
12c155f5 FC |
185 | /** |
186 | * @return the event type | |
187 | */ | |
188 | public TmfEventType getType() { | |
189 | return fType; | |
190 | } | |
8c8bf09f | 191 | |
12c155f5 FC |
192 | /** |
193 | * @return the event content | |
194 | */ | |
195 | public TmfEventContent getContent() { | |
196 | return fContent; | |
197 | } | |
8c8bf09f | 198 | |
12c155f5 FC |
199 | /** |
200 | * @return the event reference | |
201 | */ | |
202 | public TmfEventReference getReference() { | |
203 | return fReference; | |
204 | } | |
1f506a43 | 205 | |
12c155f5 FC |
206 | /** |
207 | * @param content | |
208 | * the new event content | |
209 | */ | |
210 | public void setContent(TmfEventContent content) { | |
211 | fContent = content; | |
212 | } | |
cbd4ad82 | 213 | |
12c155f5 FC |
214 | /** |
215 | * @return the event raw text | |
216 | */ | |
217 | public String getRawText() { | |
218 | if (fContent != null && fContent.getContent() != null) { | |
219 | return fContent.getContent().toString(); | |
220 | } | |
221 | return ""; //$NON-NLS-1$ | |
222 | } | |
c76c54bb | 223 | |
12c155f5 | 224 | // ------------------------------------------------------------------------ |
cbd4ad82 FC |
225 | // Object |
226 | // ------------------------------------------------------------------------ | |
28b94d61 | 227 | |
12c155f5 | 228 | @Override |
cbd4ad82 | 229 | public int hashCode() { |
12c155f5 FC |
230 | int result = 17; |
231 | result = 37 * result + fSource.hashCode(); | |
232 | result = 37 * result + fType.hashCode(); | |
233 | result = 37 * result + fEffectiveTimestamp.hashCode(); | |
cbd4ad82 FC |
234 | return result; |
235 | } | |
236 | ||
237 | @Override | |
238 | public boolean equals(Object other) { | |
239 | if (!(other instanceof TmfEvent)) | |
12c155f5 | 240 | return false; |
cbd4ad82 | 241 | TmfEvent o = (TmfEvent) other; |
12c155f5 | 242 | return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && fSource.equals(o.fSource) && fType.equals(o.fType) && fContent.equals(o.fContent); |
cbd4ad82 | 243 | } |
28b94d61 | 244 | |
12c155f5 | 245 | @Override |
3b38ea61 | 246 | @SuppressWarnings("nls") |
12c155f5 FC |
247 | public String toString() { |
248 | return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]"; | |
249 | } | |
cbd4ad82 | 250 | |
f9673903 FC |
251 | @Override |
252 | public TmfEvent clone() { | |
1a971e96 FC |
253 | TmfEvent clone = null; |
254 | try { | |
255 | clone = (TmfEvent) super.clone(); | |
2c8610f7 FC |
256 | clone.fParentTrace = fParentTrace; |
257 | clone.fEventRank = fEventRank; | |
1a971e96 FC |
258 | clone.fOriginalTimestamp = fOriginalTimestamp.clone(); |
259 | clone.fEffectiveTimestamp = fEffectiveTimestamp.clone(); | |
260 | clone.fSource = fSource.clone(); | |
261 | clone.fType = fType.clone(); | |
262 | clone.fReference = fReference.clone(); | |
263 | clone.fContent = fContent.clone(); | |
264 | } | |
265 | catch (CloneNotSupportedException e) { | |
266 | e.printStackTrace(); | |
267 | } | |
268 | ||
12c155f5 FC |
269 | return clone; |
270 | } | |
f9673903 | 271 | |
8c8bf09f | 272 | } |