Added mDNS Daemon which will resolve hal.local domain

This commit is contained in:
Ziver Koc 2021-08-24 01:24:49 +02:00
parent 68c7755e7e
commit 291c4cb42a
11 changed files with 46 additions and 16 deletions

View file

@ -124,7 +124,6 @@ public class HalServer {
logger.info("External https server up and running at: " + externalServerUrl);
} else {
logger.warning("Missing '" + CONFIG_HTTP_EXTERNAL_PORT + "' and '" + CONFIG_HTTP_EXTERNAL_DOMAIN + "' configuration, will not setup external http server.");
return;
}
// ------------------------------------

View file

@ -0,0 +1,30 @@
package se.hal.daemon;
import se.hal.intf.HalDaemon;
import zutil.log.LogUtil;
import zutil.net.dns.MulticastDnsServer;
import java.io.IOException;
import java.net.InetAddress;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
public class HalMulticastDnsDaemon implements HalDaemon {
private static final Logger logger = LogUtil.getLogger();
private MulticastDnsServer server;
@Override
public void initiate(ScheduledExecutorService executor) {
try {
server = new MulticastDnsServer();
server.addEntry("hal.local", InetAddress.getLocalHost());
server.start();
} catch (IOException e) {
logger.log(Level.SEVERE, "Was unable to start mDNS Server.", e);
}
}
}

View file

@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SensorDataAggregatorDaemon implements HalDaemon {
public class SensorDataAggregatorDaemon implements HalDaemon, Runnable {
private static final Logger logger = LogUtil.getLogger();
public enum AggregationPeriodLength{

View file

@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SensorDataCleanupDaemon implements HalDaemon {
public class SensorDataCleanupDaemon implements HalDaemon, Runnable {
private static final Logger logger = LogUtil.getLogger();
public void initiate(ScheduledExecutorService executor){
@ -44,7 +44,7 @@ public class SensorDataCleanupDaemon implements HalDaemon {
if (sensor.getUser() != null) {
cleanupSensorData(sensor.getId(), AggregationPeriodLength.FIVE_MINUTES, UTCTimeUtility.DAY_IN_MS); //clear 5-minute data older than a day
cleanupSensorData(sensor.getId(), AggregationPeriodLength.HOUR, UTCTimeUtility.WEEK_IN_MS); //clear 1-hour data older than a week
//cleanupSensorData(sensor.getId(), AggregationPeriodLength.day, TimeUtility.INFINITY); //clear 1-day data older than infinity
//cleanupSensorData(sensor.getId(), AggregationPeriodLength.day, TimeUtility.INFINITY); //clear 1-day data older than infinity
//cleanupSensorData(sensor.getId(), AggregationPeriodLength.week, TimeUtility.INFINITY); //clear 1-week data older than infinity
}
}
@ -54,10 +54,10 @@ public class SensorDataCleanupDaemon implements HalDaemon {
* Will clear periods if they are too old.
*
* @param sensorId
* @Param clearPeriodlength Will clear periods with this length
* @Param cleanupPeriodLength Will clear periods with this length
* @param olderThan Data must be older than this many ms to be cleared from the DB
*/
private void cleanupSensorData(long sensorId, AggregationPeriodLength cleanupPeriodlength, long olderThan){
private void cleanupSensorData(long sensorId, AggregationPeriodLength cleanupPeriodLength, long olderThan){
DBConnection db = HalContext.getDB();
PreparedStatement stmt = null;
try {
@ -67,7 +67,7 @@ public class SensorDataCleanupDaemon implements HalDaemon {
+ "AND timestamp_end-timestamp_start == ?"
+ "AND timestamp_end < ?");
stmt.setLong(1, sensorId);
switch(cleanupPeriodlength){
switch(cleanupPeriodLength){
case SECOND: stmt.setLong(2, UTCTimeUtility.SECOND_IN_MS-1); break;
case MINUTE: stmt.setLong(2, UTCTimeUtility.MINUTE_IN_MS-1); break;
case FIVE_MINUTES: stmt.setLong(2, UTCTimeUtility.FIVE_MINUTES_IN_MS-1); break;

View file

@ -5,7 +5,7 @@ import java.util.concurrent.ScheduledExecutorService;
/**
* Defines a standalone process that will run parallel to the main application
*/
public interface HalDaemon extends Runnable {
public interface HalDaemon {
/**
* Setup the execution of the daemon with the provided executor.

View file

@ -3,11 +3,12 @@
"name": "Hal-Core",
"description": "Plugin contains core logic for running Hal.",
"interfaces": [
{"se.hal.intf.HalDatabaseUpgrade": "se.hal.HalCoreDatabaseUpgrade"},
{"se.hal.intf.HalDatabaseUpgrade": "se.hal.HalCoreDatabaseUpgrade"},
{"se.hal.intf.HalAbstractControllerManager": "se.hal.EventControllerManager"},
{"se.hal.intf.HalAbstractControllerManager": "se.hal.SensorControllerManager"},
{"se.hal.intf.HalAbstractControllerManager": "se.hal.EventControllerManager"},
{"se.hal.intf.HalAbstractControllerManager": "se.hal.SensorControllerManager"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.HalMulticastDnsDaemon"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"},
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"},
@ -29,6 +30,7 @@
{"se.hal.intf.HalTrigger": "se.hal.trigger.EventTrigger"},
{"se.hal.intf.HalTrigger": "se.hal.trigger.SensorTrigger"},
{"se.hal.intf.HalTrigger": "se.hal.trigger.TimerTrigger"},
{"se.hal.intf.HalAction": "se.hal.action.SendEventAction"}
]
}