Commit d0cd0239 authored by René Schöne's avatar René Schöne
Browse files

Renamed MqttUpdater to MqttHandler.

parent 56be33c4
......@@ -27,11 +27,11 @@ aspect GenerationUtils {
aspect AttributesForMustache {
// --- MRos2Rag ---
eq MRos2Rag.getChild().mqttUpdaterAttribute() = mqttUpdaterAttribute();
eq MRos2Rag.getChild().mqttUpdaterField() = mqttUpdaterField();
eq MRos2Rag.getChild().mqttHandlerAttribute() = mqttHandlerAttribute();
eq MRos2Rag.getChild().mqttHandlerField() = mqttHandlerField();
syn String MRos2Rag.mqttUpdaterAttribute() = getRos2Rag().mqttUpdaterAttribute();
syn String MRos2Rag.mqttUpdaterField() = getRos2Rag().mqttUpdaterField();
syn String MRos2Rag.mqttHandlerAttribute() = getRos2Rag().mqttHandlerAttribute();
syn String MRos2Rag.mqttHandlerField() = getRos2Rag().mqttHandlerField();
syn String MRos2Rag.mqttSetHostMethod() = getRos2Rag().mqttSetHostMethod();
syn String MRos2Rag.mqttWaitUntilReadyMethod() = getRos2Rag().mqttWaitUntilReadyMethod();
syn String MRos2Rag.mqttCloseMethod() = getRos2Rag().mqttCloseMethod();
......@@ -46,7 +46,7 @@ aspect AttributesForMustache {
eq MUpdateDefinition.getInnerMappingDefinition().resultVarPrefix() = resultVarPrefix();
eq MUpdateDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : resultVarPrefix() + getInnerMappingDefinition(i - 1).getMappingDefinition().methodName();
inh String MUpdateDefinition.mqttUpdaterAttribute();
inh String MUpdateDefinition.mqttHandlerAttribute();
syn String MUpdateDefinition.connectMethod() = updateDef().connectMethod();
syn TokenComponent MUpdateDefinition.token() = updateDef().getToken();
......@@ -114,8 +114,8 @@ aspect AttributesForMustache {
// --- MTypeComponent ---
syn String MTypeComponent.name() = getTypeComponent().getName();
inh String MTypeComponent.mqttUpdaterAttribute();
inh String MTypeComponent.mqttUpdaterField();
inh String MTypeComponent.mqttHandlerAttribute();
inh String MTypeComponent.mqttHandlerField();
// --- MTokenComponent ---
syn String MTokenComponent.parentTypeName() = getTokenComponent().containingTypeDecl().getName();
......@@ -216,19 +216,19 @@ aspect AspectGeneration {
syn String DependencyDefinition.internalRelationPrefix() = "_internal_" + getID();
syn String DependencyDefinition.internalTokenName() = getSource().internalName();
syn String Ros2Rag.mqttUpdaterAttribute() = "_mqttUpdater";
syn String Ros2Rag.mqttUpdaterField() = "_mqttUpdater";
syn String Ros2Rag.mqttHandlerAttribute() = "_mqttHandler";
syn String Ros2Rag.mqttHandlerField() = "_mqttHandler";
syn String Ros2Rag.mqttSetHostMethod() = "MqttSetHost";
syn String Ros2Rag.mqttWaitUntilReadyMethod() = "MqttWaitUntilReady";
syn String Ros2Rag.mqttCloseMethod() = "MqttCloseConnections";
// naming copy attributes
// --- mqttUpdaterAttribute ---
inh String UpdateDefinition.mqttUpdaterAttribute();
inh String MappingDefinition.mqttUpdaterAttribute();
inh String DependencyDefinition.mqttUpdaterAttribute();
eq Ros2Rag.getChild().mqttUpdaterAttribute() = mqttUpdaterAttribute();
// --- mqttHandlerAttribute ---
inh String UpdateDefinition.mqttHandlerAttribute();
inh String MappingDefinition.mqttHandlerAttribute();
inh String DependencyDefinition.mqttHandlerAttribute();
eq Ros2Rag.getChild().mqttHandlerAttribute() = mqttHandlerAttribute();
// --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName();
......
......@@ -96,18 +96,18 @@ public class Compiler {
}
printMessage("Writing output files");
// copy MqttUpdater into outputDir
final String mqttUpdaterFileName = "MqttUpdater.jadd";
// copy MqttHandler into outputDir
final String mqttHandlerFileName = "MqttHandler.jadd";
try {
InputStream inputStream = Compiler.class.getClassLoader().getResourceAsStream(mqttUpdaterFileName);
InputStream inputStream = Compiler.class.getClassLoader().getResourceAsStream(mqttHandlerFileName);
if (inputStream == null) {
throw new CompilerException("Could not open " + mqttUpdaterFileName);
throw new CompilerException("Could not open " + mqttHandlerFileName);
}
Files.copy(inputStream,
Paths.get(outputDir, mqttUpdaterFileName),
Paths.get(outputDir, mqttHandlerFileName),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new CompilerException("Could not copy " + mqttUpdaterFileName, e);
throw new CompilerException("Could not copy " + mqttHandlerFileName, e);
}
writeToFile(outputDir + "/Grammar.relast", ros2Rag.getProgram().generateAbstractGrammar());
writeToFile(outputDir + "/ROS2RAG.jadd", ros2Rag.generateAspect(optionRootNode.getValue()));
......
aspect MqttUpdater {
aspect MqttHandler {
/**
* Helper class to receive updates via MQTT and use callbacks to handle those messages.
*
* @author rschoene - Initial contribution
*/
public class MqttUpdater {
public class MqttHandler {
private static final int DEFAULT_PORT = 1883;
private final org.apache.logging.log4j.Logger logger;
......@@ -23,13 +23,13 @@ public class MqttUpdater {
/** Dispatch knowledge */
private final java.util.Map<String, java.util.function.Consumer<byte[]>> callbacks;
public MqttUpdater() {
public MqttHandler() {
this("Ros2Rag");
}
public MqttUpdater(String name) {
public MqttHandler(String name) {
this.name = java.util.Objects.requireNonNull(name, "Name must be set");
this.logger = org.apache.logging.log4j.LogManager.getLogger(MqttUpdater.class);
this.logger = org.apache.logging.log4j.LogManager.getLogger(MqttHandler.class);
this.callbacks = new java.util.HashMap<>();
this.readyLock = new java.util.concurrent.locks.ReentrantLock();
this.readyCondition = readyLock.newCondition();
......@@ -37,7 +37,7 @@ public class MqttUpdater {
this.qos = org.fusesource.mqtt.client.QoS.AT_LEAST_ONCE;
}
public MqttUpdater dontSendWelcomeMessage() {
public MqttHandler dontSendWelcomeMessage() {
this.sendWelcomeMessage = false;
return this;
}
......@@ -47,7 +47,7 @@ public class MqttUpdater {
* @throws IOException if could not connect, or could not subscribe to a topic
* @return self
*/
public MqttUpdater setHost(String host) throws java.io.IOException {
public MqttHandler setHost(String host) throws java.io.IOException {
return setHost(host, DEFAULT_PORT);
}
......@@ -56,7 +56,7 @@ public class MqttUpdater {
* @throws IOException if could not connect, or could not subscribe to a topic
* @return self
*/
public MqttUpdater setHost(String host, int port) throws java.io.IOException {
public MqttHandler setHost(String host, int port) throws java.io.IOException {
java.util.Objects.requireNonNull(host, "Host need to be set!");
this.host = java.net.URI.create("tcp://" + host + ":" + port);
......@@ -109,7 +109,7 @@ public class MqttUpdater {
connection.connect(new org.fusesource.mqtt.client.Callback<Void>() {
@Override
public void onSuccess(Void value) {
if (MqttUpdater.this.sendWelcomeMessage) {
if (MqttHandler.this.sendWelcomeMessage) {
connection.publish("components", (name + " is connected").getBytes(), org.fusesource.mqtt.client.QoS.AT_LEAST_ONCE, false, new org.fusesource.mqtt.client.Callback<Void>() {
@Override
public void onSuccess(Void value) {
......
aspect MQTT {
private MqttUpdater {{rootNodeName}}.{{mqttUpdaterField}} = new MqttUpdater();
private MqttHandler {{rootNodeName}}.{{mqttHandlerField}} = new MqttHandler();
public void {{rootNodeName}}.{{mqttSetHostMethod}}(String host) throws java.io.IOException {
{{mqttUpdaterField}}.setHost(host);
{{mqttHandlerField}}.setHost(host);
}
public void {{rootNodeName}}.{{mqttSetHostMethod}}(String host, int port) throws java.io.IOException {
{{mqttUpdaterField}}.setHost(host, port);
{{mqttHandlerField}}.setHost(host, port);
}
public boolean {{rootNodeName}}.{{mqttWaitUntilReadyMethod}}(long time, java.util.concurrent.TimeUnit unit) {
return {{mqttUpdaterField}}.waitUntilReady(time, unit);
return {{mqttHandlerField}}.waitUntilReady(time, unit);
}
public void {{rootNodeName}}.{{mqttCloseMethod}}() {
{{mqttUpdaterField}}.close();
{{mqttHandlerField}}.close();
}
inh MqttUpdater ASTNode.{{mqttUpdaterAttribute}}();
inh MqttHandler ASTNode.{{mqttHandlerAttribute}}();
{{#getRootTypeComponents}}
eq {{rootNodeName}}.get{{name}}().{{mqttUpdaterAttribute}}() = {{mqttUpdaterField}};
eq {{rootNodeName}}.get{{name}}().{{mqttHandlerAttribute}}() = {{mqttHandlerField}};
{{/getRootTypeComponents}}
}
public void {{parentTypeName}}.{{connectMethod}}(String topic) {
{{mqttUpdaterAttribute}}().newConnection(topic, message -> {
{{mqttHandlerAttribute}}().newConnection(topic, message -> {
{{> mappingApplication}}
{{#loggingEnabledForReads}}
System.out.println("[Read] " + topic + " -> {{tokenName}} = " + {{lastResult}});{{!lastResult has to be a new attribute}}
......
......@@ -20,5 +20,5 @@
{{#loggingEnabledForWrites}}
System.out.println("[Write] {{tokenName}} = " + get{{tokenName}}() + " -> " + {{writeTopic}});
{{/loggingEnabledForWrites}}
{{mqttUpdaterAttribute}}().publish({{writeTopic}}, {{lastValue}});
{{mqttHandlerAttribute}}().publish({{writeTopic}}, {{lastValue}});
}
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