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 | ||
15 | /** | |
16 | * <b><u>TmfEvent</u></b> | |
17 | * <p> | |
1f506a43 | 18 | * The basic event structure in the TMF. In its canonical form, an event has: |
8c8bf09f ASL |
19 | * <ul> |
20 | * <li> a normalized timestamp | |
21 | * <li> a source (reporter) | |
22 | * <li> a type | |
23 | * <li> a content | |
24 | * </ul> | |
25 | * For convenience, a free-form reference field is also provided. It could be | |
26 | * used as e.g. a location marker in the event stream to distinguish between | |
27 | * otherwise identical events. | |
28b94d61 FC |
28 | * |
29 | * Notice that for performance reasons TmfEvent is NOT immutable. If a copy | |
30 | * of the event is needed, use clone(). | |
8c8bf09f | 31 | */ |
28b94d61 | 32 | public class TmfEvent extends TmfData implements Cloneable { |
8c8bf09f | 33 | |
4ab33d2b | 34 | // ======================================================================== |
8c8bf09f | 35 | // Attributes |
4ab33d2b | 36 | // ======================================================================== |
8c8bf09f | 37 | |
28b94d61 FC |
38 | protected TmfTimestamp fEffectiveTimestamp; |
39 | protected TmfTimestamp fOriginalTimestamp; | |
40 | protected TmfEventSource fSource; | |
41 | protected TmfEventType fType; | |
42 | protected TmfEventReference fReference; | |
8c8bf09f | 43 | |
28b94d61 FC |
44 | // Content requires a reference to the parent event so it is initialized |
45 | // using setContent() | |
46 | protected TmfEventContent fContent; | |
47 | ||
48 | // ======================================================================== | |
8c8bf09f | 49 | // Constructors |
4ab33d2b | 50 | // ======================================================================== |
8c8bf09f ASL |
51 | |
52 | /** | |
28b94d61 FC |
53 | * @param originalTS |
54 | * @param effectiveTS | |
4ab33d2b AO |
55 | * @param source |
56 | * @param type | |
4ab33d2b | 57 | * @param reference |
8c8bf09f | 58 | */ |
28b94d61 FC |
59 | public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, |
60 | TmfEventSource source, TmfEventType type, TmfEventReference reference) | |
8c8bf09f | 61 | { |
28b94d61 | 62 | fOriginalTimestamp = originalTS; |
1f506a43 | 63 | fEffectiveTimestamp = effectiveTS; |
28b94d61 FC |
64 | fSource = source; |
65 | fType = type; | |
66 | fReference = reference; | |
1f506a43 FC |
67 | } |
68 | ||
69 | /** | |
70 | * @param timestamp | |
71 | * @param source | |
72 | * @param type | |
1f506a43 FC |
73 | * @param reference |
74 | */ | |
75 | public TmfEvent(TmfTimestamp timestamp, TmfEventSource source, | |
28b94d61 | 76 | TmfEventType type, TmfEventReference reference) |
1f506a43 | 77 | { |
28b94d61 | 78 | this(timestamp, timestamp, source, type, reference); |
4e3aa37d FC |
79 | } |
80 | ||
81 | /** | |
28b94d61 FC |
82 | * Copy constructor (shallow) |
83 | * | |
84 | * @param other | |
4e3aa37d | 85 | */ |
28b94d61 FC |
86 | public TmfEvent(TmfEvent other) { |
87 | assert(other != null); | |
88 | fOriginalTimestamp = other.fOriginalTimestamp; | |
89 | fEffectiveTimestamp = other.fEffectiveTimestamp; | |
90 | fSource = other.fSource; | |
91 | fType = other.fType; | |
92 | fContent = other.fContent; | |
93 | fReference = other.fReference; | |
94 | } | |
95 | ||
96 | @SuppressWarnings("unused") | |
97 | private TmfEvent() { | |
8c8bf09f ASL |
98 | } |
99 | ||
4ab33d2b | 100 | // ======================================================================== |
8c8bf09f | 101 | // Accessors |
4ab33d2b | 102 | // ======================================================================== |
8c8bf09f ASL |
103 | |
104 | /** | |
4ab33d2b | 105 | * @return |
8c8bf09f ASL |
106 | */ |
107 | public TmfTimestamp getTimestamp() { | |
1f506a43 FC |
108 | return fEffectiveTimestamp; |
109 | } | |
110 | ||
111 | /** | |
112 | * @return | |
113 | */ | |
114 | public TmfTimestamp getOriginalTimestamp() { | |
115 | return fOriginalTimestamp; | |
8c8bf09f ASL |
116 | } |
117 | ||
118 | /** | |
4ab33d2b | 119 | * @return |
8c8bf09f ASL |
120 | */ |
121 | public TmfEventSource getSource() { | |
122 | return fSource; | |
123 | } | |
124 | ||
125 | /** | |
4ab33d2b | 126 | * @return |
8c8bf09f ASL |
127 | */ |
128 | public TmfEventType getType() { | |
129 | return fType; | |
130 | } | |
131 | ||
28b94d61 FC |
132 | /** |
133 | * @return | |
134 | */ | |
135 | public void setContent(TmfEventContent content) { | |
136 | fContent = content; | |
137 | } | |
138 | ||
8c8bf09f | 139 | /** |
4ab33d2b | 140 | * @return |
8c8bf09f ASL |
141 | */ |
142 | public TmfEventContent getContent() { | |
143 | return fContent; | |
144 | } | |
145 | ||
146 | /** | |
4ab33d2b | 147 | * @return |
8c8bf09f ASL |
148 | */ |
149 | public TmfEventReference getReference() { | |
150 | return fReference; | |
151 | } | |
1f506a43 | 152 | |
28b94d61 FC |
153 | // ======================================================================== |
154 | // Operators | |
155 | // ======================================================================== | |
156 | ||
157 | @Override | |
158 | public TmfEvent clone() { | |
159 | TmfEvent event = new TmfEvent( | |
160 | fOriginalTimestamp.clone(), | |
161 | fEffectiveTimestamp.clone(), | |
162 | fSource.clone(), | |
163 | fType.clone(), | |
164 | fReference.clone()); | |
165 | TmfEventContent content = fContent.clone(); | |
166 | event.setContent(content); | |
167 | return event; | |
168 | } | |
169 | ||
4e3aa37d FC |
170 | // TODO: Design a proper format... |
171 | @Override | |
172 | public String toString() { | |
173 | return fEffectiveTimestamp.toString(); | |
174 | } | |
8c8bf09f | 175 | } |