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