Select Git revision
CMakeLists.txt
sendDefinition.mustache 6.82 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) {
{{#javaHandler}}
{{#InUse}}
case "java":
final JavaHandler handler = {{attributeName}}();
{{senderName}}.add(() -> {
handler.push(path, {{lastValueGetterCall}});
}{{#IndexBasedListAccess}}, index{{/IndexBasedListAccess}}, connectToken);
{{updateMethodName}}();
if (writeCurrentValue) {
{{writeMethodName}}({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}connectToken);
}
success = true;
break;
{{/InUse}}
{{/javaHandler}}
{{#mqttHandler}}
{{#InUse}}
case "mqtt":
final MqttHandler handler = {{attributeName}}().resolveHandler(uri);
final String topic = {{attributeName}}().extractTopic(uri);
{{senderName}}.add(() -> {
{{#configLoggingEnabledForWrites}}
{{!FIXME circular computation for collection attributes!!}}
{{logDebug}}("[Send] {{entityName}} = {{log_}} -> {{log_}}", {{getterMethodCall}}, {{connectParameterName}});
{{/configLoggingEnabledForWrites}}
if ({{lastValueGetterCall}} != null) {
handler.publish(topic, {{lastValueGetterCall}});
{{#configLoggingEnabledForWrites}}
} else {
{{logWarn}}("[Send] {{entityName}} -> {{log_}}: can't send null.", {{connectParameterName}});
{{/configLoggingEnabledForWrites}}
}
}{{#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:
{{logError}}("Unknown protocol '{{log_}}'.", scheme);
success = false;
}
if (success) {
connectTokenMap.add(this, false, connectToken);
{{#configIncrementalOptionActive}}
{{#sendIncrementalObserverEntries}}
{{observerInstanceSingletonMethodName}}().add(
connectToken,
this, {{CompareParams}},
{{Params}},
() -> {
if (this.{{updateMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}})) {
this.{{writeMethodName}}({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
}
},
"{{AttributeString}}"
);
{{/sendIncrementalObserverEntries}}
{{/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()) {
{{logWarn}}("Disconnect called without connection for sending {{log_}}.{{entityName}} to '{{log_}}'!",
this, {{connectParameterName}});
return false;
}
{{#configIncrementalOptionActive}}
connectTokens.forEach(token -> {{observerInstanceSingletonMethodName}}().remove(token));
{{/configIncrementalOptionActive}}
RagConnectDisconnectHandlerMethod disconnectingMethod;
switch (scheme) {
{{#javaHandler}}
{{#InUse}}
case "java":
disconnectingMethod = {{senderName}}::remove;
break;
{{/InUse}}
{{/javaHandler}}
{{#mqttHandler}}
{{#InUse}}
case "mqtt":
disconnectingMethod = {{senderName}}::remove;
break;
{{/InUse}}
{{/mqttHandler}}
{{#restHandler}}
{{#InUse}}
case "rest":
disconnectingMethod = {{attributeName}}()::disconnect;
break;
{{/InUse}}
{{/restHandler}}
default:
{{logError}}("Unknown protocol '{{log_}}' in '{{log_}}' for disconnecting {{parentTypeName}}.{{entityName}}",
scheme, {{connectParameterName}});
return false;
}
boolean success = true;
for (RagConnectToken connectToken : connectTokens) {
success &= disconnectingMethod.call(connectToken);
}
return success;
}
protected boolean {{parentTypeName}}.{{updateMethodName}}({{#IndexBasedListAccess}}int index{{/IndexBasedListAccess}}) {
{{^shouldNotResetValue}}
{{tokenResetMethodName}}();
{{/shouldNotResetValue}}
{{> mappingApplication}}
{{lastValueSetter}}({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}{{lastResult}});
// normally we would return true here. unless no connect method was called so far to initialize {{senderName}} yet
{{#configEvaluationCounter}} if ({{senderName}} == null) {
{{evaluationCounterVariable}}.incrementSkip("{{parentTypeName}}", "{{entityName}}");
}
{{/configEvaluationCounter}}
return {{senderName}} != null;
}
protected void {{parentTypeName}}.{{writeMethodName}}({{#IndexBasedListAccess}}int index{{/IndexBasedListAccess}}) {
{{#configEvaluationCounter}}
{{evaluationCounterVariable}}.incrementSend("{{parentTypeName}}", "{{entityName}}");
{{/configEvaluationCounter}}
{{senderName}}.run({{#IndexBasedListAccess}}index{{/IndexBasedListAccess}});
}
protected void {{parentTypeName}}.{{writeMethodName}}({{#IndexBasedListAccess}}int index, {{/IndexBasedListAccess}}RagConnectToken token) {
{{#configEvaluationCounter}}
{{evaluationCounterVariable}}.incrementSend("{{parentTypeName}}", "{{entityName}}");
{{/configEvaluationCounter}}
{{senderName}}.run({{#IndexBasedListAccess}}index, {{/IndexBasedListAccess}}token);
}
{{#needForwardingNTA}}
syn {{{forwardingNTA_Type}}} {{parentTypeName}}.{{forwardingNTA_Name}}({{#IndexBasedListAccess}}int index{{/IndexBasedListAccess}}) {
{{#relationEndpointWithListRole}}
// for (var element : {{realGetterMethodCall}}) {
// element.{{touchedTerminalsMethodName}}();
// }
{{realGetterMethodCall}}.stream().forEach(element -> element.{{touchedTerminalsMethodName}}());
return {{realGetterMethodCall}};
{{/relationEndpointWithListRole}}
{{^relationEndpointWithListRole}}
{{{forwardingNTA_Type}}} result = {{realGetterMethodCall}};
if (result == null) {
return null;
}
return result.{{touchedTerminalsMethodName}}();
{{/relationEndpointWithListRole}}
}
{{/needForwardingNTA}}