| 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: |
| 10 | * Francois Chouinard - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.event; |
| 14 | |
| 15 | /** |
| 16 | * <b><u>TmfEvent</u></b> |
| 17 | * <p> |
| 18 | * The basic event structure in the TMF. In its canonical form, an event has: |
| 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. |
| 28 | * |
| 29 | * Notice that for performance reasons TmfEvent is NOT immutable. If a copy |
| 30 | * of the event is needed, use the copy constructor. |
| 31 | */ |
| 32 | public class TmfEvent extends TmfData { |
| 33 | |
| 34 | // ------------------------------------------------------------------------ |
| 35 | // Constants |
| 36 | // ------------------------------------------------------------------------ |
| 37 | |
| 38 | public static final TmfEvent NullEvent = new TmfEvent(); |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | // Attributes |
| 42 | // ------------------------------------------------------------------------ |
| 43 | |
| 44 | protected TmfTimestamp fEffectiveTimestamp; |
| 45 | protected TmfTimestamp fOriginalTimestamp; |
| 46 | protected TmfEventSource fSource; |
| 47 | protected TmfEventType fType; |
| 48 | protected TmfEventReference fReference; |
| 49 | |
| 50 | // Content requires a reference to the parent event so it is initialized |
| 51 | // using setContent() |
| 52 | protected TmfEventContent fContent; |
| 53 | |
| 54 | // ------------------------------------------------------------------------ |
| 55 | // Constructors |
| 56 | // ------------------------------------------------------------------------ |
| 57 | |
| 58 | /** |
| 59 | * @param originalTS the original timestamp |
| 60 | * @param effectiveTS the effective timestamp |
| 61 | * @param source the event source (generator) |
| 62 | * @param type the event type |
| 63 | * @param reference a free-form reference field |
| 64 | */ |
| 65 | public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, |
| 66 | TmfEventSource source, TmfEventType type, TmfEventReference reference) |
| 67 | { |
| 68 | fOriginalTimestamp = originalTS; |
| 69 | fEffectiveTimestamp = effectiveTS; |
| 70 | fSource = source; |
| 71 | fType = type; |
| 72 | fReference = reference; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @param timestamp the effective timestamp |
| 77 | * @param source the event source (generator) |
| 78 | * @param type the event type |
| 79 | * @param reference a free-form reference field |
| 80 | */ |
| 81 | public TmfEvent(TmfTimestamp timestamp, TmfEventSource source, |
| 82 | TmfEventType type, TmfEventReference reference) |
| 83 | { |
| 84 | this(timestamp, timestamp, source, type, reference); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Copy constructor |
| 89 | * |
| 90 | * @param other the original event |
| 91 | */ |
| 92 | public TmfEvent(TmfEvent other) { |
| 93 | if (other == null) |
| 94 | throw new IllegalArgumentException(); |
| 95 | fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp); |
| 96 | fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp); |
| 97 | fSource = new TmfEventSource(other.fSource); |
| 98 | fType = new TmfEventType(other.fType); |
| 99 | fContent = new TmfEventContent(other.fContent); |
| 100 | fReference = new TmfEventReference(other.fReference); |
| 101 | } |
| 102 | |
| 103 | private TmfEvent() { |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public boolean isNullRef() { |
| 108 | return this == NullEvent; |
| 109 | } |
| 110 | |
| 111 | // ------------------------------------------------------------------------ |
| 112 | // Accessors |
| 113 | // ------------------------------------------------------------------------ |
| 114 | |
| 115 | /** |
| 116 | * @return the effective event timestamp |
| 117 | */ |
| 118 | public TmfTimestamp getTimestamp() { |
| 119 | return fEffectiveTimestamp; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @return the original event timestamp |
| 124 | */ |
| 125 | public TmfTimestamp getOriginalTimestamp() { |
| 126 | return fOriginalTimestamp; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @return the event source |
| 131 | */ |
| 132 | public TmfEventSource getSource() { |
| 133 | return fSource; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @return the event type |
| 138 | */ |
| 139 | public TmfEventType getType() { |
| 140 | return fType; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @return the event content |
| 145 | */ |
| 146 | public TmfEventContent getContent() { |
| 147 | return fContent; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @return the event reference |
| 152 | */ |
| 153 | public TmfEventReference getReference() { |
| 154 | return fReference; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @param content the new event content |
| 159 | */ |
| 160 | public void setContent(TmfEventContent content) { |
| 161 | fContent = content; |
| 162 | } |
| 163 | |
| 164 | // ------------------------------------------------------------------------ |
| 165 | // Object |
| 166 | // ------------------------------------------------------------------------ |
| 167 | |
| 168 | @Override |
| 169 | public int hashCode() { |
| 170 | int result = 17; |
| 171 | result = 37 * result + fSource.hashCode(); |
| 172 | result = 37 * result + fType.hashCode(); |
| 173 | result = 37 * result + fEffectiveTimestamp.hashCode(); |
| 174 | return result; |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public boolean equals(Object other) { |
| 179 | if (!(other instanceof TmfEvent)) |
| 180 | return false; |
| 181 | TmfEvent o = (TmfEvent) other; |
| 182 | return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && |
| 183 | fSource.equals(o.fSource) && |
| 184 | fType.equals(o.fType) && |
| 185 | fContent.equals(o.fContent); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public String toString() { |
| 190 | return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]"; |
| 191 | } |
| 192 | |
| 193 | } |