Skip to content
Snippets Groups Projects
Commit d89b0660 authored by René Schöne's avatar René Schöne
Browse files

add "status X if mqtt Y"

parent 634f0eff
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ Comment = "//" [^\n\r]+
"after" { return sym(Terminals.AFTER); }
"sec" { return sym(Terminals.SEC); }
"in" { return sym(Terminals.IN); }
"if" { return sym(Terminals.IF); }
"start" { return sym(Terminals.START); }
"using" { return sym(Terminals.USING); }
"reqs" { return sym(Terminals.REQS); }
......
......@@ -134,6 +134,18 @@ aspect Navigation {
syn boolean Component.isUnknownComponent() = false;
eq UnknownComponent.isUnknownComponent() = true;
syn boolean AutoSetStatus.isDelayAutoSetStatus() = false;
eq DelayAutoSetStatus.isDelayAutoSetStatus() = true;
syn boolean AutoSetStatus.isMqttAutoSetStatus() = false;
eq MqttAutoSetStatus.isMqttAutoSetStatus() = true;
syn DelayAutoSetStatus AutoSetStatus.asDelayAutoSetStatus() = null;
eq DelayAutoSetStatus.asDelayAutoSetStatus() = this;
syn MqttAutoSetStatus AutoSetStatus.asMqttAutoSetStatus() = null;
eq MqttAutoSetStatus.asMqttAutoSetStatus() = this;
}
aspect Printing {
......@@ -197,9 +209,13 @@ aspect Printing {
(getStartAsUp() ? ", StartAsUp = true" : "") +
">";
}
syn String AutoSetStatus.details() {
syn String AutoSetStatus.details();
eq DelayAutoSetStatus.details() {
return "[" + getStatus() + " after " + getDelayInSeconds() + " sec]";
}
syn String MqttAutoSetStatus.details() {
return "[" + getStatus() + " if sth. on " + getTopic() + " ]";
}
syn String StartStrategy.details();
eq DockerComposeStartStrategy.details() = "docker compose (name: " + getName() + ")";
eq ScriptStartStrategy.details() = "script (cmd: '" + getCommand() + "'" + (getCwd().isBlank() ? "" : "cwd: '" + getCwd() + "'") + ")";
......
......@@ -48,8 +48,9 @@ Component component =
Component component_body =
COMMA START USING start_strategy.s component_body.c {: c.setStartStrategy(s); return c; :}
| COMMA REPORT USING report_strategy.r component_body.c {: c.setReportStrategy(r); return c; :}
| COMMA STATUS TEXT.s AFTER INTEGER.i SEC component_body.c {: c.setAutoSetStatus(new AutoSetStatus(s, Integer.parseInt(i))); return c; :}
| COMMA STATUS TEXT.s AFTER INTEGER.i SEC component_body.c {: c.setAutoSetStatus(new DelayAutoSetStatus(s, Integer.parseInt(i))); return c; :}
| COMMA START AFTER REQS component_body.c {: c.setStartAsUp(true); return c; :}
| COMMA STATUS TEXT.s IF MQTT TEXT.topic component_body.c {: c.setAutoSetStatus(new MqttAutoSetStatus(s, topic)); return c; :}
| {: Component c = new Component(); c.setStartStrategy(new ManualStartStrategy()); return c; :}
;
......
......@@ -10,7 +10,9 @@ ManualStartStrategy : StartStrategy ;
abstract ReportStrategy ;
MqttReportStrategy : ReportStrategy ::= <TopicPrefix:String> ;
AutoSetStatus ::= <Status:String> <DelayInSeconds:int> ;
abstract AutoSetStatus ::= <Status:String> ;
DelayAutoSetStatus : AutoSetStatus ::= <DelayInSeconds:int> ;
MqttAutoSetStatus : AutoSetStatus ::= <Topic:String> ;
ParsedPrecedenceRelation ;
rel ParsedPrecedenceRelation.Predecessor* -> Component ;
......
......@@ -142,10 +142,16 @@ public class MainCoordinator implements Callable<Integer> {
}
private void scheduleAutoSetStatus(Component comp) {
executor.schedule(() -> {
System.out.println("Setting status of " + comp.getName() + " to " + comp.getAutoSetStatus().getStatus());
comp.setStatus(comp.getAutoSetStatus().getStatus());
}, comp.getAutoSetStatus().getDelayInSeconds(), TimeUnit.SECONDS);
if (comp.getAutoSetStatus().isDelayAutoSetStatus()) {
executor.schedule(() -> {
System.out.println("Setting status of " + comp.getName() + " to " + comp.getAutoSetStatus().getStatus());
comp.setStatus(comp.getAutoSetStatus().getStatus());
}, comp.getAutoSetStatus().asDelayAutoSetStatus().getDelayInSeconds(), TimeUnit.SECONDS);
} else if (comp.getAutoSetStatus().isMqttAutoSetStatus()) {
mainHandler.newConnection(comp.getAutoSetStatus().asMqttAutoSetStatus().getTopic(), bytes -> {
comp.setStatus(comp.getAutoSetStatus().getStatus());
});
}
}
private void printStatus(String message) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment