1 | package de.ugoe.cs.eventbench.jfc.commands;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.security.InvalidParameterException;
|
---|
5 | import java.util.Collection;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.jfc.JFCLogParser;
|
---|
11 | import de.ugoe.cs.eventbench.jfc.data.JFCEvent;
|
---|
12 | import de.ugoe.cs.eventbench.jfc.data.JFCTargetComparator;
|
---|
13 | import de.ugoe.cs.util.console.Command;
|
---|
14 | import de.ugoe.cs.util.console.Console;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * <p>
|
---|
18 | * Command that tries to parse all files in a folder as if they were log files
|
---|
19 | * generated by the JFCMonitor. The result is one set of sequences for all files
|
---|
20 | * (not one set of sequences for each file!).
|
---|
21 | * </p>
|
---|
22 | *
|
---|
23 | * @author Steffen Herbold
|
---|
24 | * @version 1.0
|
---|
25 | */
|
---|
26 | public class CMDparseDirJFC implements Command {
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * (non-Javadoc)
|
---|
30 | *
|
---|
31 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
32 | */
|
---|
33 | @Override
|
---|
34 | public void run(List<Object> parameters) {
|
---|
35 | String path;
|
---|
36 | String sequencesName = "sequences";
|
---|
37 |
|
---|
38 | try {
|
---|
39 | path = (String) parameters.get(0);
|
---|
40 | if (parameters.size() >= 2) {
|
---|
41 | sequencesName = (String) parameters.get(1);
|
---|
42 | }
|
---|
43 | } catch (Exception e) {
|
---|
44 | throw new InvalidParameterException();
|
---|
45 | }
|
---|
46 |
|
---|
47 | File folder = new File(path);
|
---|
48 | if (!folder.isDirectory()) {
|
---|
49 | Console.printerrln(path + " is not a directory");
|
---|
50 | return;
|
---|
51 | }
|
---|
52 |
|
---|
53 | JFCTargetComparator.setMutable(true);
|
---|
54 | JFCLogParser parser = new JFCLogParser();
|
---|
55 |
|
---|
56 | String absolutPath = folder.getAbsolutePath();
|
---|
57 | for (String filename : folder.list()) {
|
---|
58 | String source = absolutPath + "/" + filename;
|
---|
59 | Console.traceln("Processing file: " + source);
|
---|
60 |
|
---|
61 | parser.parseFile(source);
|
---|
62 | }
|
---|
63 |
|
---|
64 | Collection<List<JFCEvent>> sequences = parser.getSequences();
|
---|
65 | Console.traceln("Pre-computing event target equalities.");
|
---|
66 | // compare all Events to a dummy event to make sure they are known by
|
---|
67 | // the JFCTargetComparator
|
---|
68 | JFCEvent dummyEvent = new JFCEvent("dummy");
|
---|
69 | for (List<JFCEvent> sequence : sequences) {
|
---|
70 | for (JFCEvent event : sequence) {
|
---|
71 | event.equals(dummyEvent);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | JFCTargetComparator.setMutable(false);
|
---|
75 |
|
---|
76 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
77 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * (non-Javadoc)
|
---|
84 | *
|
---|
85 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
86 | */
|
---|
87 | @Override
|
---|
88 | public void help() {
|
---|
89 | Console.println("Usage: parseDirJFC <path> {<sequencesName>}");
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|