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