use of il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator in project BPjs by bThink-BGU.
the class ExternalEventsTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
final BEvent in1a = new BEvent("in1a");
final BEvent ext1 = new BEvent("ext1");
final BEvent in1b = new BEvent("in1b");
final SingleResourceBProgram bprog = new SingleResourceBProgram("ExternalEvents.js");
bprog.setEventSelectionStrategy(new LoggingEventSelectionStrategyDecorator(bprog.getEventSelectionStrategy()));
final BProgramRunner sut = new BProgramRunner(bprog);
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.getBProgram().enqueueExternalEvent(ext1);
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(in1a).append(ext1).append(in1b);
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator in project BPjs by bThink-BGU.
the class BPJsCliRunner method main.
public static void main(String[] args) {
if (args.length == 0) {
printUsageAndExit();
}
BProgram bpp = new BProgram("BPjs") {
@Override
protected void setupProgramScope(Scriptable scope) {
for (String arg : args) {
if (arg.equals("-")) {
println(" [READ] stdin");
try {
evaluate(System.in, "stdin");
} catch (EvaluatorException ee) {
logScriptExceptionAndQuit(ee, arg);
}
} else {
if (!arg.startsWith("-")) {
Path inFile = Paths.get(arg);
println(" [READ] %s", inFile.toAbsolutePath().toString());
if (!Files.exists(inFile)) {
println("File %s does not exit", inFile.toAbsolutePath().toString());
System.exit(-2);
}
try (InputStream in = Files.newInputStream(inFile)) {
evaluate(in, arg);
} catch (EvaluatorException ee) {
logScriptExceptionAndQuit(ee, arg);
} catch (IOException ex) {
println("Exception while processing " + arg + ": " + ex.getMessage());
Logger.getLogger(BPJsCliRunner.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
println(" [ OK ] %s", arg);
}
}
private void logScriptExceptionAndQuit(EvaluatorException ee, String arg) {
println("Error in source %s:", arg);
println(ee.details());
println("line: " + ee.lineNumber() + ":" + ee.columnNumber());
println("source: " + ee.lineSource());
System.exit(-3);
}
};
SimpleEventSelectionStrategy sess = new SimpleEventSelectionStrategy();
EventSelectionStrategy ess = switchPresent("-v", args) ? new LoggingEventSelectionStrategyDecorator(sess) : sess;
bpp.setEventSelectionStrategy(ess);
BProgramRunner bpr = new BProgramRunner(bpp);
if (!switchPresent("-v", args)) {
bpr.addListener(new PrintBProgramRunnerListener());
}
bpr.run();
}
Aggregations