Added mDNS Daemon which will resolve hal.local domain
This commit is contained in:
parent
68c7755e7e
commit
291c4cb42a
11 changed files with 46 additions and 16 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
|
|
|
|||
30
hal-core/src/se/hal/daemon/HalMulticastDnsDaemon.java
Normal file
30
hal-core/src/se/hal/daemon/HalMulticastDnsDaemon.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ java.util.logging.FileHandler.formatter = zutil.log.CompactLogFormatter
|
|||
zutil.level = ALL
|
||||
zutil.db.bean.level = INFO
|
||||
zutil.net.http.page.HttpFilePage.level = INFO
|
||||
zutil.net.dns.MulticastDnsServer.level = FINE
|
||||
|
||||
# Hal Core
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,4 @@ public class SmartHomeDaemon implements HalDaemon {
|
|||
HalServer.registerExternalPage(ENDPOINT_SMARTHOME, new SmartHomePage(smartHome));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public class SmartHomeImpl extends SmartHomeApp implements TokenRegistrationList
|
|||
*
|
||||
* TODO: https://developers.google.com/assistant/smarthome/traits/temperaturesetting
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public SyncResponse onSync(SyncRequest syncRequest, Map<?, ?> headers) {
|
||||
logger.fine("Received sync request.");
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import static zutil.ui.UserMessageManager.*;
|
||||
|
||||
public class PCDataSynchronizationClient implements HalDaemon {
|
||||
public class PCDataSynchronizationClient implements HalDaemon, Runnable {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static final long SYNC_INTERVAL = 5 * 60 * 1000; // 5 min
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ZigbeeAttributeUpdateDaemon implements HalDaemon {
|
||||
public class ZigbeeAttributeUpdateDaemon implements HalDaemon, Runnable {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue