Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
JastAdd
RagConnect
Commits
d0cd0239
Commit
d0cd0239
authored
Jul 06, 2020
by
René Schöne
Browse files
Renamed MqttUpdater to MqttHandler.
parent
56be33c4
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/jastadd/backend/Generation.jadd
View file @
d0cd0239
...
...
@@ -27,11 +27,11 @@ aspect GenerationUtils {
aspect AttributesForMustache {
// --- MRos2Rag ---
eq MRos2Rag.getChild().mqtt
Updat
erAttribute() = mqtt
Updat
erAttribute();
eq MRos2Rag.getChild().mqtt
Updat
erField() = mqtt
Updat
erField();
eq MRos2Rag.getChild().mqtt
Handl
erAttribute() = mqtt
Handl
erAttribute();
eq MRos2Rag.getChild().mqtt
Handl
erField() = mqtt
Handl
erField();
syn String MRos2Rag.mqtt
Updat
erAttribute() = getRos2Rag().mqtt
Updat
erAttribute();
syn String MRos2Rag.mqtt
Updat
erField() = getRos2Rag().mqtt
Updat
erField();
syn String MRos2Rag.mqtt
Handl
erAttribute() = getRos2Rag().mqtt
Handl
erAttribute();
syn String MRos2Rag.mqtt
Handl
erField() = getRos2Rag().mqtt
Handl
erField();
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.mqtt
Updat
erAttribute();
inh String MUpdateDefinition.mqtt
Handl
erAttribute();
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.mqtt
Updat
erAttribute();
inh String MTypeComponent.mqtt
Updat
erField();
inh String MTypeComponent.mqtt
Handl
erAttribute();
inh String MTypeComponent.mqtt
Handl
erField();
// --- 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.mqtt
Updat
erAttribute() = "_mqtt
Updat
er";
syn String Ros2Rag.mqtt
Updat
erField() = "_mqtt
Updat
er";
syn String Ros2Rag.mqtt
Handl
erAttribute() = "_mqtt
Handl
er";
syn String Ros2Rag.mqtt
Handl
erField() = "_mqtt
Handl
er";
syn String Ros2Rag.mqttSetHostMethod() = "MqttSetHost";
syn String Ros2Rag.mqttWaitUntilReadyMethod() = "MqttWaitUntilReady";
syn String Ros2Rag.mqttCloseMethod() = "MqttCloseConnections";
// naming copy attributes
// --- mqtt
Updat
erAttribute ---
inh String UpdateDefinition.mqtt
Updat
erAttribute();
inh String MappingDefinition.mqtt
Updat
erAttribute();
inh String DependencyDefinition.mqtt
Updat
erAttribute();
eq Ros2Rag.getChild().mqtt
Updat
erAttribute() = mqtt
Updat
erAttribute();
// --- mqtt
Handl
erAttribute ---
inh String UpdateDefinition.mqtt
Handl
erAttribute();
inh String MappingDefinition.mqtt
Handl
erAttribute();
inh String DependencyDefinition.mqtt
Handl
erAttribute();
eq Ros2Rag.getChild().mqtt
Handl
erAttribute() = mqtt
Handl
erAttribute();
// --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName();
...
...
src/main/java/org/jastadd/ros2rag/compiler/Compiler.java
View file @
d0cd0239
...
...
@@ -96,18 +96,18 @@ public class Compiler {
}
printMessage
(
"Writing output files"
);
// copy Mqtt
Updat
er into outputDir
final
String
mqtt
Updat
erFileName
=
"Mqtt
Updat
er.jadd"
;
// copy Mqtt
Handl
er into outputDir
final
String
mqtt
Handl
erFileName
=
"Mqtt
Handl
er.jadd"
;
try
{
InputStream
inputStream
=
Compiler
.
class
.
getClassLoader
().
getResourceAsStream
(
mqtt
Updat
erFileName
);
InputStream
inputStream
=
Compiler
.
class
.
getClassLoader
().
getResourceAsStream
(
mqtt
Handl
erFileName
);
if
(
inputStream
==
null
)
{
throw
new
CompilerException
(
"Could not open "
+
mqtt
Updat
erFileName
);
throw
new
CompilerException
(
"Could not open "
+
mqtt
Handl
erFileName
);
}
Files
.
copy
(
inputStream
,
Paths
.
get
(
outputDir
,
mqtt
Updat
erFileName
),
Paths
.
get
(
outputDir
,
mqtt
Handl
erFileName
),
StandardCopyOption
.
REPLACE_EXISTING
);
}
catch
(
IOException
e
)
{
throw
new
CompilerException
(
"Could not copy "
+
mqtt
Updat
erFileName
,
e
);
throw
new
CompilerException
(
"Could not copy "
+
mqtt
Handl
erFileName
,
e
);
}
writeToFile
(
outputDir
+
"/Grammar.relast"
,
ros2Rag
.
getProgram
().
generateAbstractGrammar
());
writeToFile
(
outputDir
+
"/ROS2RAG.jadd"
,
ros2Rag
.
generateAspect
(
optionRootNode
.
getValue
()));
...
...
src/main/resources/Mqtt
Updat
er.jadd
→
src/main/resources/Mqtt
Handl
er.jadd
View file @
d0cd0239
aspect Mqtt
Updat
er {
aspect Mqtt
Handl
er {
/**
* Helper class to receive updates via MQTT and use callbacks to handle those messages.
*
* @author rschoene - Initial contribution
*/
public class Mqtt
Updat
er {
public class Mqtt
Handl
er {
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 Mqtt
Updat
er() {
public Mqtt
Handl
er() {
this("Ros2Rag");
}
public Mqtt
Updat
er(String name) {
public Mqtt
Handl
er(String name) {
this.name = java.util.Objects.requireNonNull(name, "Name must be set");
this.logger = org.apache.logging.log4j.LogManager.getLogger(Mqtt
Updat
er.class);
this.logger = org.apache.logging.log4j.LogManager.getLogger(Mqtt
Handl
er.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 Mqtt
Updat
er dontSendWelcomeMessage() {
public Mqtt
Handl
er 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 Mqtt
Updat
er setHost(String host) throws java.io.IOException {
public Mqtt
Handl
er 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 Mqtt
Updat
er setHost(String host, int port) throws java.io.IOException {
public Mqtt
Handl
er 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 (Mqtt
Updat
er.this.sendWelcomeMessage) {
if (Mqtt
Handl
er.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) {
...
...
src/main/resources/mqtt.mustache
View file @
d0cd0239
aspect MQTT {
private Mqtt
Updat
er
{{
rootNodeName
}}
.
{{
mqtt
Updat
erField
}}
= new Mqtt
Updat
er();
private Mqtt
Handl
er
{{
rootNodeName
}}
.
{{
mqtt
Handl
erField
}}
= new Mqtt
Handl
er();
public void
{{
rootNodeName
}}
.
{{
mqttSetHostMethod
}}
(String host) throws java.io.IOException {
{{
mqtt
Updat
erField
}}
.setHost(host);
{{
mqtt
Handl
erField
}}
.setHost(host);
}
public void
{{
rootNodeName
}}
.
{{
mqttSetHostMethod
}}
(String host, int port) throws java.io.IOException {
{{
mqtt
Updat
erField
}}
.setHost(host, port);
{{
mqtt
Handl
erField
}}
.setHost(host, port);
}
public boolean
{{
rootNodeName
}}
.
{{
mqttWaitUntilReadyMethod
}}
(long time, java.util.concurrent.TimeUnit unit) {
return
{{
mqtt
Updat
erField
}}
.waitUntilReady(time, unit);
return
{{
mqtt
Handl
erField
}}
.waitUntilReady(time, unit);
}
public void
{{
rootNodeName
}}
.
{{
mqttCloseMethod
}}
() {
{{
mqtt
Updat
erField
}}
.close();
{{
mqtt
Handl
erField
}}
.close();
}
inh Mqtt
Updat
er ASTNode.
{{
mqtt
Updat
erAttribute
}}
();
inh Mqtt
Handl
er ASTNode.
{{
mqtt
Handl
erAttribute
}}
();
{{#
getRootTypeComponents
}}
eq
{{
rootNodeName
}}
.get
{{
name
}}
().
{{
mqtt
Updat
erAttribute
}}
() =
{{
mqtt
Updat
erField
}}
;
eq
{{
rootNodeName
}}
.get
{{
name
}}
().
{{
mqtt
Handl
erAttribute
}}
() =
{{
mqtt
Handl
erField
}}
;
{{/
getRootTypeComponents
}}
}
src/main/resources/readDefinition.mustache
View file @
d0cd0239
public void
{{
parentTypeName
}}
.
{{
connectMethod
}}
(String topic) {
{{
mqtt
Updat
erAttribute
}}
().newConnection(topic, message -> {
{{
mqtt
Handl
erAttribute
}}
().newConnection(topic, message -> {
{{>
mappingApplication
}}
{{#
loggingEnabledForReads
}}
System.out.println("[Read] " + topic + " ->
{{
tokenName
}}
= " +
{{
lastResult
}}
);
{{!lastResult has to be a new attribute}}
...
...
src/main/resources/writeDefinition.mustache
View file @
d0cd0239
...
...
@@ -20,5 +20,5 @@
{{#
loggingEnabledForWrites
}}
System.out.println("[Write]
{{
tokenName
}}
= " + get
{{
tokenName
}}
() + " -> " +
{{
writeTopic
}}
);
{{/
loggingEnabledForWrites
}}
{{
mqtt
Updat
erAttribute
}}
().publish(
{{
writeTopic
}}
,
{{
lastValue
}}
);
{{
mqtt
Handl
erAttribute
}}
().publish(
{{
writeTopic
}}
,
{{
lastValue
}}
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment