Select Git revision
mqtt.mustache
sendDefinition.mustache 4.99 KiB
private RagConnect{{#IndexBasedListAccess}}Mapping{{/IndexBasedListAccess}}Publisher {{parentTypeName}}.{{senderName}} = new RagConnect{{#IndexBasedListAccess}}Mapping{{/IndexBasedListAccess}}Publisher();
public boolean {{parentTypeName}}.{{connectMethodName}}(String {{connectParameterName}}{{#IndexBasedListAccess}}, int index{{/IndexBasedListAccess}}, boolean writeCurrentValue) throws java.io.IOException {
{{>handleUri}}
RagConnectToken connectToken = new RagConnectToken(uri, "{{entityName}}");
boolean success;
switch (scheme) {
{{#mqttHandler}}
{{#InUse}}
case "mqtt":
final MqttHandler handler = {{attributeName}}().resolveHandler(uri);
final String topic = {{attributeName}}().extractTopic(uri);
{{senderName}}.add(() -> {
{{#configLoggingEnabledForWrites}}
System.out.println("[Send] {{entityName}} = " + {{getterMethodCall}} + " -> " + {{connectParameterName}});
{{/configLoggingEnabledForWrites}}
handler.publish(topic, {{lastValueGetterCall}});
}{{#IndexBasedListAccess}}, index{{/IndexBasedListAccess}}, connectToken);
{{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
if (writeCurrentValue) {
{{writeMethodName}}({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}connectToken);
}
success = true;
break;
{{/InUse}}
{{/mqttHandler}}
{{#restHandler}}
{{#InUse}}
case "rest":
success = {{attributeName}}().newGETConnection(connectToken, () -> {
{{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
return new String({{lastValueGetterCall}});
});
break;
{{/InUse}}
{{/restHandler}}
default:
System.err.println("Unknown protocol '" + scheme + "'.");
success = false;
}
if (success) {
connectTokenMap.add(this, false, connectToken);
{{#configIncrementalOptionActive}}
{{!todo maybe getterMethodName needs to be change for indexed send}}
{{observerInstanceSingletonMethodName}}().add(
connectToken,
this,
"{{getterMethodName}}{{#IndexBasedListAccess}}_int{{/IndexBasedListAccess}}",
{{#IndexBasedListAccess}}index,{{/IndexBasedListAccess}}
() -> {
if (this.{{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}})) {
this.{{writeMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
}
}
);
{{/configIncrementalOptionActive}}
}
return success;
}
{{!todo check if index parameter is needed here for typeIsList and indexBasedListAccess}}
public boolean {{parentTypeName}}.{{disconnectMethodName}}(String {{connectParameterName}}) throws java.io.IOException {
{{>handleUri}}
java.util.List<RagConnectToken> connectTokens = connectTokenMap.removeAll(this, false, uri, "{{entityName}}");
if (connectTokens.isEmpty()) {
System.err.println("Disconnect called without connection for sending " + this + ".{{entityName}} to '" + {{connectParameterName}} + "'!");
return false;
}
{{#configIncrementalOptionActive}}
connectTokens.forEach(token -> {{observerInstanceSingletonMethodName}}().remove(token));