Commit a2bcf7eb authored by Jaime Arias's avatar Jaime Arias
Browse files

feature: add scheduling tables to service response

parent 1c1af04c
...@@ -5,6 +5,7 @@ import java.io.BufferedWriter; ...@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -40,15 +41,17 @@ public class MinimalScheduling extends BinaryService { ...@@ -40,15 +41,17 @@ public class MinimalScheduling extends BinaryService {
formalism = "http://formalisms.cosyverif.org/adtree.fml") formalism = "http://formalisms.cosyverif.org/adtree.fml")
private Model modelParameter; private Model modelParameter;
@Parameter(name = "Scheduling Table", @Parameter(name = "Scheduling Information", help = "Scheduling information for each generated graph.",
help = "String parameter help message.", direction = Direction.OUT,
direction = Direction.OUT, multiline = true)
multiline = true)
private String outputParameter = ""; private String outputParameter = "";
@Parameter(name = "Number of graphs", help = "String parameter help message.", direction = Direction.OUT) @Parameter(name = "Number of graphs", help = "Number of graphs generated by the counter nodes", direction = Direction.OUT)
private int nGraphs = 0; private int nGraphs = 0;
@Parameter(name = "Scheduling Table", help = "Formatted table with the minimal scheduling", direction = Direction.OUT, contenttype = "plain/text")
private File outputTables = null;
@Launch @Launch
public Task executeBinary() throws IOException { public Task executeBinary() throws IOException {
parser = GrmlParser.create(modelParameter); parser = GrmlParser.create(modelParameter);
...@@ -69,6 +72,7 @@ public class MinimalScheduling extends BinaryService { ...@@ -69,6 +72,7 @@ public class MinimalScheduling extends BinaryService {
public void fallback(String line){ public void fallback(String line){
try{ try{
outputParameter = formatResult(model); outputParameter = formatResult(model);
outputTables = getTables();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -106,10 +110,11 @@ public class MinimalScheduling extends BinaryService { ...@@ -106,10 +110,11 @@ public class MinimalScheduling extends BinaryService {
while (this.nGraphs > 0 && (line = br.readLine()) != null) { while (this.nGraphs > 0 && (line = br.readLine()) != null) {
// find a graph info // find a graph info
if (line.startsWith("Graph #") || line.startsWith("# Agents:") || line.startsWith("# Slots:")) { if (line.startsWith("Graph #")) {
if (line.startsWith("#")) { s.append(line + " => ");
s.append(" - "); } else if (line.startsWith("# Agents:")) {
} s.append(line + " - ");
} else if (line.startsWith("# Slots:")) {
s.append(line); s.append(line);
} }
...@@ -118,7 +123,7 @@ public class MinimalScheduling extends BinaryService { ...@@ -118,7 +123,7 @@ public class MinimalScheduling extends BinaryService {
s.append("\n"); s.append("\n");
} }
} }
fw.append("data:\n" + s); fw.append("data:\n" + s + "\n");
} catch (Exception e) { } catch (Exception e) {
fw.append("error: " + e.getMessage() + "\n"); fw.append("error: " + e.getMessage() + "\n");
e.printStackTrace(); e.printStackTrace();
...@@ -134,6 +139,59 @@ public class MinimalScheduling extends BinaryService { ...@@ -134,6 +139,59 @@ public class MinimalScheduling extends BinaryService {
return s.toString(); return s.toString();
} }
private File getTables() throws IOException {
File fileOutput = null;
BufferedWriter bw = null;
FileWriter fw = null;
String line;
BufferedReader br = null;
FileReader fr = null;
File directory = new File(baseDirectory().getAbsolutePath());
File[] files = {};
try {
files = directory.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".txt") && !name.equals("tables.txt");
}
});
fileOutput = new File(baseDirectory().getAbsolutePath() + "/tables.txt");
fw = new FileWriter(fileOutput);
bw = new BufferedWriter(fw);
for (File f : files) {
bw.write(f.getName() + "\n");
fr = new FileReader(f);
br = new BufferedReader(fr);
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
bw.newLine();
fr.close();
br.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
if (br != null)
br.close();
if (fr != null)
fr.close();
}
return fileOutput;
}
@Example(name = "Example of the minimal scheduling algorithm", @Example(name = "Example of the minimal scheduling algorithm",
help = "Example of the minimal scheduling algorithm") help = "Example of the minimal scheduling algorithm")
public MinimalScheduling example() { public MinimalScheduling example() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment