1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
15 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
18 * <b><u>TmfEvent</u></b>
20 * The basic event structure in the TMF. In its canonical form, an event has:
22 * <li> a normalized timestamp
23 * <li> a source (reporter)
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.
31 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
32 * of the event is needed, use the copy constructor.
34 public class TmfEvent
extends TmfData
implements Cloneable
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 public static final TmfEvent NullEvent
= new TmfEvent();
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 protected ITmfTrace fParentTrace
;
47 protected long fEventRank
;
48 protected TmfTimestamp fEffectiveTimestamp
;
49 protected TmfTimestamp fOriginalTimestamp
;
50 protected TmfEventSource fSource
;
51 protected TmfEventType fType
;
52 protected TmfEventReference fReference
;
54 // Content requires a reference to the parent event so it is initialized
56 protected TmfEventContent fContent
;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * @param originalTS the original timestamp
64 * @param effectiveTS the effective timestamp
65 * @param source the event source (generator)
66 * @param type the event type
67 * @param reference a free-form reference field
69 public TmfEvent(ITmfTrace trace
, long rank
, TmfTimestamp originalTS
, TmfTimestamp effectiveTS
,
70 TmfEventSource source
, TmfEventType type
, TmfEventReference reference
)
74 fOriginalTimestamp
= originalTS
;
75 fEffectiveTimestamp
= effectiveTS
;
78 fReference
= reference
;
82 * @param originalTS the original timestamp
83 * @param effectiveTS the effective timestamp
84 * @param source the event source (generator)
85 * @param type the event type
86 * @param reference a free-form reference field
88 public TmfEvent(TmfTimestamp originalTS
, TmfTimestamp effectiveTS
,
89 TmfEventSource source
, TmfEventType type
, TmfEventReference reference
)
91 this(null, -1, originalTS
, effectiveTS
, source
, type
, reference
);
95 * @param timestamp the effective timestamp
96 * @param source the event source (generator)
97 * @param type the event type
98 * @param reference a free-form reference field
100 public TmfEvent(TmfTimestamp timestamp
, TmfEventSource source
,
101 TmfEventType type
, TmfEventReference reference
)
103 this(null, -1, timestamp
, timestamp
, source
, type
, reference
);
109 * @param other the original event
111 public TmfEvent(TmfEvent other
) {
113 throw new IllegalArgumentException();
114 fParentTrace
= other
.fParentTrace
;
115 fEventRank
= other
.fEventRank
;
116 fOriginalTimestamp
= new TmfTimestamp(other
.fOriginalTimestamp
);
117 fEffectiveTimestamp
= new TmfTimestamp(other
.fEffectiveTimestamp
);
118 fSource
= new TmfEventSource(other
.fSource
);
119 fType
= new TmfEventType(other
.fType
);
120 fContent
= new TmfEventContent(other
.fContent
);
121 fReference
= new TmfEventReference(other
.fReference
);
128 public boolean isNullRef() {
129 return this == NullEvent
;
132 // ------------------------------------------------------------------------
134 // ------------------------------------------------------------------------
137 * @return the parent trace
139 public ITmfTrace
getParentTrace() {
144 * @return the event rank
146 public long getEventRank() {
151 * @return the effective event timestamp
153 public TmfTimestamp
getTimestamp() {
154 return fEffectiveTimestamp
;
158 * @return the original event timestamp
160 public TmfTimestamp
getOriginalTimestamp() {
161 return fOriginalTimestamp
;
165 * @return the event source
167 public TmfEventSource
getSource() {
172 * @return the event type
174 public TmfEventType
getType() {
179 * @return the event content
181 public TmfEventContent
getContent() {
186 * @return the event reference
188 public TmfEventReference
getReference() {
194 * the new event content
196 public void setContent(TmfEventContent content
) {
201 * @return the event raw text
203 public String
getRawText() {
204 if (fContent
!= null && fContent
.getContent() != null) {
205 return fContent
.getContent().toString();
207 return ""; //$NON-NLS-1$
210 // ------------------------------------------------------------------------
212 // ------------------------------------------------------------------------
215 public int hashCode() {
217 result
= 37 * result
+ fSource
.hashCode();
218 result
= 37 * result
+ fType
.hashCode();
219 result
= 37 * result
+ fEffectiveTimestamp
.hashCode();
224 public boolean equals(Object other
) {
225 if (!(other
instanceof TmfEvent
))
227 TmfEvent o
= (TmfEvent
) other
;
228 return fEffectiveTimestamp
.equals(o
.fEffectiveTimestamp
) && fSource
.equals(o
.fSource
) && fType
.equals(o
.fType
) && fContent
.equals(o
.fContent
);
232 @SuppressWarnings("nls")
233 public String
toString() {
234 return "[TmfEvent(" + fEffectiveTimestamp
+ "," + fSource
+ "," + fType
+ "," + fContent
+ ")]";
238 public TmfEvent
clone() {
239 TmfEvent clone
= null;
241 clone
= (TmfEvent
) super.clone();
242 clone
.fParentTrace
= fParentTrace
;
243 clone
.fEventRank
= fEventRank
;
244 clone
.fOriginalTimestamp
= fOriginalTimestamp
.clone();
245 clone
.fEffectiveTimestamp
= fEffectiveTimestamp
.clone();
246 clone
.fSource
= fSource
.clone();
247 clone
.fType
= fType
.clone();
248 clone
.fReference
= fReference
.clone();
249 clone
.fContent
= fContent
.clone();
251 catch (CloneNotSupportedException e
) {