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() {
193 * @param content the new event content
195 public void setContent(TmfEventContent content
) {
200 * @return the event raw text
202 public String
getRawText() {
203 if (fContent
!= null && fContent
.getContent() != null) {
204 return fContent
.getContent().toString();
206 return ""; //$NON-NLS-1$
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
214 public int hashCode() {
216 result
= 37 * result
+ fSource
.hashCode();
217 result
= 37 * result
+ fType
.hashCode();
218 result
= 37 * result
+ fEffectiveTimestamp
.hashCode();
223 public boolean equals(Object other
) {
224 if (!(other
instanceof TmfEvent
))
226 TmfEvent o
= (TmfEvent
) other
;
227 return fEffectiveTimestamp
.equals(o
.fEffectiveTimestamp
) &&
228 fSource
.equals(o
.fSource
) &&
229 fType
.equals(o
.fType
) &&
230 fContent
.equals(o
.fContent
);
234 @SuppressWarnings("nls")
235 public String
toString() {
236 return "[TmfEvent(" + fEffectiveTimestamp
+ "," + fSource
+ "," + fType
+ "," + fContent
+ ")]";
240 public TmfEvent
clone() {
241 TmfEvent clone
= null;
243 clone
= (TmfEvent
) super.clone();
244 clone
.fParentTrace
= fParentTrace
;
245 clone
.fEventRank
= fEventRank
;
246 clone
.fOriginalTimestamp
= fOriginalTimestamp
.clone();
247 clone
.fEffectiveTimestamp
= fEffectiveTimestamp
.clone();
248 clone
.fSource
= fSource
.clone();
249 clone
.fType
= fType
.clone();
250 clone
.fReference
= fReference
.clone();
251 clone
.fContent
= fContent
.clone();
253 catch (CloneNotSupportedException e
) {