Skip to content

Instantly share code, notes, and snippets.

@s-l-teichmann
Last active January 18, 2019 12:00
Show Gist options
  • Save s-l-teichmann/0df6fbcd18bd6aaa07543e62d912441e to your computer and use it in GitHub Desktop.
Save s-l-teichmann/0df6fbcd18bd6aaa07543e62d912441e to your computer and use it in GitHub Desktop.
diff -r 2e0936c9783e broadcast/alarmstream.go
--- a/broadcast/alarmstream.go Thu Jan 17 13:36:18 2019 +0100
+++ b/broadcast/alarmstream.go Fri Jan 18 12:59:27 2019 +0100
@@ -181,6 +181,15 @@
return nil
}
+func (asb *AlarmStreamBroker) heartbeat() {
+ // TODO: Implement me!
+}
+
+func (asb *AlarmStreamBroker) HandleHeartbeat(json.RawMessage) error {
+ asb.cmds <- func() { asb.heartbeat() }
+ return nil
+}
+
// HandleAlarm is the entry point for "Alarm" events.
func (asb *AlarmStreamBroker) HandleAlarm(msg json.RawMessage) error {
return asb.handle(msg, (*AlarmStreamBroker).handleAlarm)
diff -r 2e0936c9783e broadcast/pointstream.go
--- a/broadcast/pointstream.go Thu Jan 17 13:36:18 2019 +0100
+++ b/broadcast/pointstream.go Fri Jan 18 12:59:27 2019 +0100
@@ -210,6 +210,17 @@
return nil
}
+func (psb *PointstreamBroker) heartbeat() {
+ // TODO: Implement me!
+}
+
+// Handle the heartbeat from the Listen/Notify receiver.
+func (psb *PointstreamBroker) HandleHeartbeat(json.RawMessage) error {
+ // Move to pointstream main.
+ psb.cmds <- func() { psb.heartbeat() }
+ return nil
+}
+
func (psb *PointstreamBroker) registerClient(
key string,
geom wkt.Geom,
diff -r 2e0936c9783e broadcast/receiver.go
--- a/broadcast/receiver.go Thu Jan 17 13:36:18 2019 +0100
+++ b/broadcast/receiver.go Fri Jan 18 12:59:27 2019 +0100
@@ -82,8 +82,15 @@
return err
}
+ ticker := time.NewTicker(time.Minute)
+ defer ticker.Stop()
+
for {
select {
+ case <-ticker.C:
+ rcv.dispatch(`{"type": "hb-light`)
+ rcv.dispatch(`{"type": "hb-alarm"`)
+
case e := <-listener.Notify:
if e == nil {
continue
diff -r 2e0936c9783e controllers/controller.go
--- a/controllers/controller.go Thu Jan 17 13:36:18 2019 +0100
+++ b/controllers/controller.go Fri Jan 18 12:59:27 2019 +0100
@@ -12,11 +12,13 @@
)
const (
- pointstreamType = "stroke"
- alarmType = "Alarm"
- allClearType = "Entwarnung"
- testAlarmType = "Testalarm"
- testAllClearType = "Testentwarnung"
+ pointstreamHeartbeatType = "hb-light"
+ alarmHeartbeatType = "hb-alarm"
+ pointstreamType = "stroke"
+ alarmType = "Alarm"
+ allClearType = "Entwarnung"
+ testAlarmType = "Testalarm"
+ testAllClearType = "Testentwarnung"
)
// Controller encapsulates the state known to all endpoints.
@@ -44,7 +46,9 @@
rcv := broadcast.NewReceiver(dsn)
rcv.AddHandler(pointstreamType, c.psb.Handle)
+ rcv.AddHandler(pointstreamHeartbeatType, c.psb.HandleHeartbeat)
rcv.AddHandler(alarmType, c.asb.HandleAlarm)
+ rcv.AddHandler(alarmHeartbeatType, c.asb.HandleHeartbeat)
rcv.AddHandler(allClearType, c.asb.HandleAllClear)
rcv.AddHandler(testAlarmType, c.asb.HandleTestAlarm)
rcv.AddHandler(testAllClearType, c.asb.HandleTestAllClear)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment