Skip to content

Commit

Permalink
build for tag
Browse files Browse the repository at this point in the history
  • Loading branch information
simon.johnson committed May 20, 2022
1 parent 41123e5 commit 115c73f
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 55 deletions.
2 changes: 1 addition & 1 deletion mqtt-sn-client/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.slj</groupId>
<artifactId>mqtt-sn-client</artifactId>
<version>1.0.0</version>
<version>0.1.12</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion mqtt-sn-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<groupId>org.slj</groupId>
<artifactId>mqtt-sn-client</artifactId>
<version>1.0.0</version>
<version>0.1.12</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void launch(MqttsnInteractiveClient interactiveClient) throws Exce
try (Scanner input = new Scanner(System.in)) {
PrintStream output = System.out;
interactiveClient.init(input, output);
interactiveClient.welcome();
interactiveClient.welcome("Welcome to the mqtt-sn interactive client. You will need to give me the location of your MQTT-SN compliant gateway to continue..");
interactiveClient.configureWithHistory();
interactiveClient.start();
interactiveClient.command();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ public void disableOutput(){
message("console messaging output disabled");
}

public void welcome(){
public void welcome(String welcome){
synchronized (output){
output.println("===============================================");
output.println(String.format("Welcome to %s", getCLIName()));
output.println("===============================================");

if(welcome != null){
output.println(String.format("%s", welcome));
}
}
}

Expand All @@ -186,14 +190,21 @@ public void exit(){
}

protected void configure() throws IOException {
do{
hostName = captureMandatoryString(input, output, "Please enter a valid host name or ip address");
} while(!validHost());
if(needsHostname()){
do{
hostName = captureMandatoryString(input, output, "Please enter a valid host name or ip address");
} while(!validHost());
}

port = captureMandatoryInt(input, output, "Please enter a port", null);
do{
clientId = captureString(input, output, "Please enter a valid clientId");
} while(!validClientId(MAX_ALLOWED_CLIENTID_LENGTH));
if(needsPort()){
port = captureMandatoryInt(input, output, "Please enter a port", null);
}

if(needsClientId()){
do{
clientId = captureString(input, output, "Please enter a valid clientId");
} while(!validClientId(MAX_ALLOWED_CLIENTID_LENGTH));
}
}

public void configureWithHistory() throws IOException {
Expand All @@ -213,7 +224,13 @@ public void configureWithHistory() throws IOException {
}

protected boolean configOk(){
return hostName != null && port != 0 ;
if(needsHostname()){
if(hostName == null) return false;
}
if(needsPort()){
if(port == 0) return false;
}
return true;
}

protected void loadConfigHistory(Properties props) throws IOException {
Expand Down Expand Up @@ -505,6 +522,18 @@ protected void quit()
}
}

protected boolean needsHostname(){
return true;
}

protected boolean needsClientId(){
return true;
}

protected boolean needsPort(){
return true;
}

protected abstract String getPropertyFileName();

protected abstract boolean processCommand(String command) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ protected AbstractMqttsnRuntimeRegistry createRuntimeRegistry(MqttsnOptions opti
withTransport(createTransport()).
withCodec(MqttsnCodecs.MQTTSN_CODEC_VERSION_1_2);
}
});
}, true, "Welcome to the AWS IoT Core version of the gateway. You will need to connect your gateway to your AWS IoT via the credentials available in your AWS console.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ protected AbstractMqttsnRuntimeRegistry createRuntimeRegistry(MqttsnOptions opti
withTransport(createTransport()).
withCodec(MqttsnCodecs.MQTTSN_CODEC_VERSION_1_2);
}
});
}, true, "Welcome to the Google IoT Core version of the gateway. You will need to connect your gateway to your Google IoT via the credentials available in your Google console.");
}
}
6 changes: 1 addition & 5 deletions mqtt-sn-gateway-connector-paho/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</dependencies>

<build>
<finalName>mqtt-sn-gateway-${version}</finalName>
<finalName>mqtt-sn-gateway-${project.version}</finalName>
<plugins>

<!-- Maven Shade Plugin -->
Expand All @@ -89,10 +89,6 @@
</goals>
<configuration>
<transformers>
<!-- add org.slj.dtls.test.Main-Class to manifest file -->
<!--transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.slj.mqtt.sn.gateway.impl.AggregatingGatewayMain</mainClass>
</transformer-->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.slj.mqtt.sn.gateway.connector.paho.AggregatingGatewayInteractiveMain</mainClass>
</transformer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ protected AbstractMqttsnRuntimeRegistry createRuntimeRegistry(MqttsnOptions opti
withUsername(username).
withPassword(password);

/*
MqttsnSecurityOptions securityOptions = new MqttsnSecurityOptions().
withIntegrityType(MqttsnSecurityOptions.INTEGRITY_TYPE.hmac).
withIntegrityPoint(MqttsnSecurityOptions.INTEGRITY_POINT.protocol_messages);
options.withSecurityOptions(securityOptions);
*/

return MqttsnGatewayRuntimeRegistry.defaultConfiguration(options).
withBrokerConnectionFactory(new PahoMqttsnBrokerConnectionFactory()).
withBrokerService(new MqttsnAggregatingGateway(brokerOptions)).
withTransport(createTransport()).
withCodec(MqttsnCodecs.MQTTSN_CODEC_VERSION_1_2);
}
});
}, true, "Welcome to the custom-broker version of the gateway. You will need to connect your gateway to your MQTT broker using a client connection host, port, username, password & clientId.");
}
}
26 changes: 24 additions & 2 deletions mqtt-sn-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<groupId>org.slj</groupId>
<artifactId>mqtt-sn-gateway</artifactId>
<version>1.0.0</version>
<version>0.1.12</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -65,12 +65,34 @@
</dependencies>

<build>
<finalName>mqtt-sn-gateway-v12-loopback-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.slj.mqtt.sn.gateway.impl.connector.LoopbackGatewayInteractiveMain</mainClass>
</transformer>
</transformers>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.slj.mqtt.sn.utils.MqttsnUtils;

import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
Expand All @@ -57,6 +58,8 @@ public abstract class MqttsnInteractiveGateway extends AbstractInteractiveCli {
protected String username;
protected String password;

protected boolean needsBroker;

enum COMMANDS {
POKE("Poke the queue", new String[0], true),
INFLIGHT("List inlight messages", new String[0], false),
Expand Down Expand Up @@ -105,6 +108,11 @@ public String getDescription(){
}
}

public void init(boolean needsBroker, Scanner input, PrintStream output) {
this.needsBroker = needsBroker;
super.init(input, output);
}

@Override
protected boolean processCommand(String command) throws Exception {
COMMANDS c = COMMANDS.valueOf(command.toUpperCase());
Expand Down Expand Up @@ -415,16 +423,15 @@ protected void status()
protected MqttsnOptions createOptions() {
return new MqttsnGatewayOptions().
withRealtimeMessageCounters(true).
withMaxConnectedClients(10000).
withMaxConnectedClients(100).
withGatewayId(101).
withContextId(clientId).
withMaxMessagesInQueue(100).
withRemoveDisconnectedSessionsSeconds(60 * 60).
withTransportProtocolHandoffThreadCount(60).
withTransportSendHandoffThreadCount(120).
withTransportProtocolHandoffThreadCount(20).
withTransportSendHandoffThreadCount(20).
withQueueProcessorThreadCount(2).
withMinFlushTime(5).
withSleepClearsRegistrations(false);
withMinFlushTime(5);
}

@Override
Expand All @@ -443,10 +450,15 @@ protected AbstractMqttsnRuntime createRuntime(AbstractMqttsnRuntimeRegistry regi
@Override
public void start() throws Exception {
super.start();
message(String.format("Attempting to connect to backend broker at %s:%s...", hostName, port));
if(needsBroker){
message(String.format("Attempting to connect to backend broker at %s:%s...", hostName, port));
}
try {
getRuntime().start(getRuntimeRegistry(), false);
message("Successfully connected to broker, TCP/IP connection active.");
if(needsBroker){
message("Successfully connected to broker, TCP/IP connection active.");
}
message(String.format("Gateway listening for datagram traffic on %s", MqttsnUdpOptions.DEFAULT_LOCAL_PORT));
} catch(Exception e){
message(cli_red("Unable to connect to broker"));
message("Please check the connection details supplied");
Expand All @@ -457,22 +469,28 @@ public void start() throws Exception {
@Override
protected void configure() throws IOException {
super.configure();
username = captureString(input, output, "Please enter a valid username for you broker connection");
password = captureString(input, output, "Please enter a valid password for you broker connection");
if(needsBroker){
username = captureString(input, output, "Please enter a valid username for you broker connection");
password = captureString(input, output, "Please enter a valid password for you broker connection");
}
}

@Override
protected void loadConfigHistory(Properties props) throws IOException {
super.loadConfigHistory(props);
username = props.getProperty(USERNAME);
password = props.getProperty(PASSWORD);
if(needsBroker){
username = props.getProperty(USERNAME);
password = props.getProperty(PASSWORD);
}
}

@Override
protected void saveConfigHistory(Properties props) {
super.saveConfigHistory(props);
props.setProperty(USERNAME, username);
props.setProperty(PASSWORD, password);
if(needsBroker){
props.setProperty(USERNAME, username);
props.setProperty(PASSWORD, password);
}
}

@Override
Expand All @@ -494,4 +512,19 @@ public String getColorForState(MqttsnClientState state){
default: return cli_red(state.toString());
}
}

@Override
protected boolean needsHostname() {
return needsBroker;
}

@Override
protected boolean needsClientId() {
return super.needsClientId();
}

@Override
protected boolean needsPort() {
return needsBroker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

public class MqttsnInteractiveGatewayLauncher {
static final String DEBUG = "debug";
public static void launch(MqttsnInteractiveGateway interactiveGateway) throws Exception {
public static void launch(MqttsnInteractiveGateway interactiveGateway, boolean needsBroker, String welcome) throws Exception {
if(!Boolean.getBoolean(DEBUG)) LogManager.getLogManager().reset();
try (Scanner input = new Scanner(System.in)) {
PrintStream output = System.out;
interactiveGateway.init(input, output);
interactiveGateway.welcome();
interactiveGateway.init(needsBroker, input, output);
interactiveGateway.welcome(welcome);
interactiveGateway.configureWithHistory();
interactiveGateway.start();
interactiveGateway.command();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,18 @@ public class LoopbackGatewayInteractiveMain {
public static void main(String[] args) throws Exception {
MqttsnInteractiveGatewayLauncher.launch(new MqttsnInteractiveGateway() {
protected AbstractMqttsnRuntimeRegistry createRuntimeRegistry(MqttsnOptions options, IMqttsnTransport transport) {

MqttsnBackendOptions brokerOptions = new MqttsnBackendOptions().
withHost(hostName).
withPort(port).
withUsername(username).
withPassword(password);

/*
MqttsnSecurityOptions securityOptions = new MqttsnSecurityOptions().
withIntegrityType(MqttsnSecurityOptions.INTEGRITY_TYPE.hmac).
withIntegrityPoint(MqttsnSecurityOptions.INTEGRITY_POINT.protocol_messages);
options.withSecurityOptions(securityOptions);
*/

options.withMaxMessagesInQueue(10000);
return MqttsnGatewayRuntimeRegistry.defaultConfiguration(options).
withBrokerConnectionFactory(new LoopbackMqttsnBrokerConnectionFactory()).
withBrokerService(new MqttsnAggregatingGateway(brokerOptions)).
withTransport(createTransport()).
withCodec(MqttsnCodecs.MQTTSN_CODEC_VERSION_1_2);
}
});
}, false, "Welcome to the loopback gateway. This version does NOT use a backend broker, instead brokering MQTT messages itself as a loopback to connected devices.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public boolean isConnected() throws MqttsnBackendException {
return connected;
}


@Override
public void close() {
connected = false;
Expand Down

0 comments on commit 115c73f

Please sign in to comment.