1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.ReplayGenerator;
|
---|
8 | import de.ugoe.cs.eventbench.SequenceInstanceOf;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Command to create a replay file from stored sessions.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDgenerateReplayfile implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void help() {
|
---|
31 | Console.println("Usage: generateReplayfile <filename> {<sequences>}");
|
---|
32 | }
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * (non-Javadoc)
|
---|
36 | *
|
---|
37 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
38 | */
|
---|
39 | @SuppressWarnings("unchecked")
|
---|
40 | @Override
|
---|
41 | public void run(List<Object> parameters) {
|
---|
42 | if (parameters.size() < 1) {
|
---|
43 | throw new InvalidParameterException();
|
---|
44 | }
|
---|
45 | String filename = (String) parameters.get(0);
|
---|
46 | String sequencesName = "sequences";
|
---|
47 | if (parameters.size() == 2) {
|
---|
48 | sequencesName = (String) parameters.get(1);
|
---|
49 | }
|
---|
50 |
|
---|
51 | Collection<List<ReplayableEvent<?>>> sequences = null;
|
---|
52 | Object dataObject = GlobalDataContainer.getInstance().getData(
|
---|
53 | sequencesName);
|
---|
54 | if (dataObject == null) {
|
---|
55 | Console.println("Object " + sequencesName
|
---|
56 | + " not found in storage.");
|
---|
57 | return;
|
---|
58 | }
|
---|
59 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
60 | Console.println("Object " + sequencesName
|
---|
61 | + "not of type Collection<List<Event<?>>>.");
|
---|
62 | return;
|
---|
63 | }
|
---|
64 |
|
---|
65 | sequences = (Collection<List<ReplayableEvent<?>>>) dataObject;
|
---|
66 | ReplayGenerator generator = new ReplayGenerator();
|
---|
67 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|