Skip to content

Commit

Permalink
Merge pull request #9 from DerTomm/development
Browse files Browse the repository at this point in the history
Pull request for release 1.1 changes
  • Loading branch information
DerTomm authored Feb 15, 2020
2 parents faf3c11 + 0a16b96 commit 692fc08
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,32 @@ The file contains the following parameters:

## System requirements

The application needs Java Runtime version 1.8 to run.
Starting with release 1.1 the application needs Java Runtime version 13 or later to run. Older releases can be used with Java 8.

## Usage

After downloading and extracting the release archive please check and modify the properties file first. Then you can start the application with

`java -jar serialMqttBridge-<VERSION>.jar`.

## Developers

Developers can clone the code and build the application using Maven:

`mvn package`

Please note: Unfortunately there is no Maven Central artifact of the used `jssc` library yet. So if you want to compile the code yourself you have to download the dependency from Github (https://github.com/java-native/jssc/releases/download/v2.9.1/jssc-2.9.1.jar) and import it into your local Maven repository:

```
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=com.github.java-native \
-DartifactId=jssc \
-Dversion=2.9.1 \
-Dpackaging=jar \
-DgeneratePom=true
```

If you want to create your own preprocessor plugin just implement the according interfaces in the _de.reitho.serialMqttBridge.plugins_ package, put the classes into the classpath and define them in the config file.

## Outlook
Expand Down
21 changes: 10 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

<groupId>de.reitho</groupId>
<artifactId>serialMqttBridge</artifactId>
<version>1.0.2</version>
<version>1.1</version>
<name>SerialMqttBridge</name>

<properties>
<java.version>1.8</java.version>
<java.version>13</java.version>
</properties>

<build>
Expand All @@ -17,7 +17,7 @@

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand All @@ -28,7 +28,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<version>3.2.0</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
Expand All @@ -39,7 +39,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -74,28 +74,27 @@
<dependencies>

<dependency>
<groupId>org.scream3r</groupId>
<groupId>com.github.java-native</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
<version>2.9.1</version>
</dependency>


<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
<version>1.2.3</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
<version>0.9.12</version>
</dependency>

<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
<version>1.2.2</version>
</dependency>

</dependencies>
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/de/reitho/serialMqttBridge/SerialMqttBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.Set;

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,7 +18,7 @@

public class SerialMqttBridge {

Logger logger = LoggerFactory.getLogger(SerialMqttBridge.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SerialMqttBridge.class);

private MqttPublishPreprocessingPlugin mqttPublishPreprocessor;
private SerialSendPreprocessingPlugin serialSendPreprocessor;
Expand Down Expand Up @@ -45,25 +49,25 @@ public void launch() {
try {

// Get config handler instance
logger.info("Reading configuration file");
LOGGER.info("Reading configuration file");
configHandler = ConfigHandler.getInstance();

// Instantiate preprocessor plugins if defined in config
logger.info("Searching for plugins");
LOGGER.info("Searching for plugins");
loadPlugins();

// Establish serial connection
logger.info("Creating serial handler and establish connection");
LOGGER.info("Creating serial handler and establish connection");
serialHandler = SerialHandler.getInstance(this);

// Establish MQTT connection
logger.info("Creating MQTT handler and establish connection");
LOGGER.info("Creating MQTT handler and establish connection");
mqttHandler = MqttHandler.getInstance(this);

isInitialized = true;
}
catch (Exception e) {
logger.error("An error occured.", e);
LOGGER.error("An error occured.", e);
System.exit(1);
}

Expand All @@ -74,7 +78,11 @@ public void launch() {
*/
private void loadPlugins() throws Exception {

Reflections reflections = new Reflections();
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("de.reitho.serialMqttBridge.plugins", ClasspathHelper.contextClassLoader()))
.setScanners(new SubTypesScanner())
.filterInputsBy(new FilterBuilder().includePackage("de.reitho.serialMqttBridge.plugins")));

/*
* Find all MQTT publishing preprocessor plugins and load the one the user defined in configuration file - otherwise skip plugin instantiation.
Expand All @@ -85,15 +93,15 @@ private void loadPlugins() throws Exception {
Set<Class<? extends MqttPublishPreprocessingPlugin>> mqttPreprocessorPlugins = reflections.getSubTypesOf(MqttPublishPreprocessingPlugin.class);
for (Class<? extends MqttPublishPreprocessingPlugin> c : mqttPreprocessorPlugins) {
if (c.getName().equalsIgnoreCase(configuredMqttPreprocessorPlugin)) {
mqttPublishPreprocessor = c.newInstance();
mqttPublishPreprocessor = c.getDeclaredConstructor().newInstance();
break;
}
}
if (mqttPublishPreprocessor == null) {
throw new Exception("Defined MQTT publish preproecessor plugin could not be found.");
}

logger.info("Using MQTT publish preprocessor plugin " + mqttPublishPreprocessor);
LOGGER.info("Using MQTT publish preprocessor plugin " + mqttPublishPreprocessor);
}

/*
Expand All @@ -105,15 +113,15 @@ private void loadPlugins() throws Exception {
Set<Class<? extends SerialSendPreprocessingPlugin>> serialPreprocessorPlugins = reflections.getSubTypesOf(SerialSendPreprocessingPlugin.class);
for (Class<? extends SerialSendPreprocessingPlugin> c : serialPreprocessorPlugins) {
if (c.getName().equalsIgnoreCase(configuredSerialPreprocessorPlugin)) {
serialSendPreprocessor = c.newInstance();
serialSendPreprocessor = c.getDeclaredConstructor().newInstance();
break;
}
}
if (serialSendPreprocessor == null) {
throw new Exception("Defined serial send preproecessor plugin could not be found.");
}

logger.info("Using serial send preprocessor plugin " + serialSendPreprocessor);
LOGGER.info("Using serial send preprocessor plugin " + serialSendPreprocessor);
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
<!-- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>

<appender name="LOGFILE" class="ch.qos.logback.core.FileAppender">
<file>./logs/SerialMqttBridge.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
<appender name="LOGFILE" class="ch.qos.logback.core.FileAppender">
<file>./logs/SerialMqttBridge.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
<!-- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n -->
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</appender>

<!-- Send logging output to both console and log file -->
<root level="INFO" additivity="true">
<appender-ref ref="LOGFILE" />
<appender-ref ref="STDOUT" />
</root>
<root level="INFO" additivity="true">
<appender-ref ref="LOGFILE" />
<appender-ref ref="STDOUT" />
</root>

</configuration>

0 comments on commit 692fc08

Please sign in to comment.