1 | package de.ugoe.cs.quest.ui.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
9 | import de.ugoe.cs.quest.ReplayGenerator;
|
---|
10 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
11 | import de.ugoe.cs.quest.usageprofiles.IStochasticProcess;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * <p>
|
---|
18 | * Command to create a replay file with randomly generated sessions.
|
---|
19 | * </p>
|
---|
20 | *
|
---|
21 | * @author Steffen Herbold
|
---|
22 | * @version 1.0
|
---|
23 | */
|
---|
24 | public class CMDgenerateRandomReplay implements Command {
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * (non-Javadoc)
|
---|
28 | *
|
---|
29 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public String help() {
|
---|
33 | return "generateRandomReplay <modelName> <filename> {<numSessions>}";
|
---|
34 | }
|
---|
35 |
|
---|
36 | /*
|
---|
37 | * (non-Javadoc)
|
---|
38 | *
|
---|
39 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
40 | */
|
---|
41 | @Override
|
---|
42 | public void run(List<Object> parameters) {
|
---|
43 | String modelname;
|
---|
44 | String filename;
|
---|
45 | int numSessions = 1;
|
---|
46 | try {
|
---|
47 | modelname = (String) parameters.get(0);
|
---|
48 | filename = (String) parameters.get(1);
|
---|
49 | if (parameters.size() < 3) {
|
---|
50 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
51 | }
|
---|
52 | } catch (Exception e) {
|
---|
53 | throw new InvalidParameterException();
|
---|
54 | }
|
---|
55 |
|
---|
56 | IStochasticProcess model = null;
|
---|
57 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
58 | .getData(modelname);
|
---|
59 | if (dataObject == null) {
|
---|
60 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
64 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | model = (IStochasticProcess) dataObject;
|
---|
68 | Collection<List<Event>> sequences = new LinkedList<List<Event>>();
|
---|
69 | try {
|
---|
70 | for (int i = 0; i < numSessions; i++) {
|
---|
71 | sequences
|
---|
72 | .add((List<Event>) model.randomSequence());
|
---|
73 | }
|
---|
74 | } catch (ClassCastException e) {
|
---|
75 | Console.printerrln("Modeled events don't support replay.");
|
---|
76 | }
|
---|
77 | ReplayGenerator generator = new ReplayGenerator();
|
---|
78 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|