Skip to content
Snippets Groups Projects
Commit 87104a7d authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

MQTT default port as constant var

parent 98522533
No related branches found
No related tags found
No related merge requests found
...@@ -3,4 +3,10 @@ aspect ExternalHost { ...@@ -3,4 +3,10 @@ aspect ExternalHost {
public ExternalHost ExternalHost.copyFrom(ExternalHost host) { public ExternalHost ExternalHost.copyFrom(ExternalHost host) {
return setHostName(host.getHostName()).setPort(host.getPort()).setUserName(host.getUserName()).setPassword(host.getPassword()); return setHostName(host.getHostName()).setPort(host.getPort()).setUserName(host.getUserName()).setPassword(host.getPassword());
} }
public ExternalHost ExternalHost.setDefaultPort(int defaultPort) {
if (this.getPort()==0) {
this.setPort(defaultPort);
}
return this;
}
} }
\ No newline at end of file
package de.tudresden.inf.st.eraser.jastadd.model;
public class MQTTConstants {
public static final int MQTT_DEFAULT_PORT = 1883;
}
...@@ -7,6 +7,8 @@ import org.fusesource.mqtt.client.*; ...@@ -7,6 +7,8 @@ import org.fusesource.mqtt.client.*;
import java.net.URI; import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static de.tudresden.inf.st.eraser.jastadd.model.MQTTConstants.MQTT_DEFAULT_PORT;
/** /**
* Implementation of a MQTT sender using <code>org.fusesource.mqtt.client</code>. * Implementation of a MQTT sender using <code>org.fusesource.mqtt.client</code>.
* *
...@@ -30,9 +32,9 @@ public class MQTTSenderImpl implements MQTTSender { ...@@ -30,9 +32,9 @@ public class MQTTSenderImpl implements MQTTSender {
@Override @Override
public MQTTSender setHost(ExternalHost host) { public MQTTSender setHost(ExternalHost host) {
int port = host.getPort()!=0 ? host.getPort() : 1883; host.setDefaultPort(MQTT_DEFAULT_PORT);
/* The host running the MQTT broker. */ /* The host running the MQTT broker. */
URI hostUri = URI.create("tcp://" + host.getHostName() + ":" + port); URI hostUri = URI.create("tcp://" + host.getHostName() + ":" + host.getPort());
logger.debug("Host is {}", hostUri); logger.debug("Host is {}", hostUri);
MQTT mqtt = new MQTT(); MQTT mqtt = new MQTT();
String username = host.getUserName(); String username = host.getUserName();
......
...@@ -18,6 +18,8 @@ import java.util.concurrent.locks.Lock; ...@@ -18,6 +18,8 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import static de.tudresden.inf.st.eraser.jastadd.model.MQTTConstants.MQTT_DEFAULT_PORT;
/** /**
* Subscribe to topics, receive and store messages. * Subscribe to topics, receive and store messages.
* *
...@@ -53,8 +55,8 @@ public class MqttReceiver implements AutoCloseable { ...@@ -53,8 +55,8 @@ public class MqttReceiver implements AutoCloseable {
* Sets the host to receive messages from * Sets the host to receive messages from
*/ */
public void setHost(ExternalHost externalHost) { public void setHost(ExternalHost externalHost) {
int port = externalHost.getPort()!=0 ? externalHost.getPort() : 1883; externalHost.setDefaultPort(MQTT_DEFAULT_PORT);
this.host = URI.create("tcp://" + externalHost.getHostName() + ":" + port); this.host = URI.create("tcp://" + externalHost.getHostName() + ":" + externalHost.getPort());
this.username = externalHost.getUserName(); this.username = externalHost.getUserName();
this.password = externalHost.getPassword(); this.password = externalHost.getPassword();
logger.debug("Host is {}", externalHost.getHostName()); logger.debug("Host is {}", externalHost.getHostName());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment