source: trunk/EventBenchCore/src/de/ugoe/cs/eventbench/data/ReplayableEvent.java @ 405

Last change on this file since 405 was 405, checked in by sherbold, 12 years ago
  • updated de.ugoe.cs.eventbench.data.ReplayableEvent? such that equals does not take the replay messages into account anymore.
File size: 4.0 KB
Line 
1package de.ugoe.cs.eventbench.data;
2
3import java.security.InvalidParameterException;
4import java.util.LinkedList;
5import java.util.List;
6
7import de.ugoe.cs.eventbench.IReplayDecorator;
8
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 */
24public class ReplayableEvent<T extends IReplayable> extends Event<T> {
25
26        /**
27         * Id for object serialization.
28         */
29        private static final long serialVersionUID = 1L;
30
31        /**
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         */
38        protected List<T> replayEvents = new LinkedList<T>();;
39
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         */
47        protected boolean replayValid = true;
48
49        /**
50         * <p>
51         * {@link IReplayDecorator} used when replays of this type are written.
52         * </p>
53         */
54        protected IReplayDecorator decorator = null;
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         */
65        public ReplayableEvent(String type) {
66                super(type);
67        }
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
76         * @throws InvalidParameterException
77         *             thrown is replayable is null
78         */
79        public void addReplayEvent(T replayable) {
80                if (replayable == null) {
81                        throw new InvalidParameterException("replayble must not be null");
82                }
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
93         * @throws InvalidParameterException
94         *             thrown if generatedReplaySeq is null
95         */
96        public void addReplaySequence(List<T> generatedReplaySeq) {
97                if (generatedReplaySeq == null) {
98                        throw new InvalidParameterException(
99                                        "generatedReplaySeq must not be null");
100                }
101                replayEvents.addAll(generatedReplaySeq);
102        }
103
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;
114        }
115
116        /**
117         * <p>
118         * Returns a the list of replay events.
119         * </p>
120         * <p>
121         * The return value is a copy of the list used internally!
122         * </p>
123         *
124         * @return list of replay events.
125         */
126        public List<T> getReplayMessages() {
127                return new LinkedList<T>(replayEvents);
128        }
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         */
137        public boolean hasValidReplay() {
138                return replayValid;
139        }
140
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         */
147        public void invalidateReplay() {
148                replayValid = false;
149        }
150
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         */
159        public void setDecorator(IReplayDecorator decorator) {
160                this.decorator = decorator;
161        }
162       
163        @Override
164        public boolean canEqual(Object other) {
165                return (other instanceof ReplayableEvent<?>);
166        }
167}
Note: See TracBrowser for help on using the repository browser.