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