[1] | 1 | package de.ugoe.cs.eventbench.data;
|
---|
| 2 |
|
---|
[336] | 3 | import java.security.InvalidParameterException;
|
---|
[1] | 4 | import java.util.LinkedList;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
[57] | 7 | import de.ugoe.cs.eventbench.IReplayDecorator;
|
---|
| 8 |
|
---|
[79] | 9 | /**
|
---|
| 10 | * <p>
|
---|
| 11 | * Subclass of {@link Event} for events that contain all informations required
|
---|
| 12 | * for replaying them, i.e., generating scripts that can used for automated
|
---|
| 13 | * software execution.
|
---|
| 14 | * </p>
|
---|
| 15 | *
|
---|
| 16 | * @author Steffen Herbold
|
---|
| 17 | * @version 1.0
|
---|
| 18 | *
|
---|
| 19 | * @param <T>
|
---|
| 20 | * Allows only types that extend {@link IReplayable} and is used to
|
---|
| 21 | * define a list of replayables that describe the replay of the
|
---|
| 22 | * event.
|
---|
| 23 | */
|
---|
[1] | 24 | public class ReplayableEvent<T extends IReplayable> extends Event<T> {
|
---|
| 25 |
|
---|
[79] | 26 | /**
|
---|
[86] | 27 | * Id for object serialization.
|
---|
| 28 | */
|
---|
| 29 | private static final long serialVersionUID = 1L;
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
[79] | 32 | * <p>
|
---|
| 33 | * List of {@link IReplayable}s of type T that describes the replay of an
|
---|
| 34 | * event. The {@link IReplayable}s can be interpreted as <it>sub-events</it>
|
---|
| 35 | * on the platform level that make up the abstract event.
|
---|
| 36 | * </p>
|
---|
| 37 | */
|
---|
[335] | 38 | protected List<T> replayEvents = new LinkedList<T>();;
|
---|
[1] | 39 |
|
---|
[79] | 40 | /**
|
---|
| 41 | * <p>
|
---|
| 42 | * Defines whether the replay is valid or invalid. It may be invalid, e.g.,
|
---|
| 43 | * due to errors during the generation of the event or lack of vital
|
---|
| 44 | * information.
|
---|
| 45 | * </p>
|
---|
| 46 | */
|
---|
[335] | 47 | protected boolean replayValid = true;
|
---|
[79] | 48 |
|
---|
| 49 | /**
|
---|
| 50 | * <p>
|
---|
| 51 | * {@link IReplayDecorator} used when replays of this type are written.
|
---|
| 52 | * </p>
|
---|
| 53 | */
|
---|
[335] | 54 | protected IReplayDecorator decorator = null;
|
---|
[79] | 55 |
|
---|
| 56 | /**
|
---|
| 57 | * <p>
|
---|
| 58 | * Constructor. Creates a new event with the given type.
|
---|
| 59 | * <p>
|
---|
| 60 | *
|
---|
| 61 | * @param type
|
---|
| 62 | * type of the event
|
---|
| 63 | * @see Event#Event(String)
|
---|
| 64 | */
|
---|
[1] | 65 | public ReplayableEvent(String type) {
|
---|
| 66 | super(type);
|
---|
| 67 | }
|
---|
[79] | 68 |
|
---|
| 69 | /**
|
---|
| 70 | * <p>
|
---|
| 71 | * Adds a new {@link IReplayable} of type T to the replay sequence.
|
---|
| 72 | * </p>
|
---|
| 73 | *
|
---|
| 74 | * @param replayable
|
---|
| 75 | * element that is added to the sequence
|
---|
[336] | 76 | * @throws InvalidParameterException
|
---|
| 77 | * thrown is replayable is null
|
---|
[79] | 78 | */
|
---|
| 79 | public void addReplayEvent(T replayable) {
|
---|
[336] | 80 | if (replayable == null) {
|
---|
| 81 | throw new InvalidParameterException("replayble must not be null");
|
---|
| 82 | }
|
---|
[79] | 83 | replayEvents.add(replayable);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * <p>
|
---|
| 88 | * Adds a {@link List}ist of {@link IReplayable} to the replay sequence.
|
---|
| 89 | * </p>
|
---|
| 90 | *
|
---|
| 91 | * @param generatedReplaySeq
|
---|
| 92 | * {@link List} that is added to the sequence
|
---|
[336] | 93 | * @throws InvalidParameterException
|
---|
| 94 | * thrown if generatedReplaySeq is null
|
---|
[79] | 95 | */
|
---|
[1] | 96 | public void addReplaySequence(List<T> generatedReplaySeq) {
|
---|
[336] | 97 | if (generatedReplaySeq == null) {
|
---|
| 98 | throw new InvalidParameterException(
|
---|
| 99 | "generatedReplaySeq must not be null");
|
---|
| 100 | }
|
---|
[1] | 101 | replayEvents.addAll(generatedReplaySeq);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[79] | 104 | /**
|
---|
| 105 | * <p>
|
---|
| 106 | * Returns the {@link IReplayDecorator} of the event.
|
---|
| 107 | * </p>
|
---|
| 108 | *
|
---|
| 109 | * @return {@link IReplayDecorator} of the event; null if no decorator has
|
---|
| 110 | * been set
|
---|
| 111 | */
|
---|
| 112 | public IReplayDecorator getReplayDecorator() {
|
---|
| 113 | return decorator;
|
---|
[1] | 114 | }
|
---|
[79] | 115 |
|
---|
[1] | 116 | /**
|
---|
| 117 | * <p>
|
---|
| 118 | * Returns a the list of replay events.
|
---|
[79] | 119 | * </p>
|
---|
[1] | 120 | * <p>
|
---|
| 121 | * The return value is a copy of the list used internally!
|
---|
| 122 | * </p>
|
---|
[79] | 123 | *
|
---|
| 124 | * @return list of replay events.
|
---|
[1] | 125 | */
|
---|
| 126 | public List<T> getReplayMessages() {
|
---|
| 127 | return new LinkedList<T>(replayEvents);
|
---|
| 128 | }
|
---|
[79] | 129 |
|
---|
| 130 | /**
|
---|
| 131 | * <p>
|
---|
| 132 | * Returns whether the replay is valid or not.
|
---|
| 133 | * </p>
|
---|
| 134 | *
|
---|
| 135 | * @return true, if replay is valid; false otherwise.
|
---|
| 136 | */
|
---|
[1] | 137 | public boolean hasValidReplay() {
|
---|
| 138 | return replayValid;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[79] | 141 | /**
|
---|
| 142 | * <p>
|
---|
| 143 | * Marks the replay as invalid. Once marked as invalid, it remains so and
|
---|
| 144 | * cannot be changed back to valid.
|
---|
| 145 | * </p>
|
---|
| 146 | */
|
---|
[1] | 147 | public void invalidateReplay() {
|
---|
| 148 | replayValid = false;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[79] | 151 | /**
|
---|
| 152 | * <p>
|
---|
| 153 | * Sets the {@link IReplayDecorator} associated with the event.
|
---|
| 154 | * </p>
|
---|
| 155 | *
|
---|
| 156 | * @param decorator
|
---|
| 157 | * decorator associated with the event
|
---|
| 158 | */
|
---|
[57] | 159 | public void setDecorator(IReplayDecorator decorator) {
|
---|
| 160 | this.decorator = decorator;
|
---|
| 161 | }
|
---|
[1] | 162 |
|
---|
[336] | 163 | /*
|
---|
| 164 | * (non-Javadoc)
|
---|
| 165 | *
|
---|
[108] | 166 | * @see de.ugoe.cs.eventbench.data.Event#equals(java.lang.Object)
|
---|
| 167 | */
|
---|
| 168 | @Override
|
---|
| 169 | public boolean equals(Object other) {
|
---|
| 170 | if (this == other) {
|
---|
| 171 | return true;
|
---|
| 172 | }
|
---|
| 173 | if (other instanceof ReplayableEvent<?>) {
|
---|
| 174 | ReplayableEvent<?> otherEvent = (ReplayableEvent<?>) other;
|
---|
[336] | 175 | if (replayEvents != null) {
|
---|
| 176 | return super.equals(otherEvent)
|
---|
| 177 | && replayEvents.equals(otherEvent.replayEvents)
|
---|
| 178 | && replayValid == otherEvent.replayValid;
|
---|
| 179 | } else {
|
---|
| 180 | return super.equals(otherEvent)
|
---|
| 181 | && otherEvent.replayEvents == null
|
---|
| 182 | && replayValid == otherEvent.replayValid;
|
---|
| 183 | }
|
---|
[108] | 184 |
|
---|
| 185 | } else {
|
---|
| 186 | return false;
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[336] | 190 | @Override
|
---|
| 191 | public boolean canEqual(Object other) {
|
---|
| 192 | return (other instanceof ReplayableEvent<?>);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | /*
|
---|
| 196 | * (non-Javadoc)
|
---|
| 197 | *
|
---|
[108] | 198 | * @see de.ugoe.cs.eventbench.data.Event#hashCode()
|
---|
| 199 | */
|
---|
| 200 | @Override
|
---|
| 201 | public int hashCode() {
|
---|
| 202 | int multiplier = 17;
|
---|
| 203 | int hash = super.hashCode();
|
---|
[336] | 204 | if (replayEvents != null) {
|
---|
| 205 | hash = multiplier * hash + replayEvents.hashCode();
|
---|
| 206 | }
|
---|
[108] | 207 | hash = multiplier * hash + (replayValid ? 1 : 0);
|
---|
| 208 |
|
---|
| 209 | return hash;
|
---|
| 210 | }
|
---|
[1] | 211 | }
|
---|