From 7d66206815d35c9136f039d119ca0a5ea5cd387b Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 9 Mar 2016 03:49:27 +0100 Subject: [PATCH] Rename Daemon to MultiCollector --- main.go | 10 +++++----- respond/collector.go | 17 ----------------- respond/daemon.go | 33 --------------------------------- respond/multi_collector.go | 33 +++++++++++++++++++++++++++++++++ respond/respond.go | 22 ++++++++++++++++++++++ 5 files changed, 60 insertions(+), 55 deletions(-) delete mode 100644 respond/daemon.go create mode 100644 respond/multi_collector.go create mode 100644 respond/respond.go diff --git a/main.go b/main.go index 77b3666..e986639 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ var ( configFile string config *models.Config wsserverForNodes *websocketserver.Server - respondDaemon *respond.Daemon + multiCollector *respond.MultiCollector nodes = models.NewNodes() //aliases = models.NewNodes() ) @@ -50,7 +50,7 @@ func main() { } if config.Respondd.Enable { - respondDaemon = respond.NewDaemon(func(coll *respond.Collector, res *respond.Response) { + multiCollector = respond.NewMultiCollector(func(coll *respond.Collector, res *respond.Response) { switch coll.CollectType { case "neighbours": @@ -75,7 +75,7 @@ func main() { log.Println("unknown CollectType:", coll.CollectType) } }) - go respondDaemon.ListenAndSend(collectInterval) + go multiCollector.ListenAndSend(collectInterval) } //TODO bad @@ -92,7 +92,7 @@ func main() { if wsserverForNodes != nil { wsserverForNodes.Close() } - if respondDaemon != nil { - respondDaemon.Close() + if multiCollector != nil { + multiCollector.Close() } } diff --git a/respond/collector.go b/respond/collector.go index 4b738b9..5358d01 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -6,23 +6,6 @@ import ( "time" ) -const ( - // default multicast group used by announced - multiCastGroup string = "ff02:0:0:0:0:0:2:1001" - - // default udp port used by announced - port string = "1001" - - // maximum receivable size - maxDataGramSize int = 8192 -) - -//Response of the respond request -type Response struct { - Address net.UDPAddr - Raw []byte -} - //Collector for a specificle respond messages type Collector struct { CollectType string diff --git a/respond/daemon.go b/respond/daemon.go deleted file mode 100644 index 5dd54b2..0000000 --- a/respond/daemon.go +++ /dev/null @@ -1,33 +0,0 @@ -package respond - -import "time" - -//Daemon struct -type Daemon struct { - collectors []*Collector -} - -//NewDaemon create a list of collectors -func NewDaemon(parseFunc func(coll *Collector, res *Response)) *Daemon { - return &Daemon{ - collectors: []*Collector{ - NewCollector("statistics", parseFunc), - NewCollector("nodeinfo", parseFunc), - NewCollector("neighbours", parseFunc), - }, - } -} - -//ListenAndSend on Collection -func (daemon *Daemon) ListenAndSend(collectInterval time.Duration) { - for _, col := range daemon.collectors { - col.sender(collectInterval) - } -} - -//Close all Collections -func (daemon *Daemon) Close() { - for _, col := range daemon.collectors { - col.Close() - } -} diff --git a/respond/multi_collector.go b/respond/multi_collector.go new file mode 100644 index 0000000..8f4253a --- /dev/null +++ b/respond/multi_collector.go @@ -0,0 +1,33 @@ +package respond + +import "time" + +//MultiCollector struct +type MultiCollector struct { + collectors []*Collector +} + +//NewMultiCollector create a list of collectors +func NewMultiCollector(parseFunc func(coll *Collector, res *Response)) *MultiCollector { + return &MultiCollector{ + collectors: []*Collector{ + NewCollector("statistics", parseFunc), + NewCollector("nodeinfo", parseFunc), + NewCollector("neighbours", parseFunc), + }, + } +} + +//ListenAndSend on Collection +func (multi *MultiCollector) ListenAndSend(collectInterval time.Duration) { + for _, col := range multi.collectors { + col.sender(collectInterval) + } +} + +//Close all Collections +func (multi *MultiCollector) Close() { + for _, col := range multi.collectors { + col.Close() + } +} diff --git a/respond/respond.go b/respond/respond.go new file mode 100644 index 0000000..f347121 --- /dev/null +++ b/respond/respond.go @@ -0,0 +1,22 @@ +package respond + +import ( + "net" +) + +const ( + // default multicast group used by announced + multiCastGroup string = "ff02:0:0:0:0:0:2:1001" + + // default udp port used by announced + port string = "1001" + + // maximum receivable size + maxDataGramSize int = 8192 +) + +//Response of the respond request +type Response struct { + Address net.UDPAddr + Raw []byte +}