1 | package de.ugoe.cs.eventbench.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.eventbench.CommandHelpers;
|
---|
9 | import de.ugoe.cs.eventbench.ReplayGenerator;
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
12 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
13 | import de.ugoe.cs.util.console.Command;
|
---|
14 | import de.ugoe.cs.util.console.Console;
|
---|
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 void help() {
|
---|
33 | Console.println("Usage: 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 | @SuppressWarnings("unchecked")
|
---|
42 | @Override
|
---|
43 | public void run(List<Object> parameters) {
|
---|
44 | String modelname;
|
---|
45 | String filename;
|
---|
46 | int numSessions = 1;
|
---|
47 | try {
|
---|
48 | modelname = (String) parameters.get(0);
|
---|
49 | filename = (String) parameters.get(1);
|
---|
50 | if (parameters.size() < 3) {
|
---|
51 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
52 | }
|
---|
53 | } catch (Exception e) {
|
---|
54 | throw new InvalidParameterException();
|
---|
55 | }
|
---|
56 |
|
---|
57 | IStochasticProcess model = null;
|
---|
58 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
59 | .getData(modelname);
|
---|
60 | if (dataObject == null) {
|
---|
61 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
62 | return;
|
---|
63 | }
|
---|
64 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
65 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 | model = (IStochasticProcess) dataObject;
|
---|
69 | Collection<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>();
|
---|
70 | try {
|
---|
71 | for (int i = 0; i < numSessions; i++) {
|
---|
72 | sequences
|
---|
73 | .add((List<ReplayableEvent<?>>) model.randomSequence());
|
---|
74 | }
|
---|
75 | } catch (ClassCastException e) {
|
---|
76 | Console.println("Modeled events don't support replay.");
|
---|
77 | }
|
---|
78 | ReplayGenerator generator = new ReplayGenerator();
|
---|
79 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
80 | }
|
---|
81 |
|
---|
82 | }
|
---|