1 | package de.ugoe.cs.eventbench.data;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.IReplayDecorator;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * <p>
|
---|
10 | * Subclass of {@link Event} for events that contain all informations required
|
---|
11 | * for replaying them, i.e., generating scripts that can used for automated
|
---|
12 | * software execution.
|
---|
13 | * </p>
|
---|
14 | *
|
---|
15 | * @author Steffen Herbold
|
---|
16 | * @version 1.0
|
---|
17 | *
|
---|
18 | * @param <T>
|
---|
19 | * Allows only types that extend {@link IReplayable} and is used to
|
---|
20 | * define a list of replayables that describe the replay of the
|
---|
21 | * event.
|
---|
22 | */
|
---|
23 | public class ReplayableEvent<T extends IReplayable> extends Event<T> {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Id for object serialization.
|
---|
27 | */
|
---|
28 | private static final long serialVersionUID = 1L;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * List of {@link IReplayable}s of type T that describes the replay of an
|
---|
33 | * event. The {@link IReplayable}s can be interpreted as <it>sub-events</it>
|
---|
34 | * on the platform level that make up the abstract event.
|
---|
35 | * </p>
|
---|
36 | */
|
---|
37 | private List<T> replayEvents = new LinkedList<T>();;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * <p>
|
---|
41 | * Defines whether the replay is valid or invalid. It may be invalid, e.g.,
|
---|
42 | * due to errors during the generation of the event or lack of vital
|
---|
43 | * information.
|
---|
44 | * </p>
|
---|
45 | */
|
---|
46 | private boolean replayValid = true;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * <p>
|
---|
50 | * {@link IReplayDecorator} used when replays of this type are written.
|
---|
51 | * </p>
|
---|
52 | */
|
---|
53 | private IReplayDecorator decorator = null;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * <p>
|
---|
57 | * Constructor. Creates a new event with the given type.
|
---|
58 | * <p>
|
---|
59 | *
|
---|
60 | * @param type
|
---|
61 | * type of the event
|
---|
62 | * @see Event#Event(String)
|
---|
63 | */
|
---|
64 | public ReplayableEvent(String type) {
|
---|
65 | super(type);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * <p>
|
---|
70 | * Adds a new {@link IReplayable} of type T to the replay sequence.
|
---|
71 | * </p>
|
---|
72 | *
|
---|
73 | * @param replayable
|
---|
74 | * element that is added to the sequence
|
---|
75 | */
|
---|
76 | public void addReplayEvent(T replayable) {
|
---|
77 | replayEvents.add(replayable);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * <p>
|
---|
82 | * Adds a {@link List}ist of {@link IReplayable} to the replay sequence.
|
---|
83 | * </p>
|
---|
84 | *
|
---|
85 | * @param generatedReplaySeq
|
---|
86 | * {@link List} that is added to the sequence
|
---|
87 | */
|
---|
88 | public void addReplaySequence(List<T> generatedReplaySeq) {
|
---|
89 | replayEvents.addAll(generatedReplaySeq);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * <p>
|
---|
94 | * Returns the {@link IReplayDecorator} of the event.
|
---|
95 | * </p>
|
---|
96 | *
|
---|
97 | * @return {@link IReplayDecorator} of the event; null if no decorator has
|
---|
98 | * been set
|
---|
99 | */
|
---|
100 | public IReplayDecorator getReplayDecorator() {
|
---|
101 | return decorator;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * <p>
|
---|
106 | * Returns a the list of replay events.
|
---|
107 | * </p>
|
---|
108 | * <p>
|
---|
109 | * The return value is a copy of the list used internally!
|
---|
110 | * </p>
|
---|
111 | *
|
---|
112 | * @return list of replay events.
|
---|
113 | */
|
---|
114 | public List<T> getReplayMessages() {
|
---|
115 | return new LinkedList<T>(replayEvents);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * <p>
|
---|
120 | * Returns whether the replay is valid or not.
|
---|
121 | * </p>
|
---|
122 | *
|
---|
123 | * @return true, if replay is valid; false otherwise.
|
---|
124 | */
|
---|
125 | public boolean hasValidReplay() {
|
---|
126 | return replayValid;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * <p>
|
---|
131 | * Marks the replay as invalid. Once marked as invalid, it remains so and
|
---|
132 | * cannot be changed back to valid.
|
---|
133 | * </p>
|
---|
134 | */
|
---|
135 | public void invalidateReplay() {
|
---|
136 | replayValid = false;
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * <p>
|
---|
141 | * Sets the {@link IReplayDecorator} associated with the event.
|
---|
142 | * </p>
|
---|
143 | *
|
---|
144 | * @param decorator
|
---|
145 | * decorator associated with the event
|
---|
146 | */
|
---|
147 | public void setDecorator(IReplayDecorator decorator) {
|
---|
148 | this.decorator = decorator;
|
---|
149 | }
|
---|
150 |
|
---|
151 | }
|
---|