crawler_manager_go/crawler_manager_event.go
2017-05-11 18:19:06 +09:00

136 lines
1.9 KiB
Go

package crawler_manager
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/config_manager"
"loafle.com/overflow/agent_api/observer/messages"
"fmt"
)
func listenEvent() {
go listenConfigLoaded();
go listenAgentStop()
go listenAddSensor();
go listenRemoveSensor();
go listenUpdateSensor();
go listenUpdateCrawler()
}
func listenConfigLoaded() {
ch := make(chan interface{}, 0)
observer.Add(messages.CFG_LOADED, ch)
o := <-ch
cm := o.(config_manager.ConfigManager)
GetInstance().ConfigMgr = cm;
SettingPath()
err := GetInstance().init();
if err != nil {
//FIXME:: noti err
return;
}
observer.Notify(messages.CRM_READY, nil)
}
func listenAgentStop() {
ch := make(chan interface{}, 0)
observer.Add(messages.CLT_STOPPED, ch)
o := <-ch
fmt.Println(o)
GetInstance().stopContainerAll()
observer.Notify(messages.CRM_STOPPED, nil)
}
func listenAddSensor() {
ch := make(chan interface{}, 0)
observer.Add(messages.SCF_SENSOR_ADD_DONE, ch);
o := <-ch
str := o.(string)
fmt.Println(str)
err := GetInstance().addSensor(str)
if err != nil {
//FIXME:: noti err
return
}
observer.Notify(messages.CRM_SENSOR_ADD_DONE, nil)
}
func listenRemoveSensor() {
ch := make(chan interface{}, 0)
observer.Add(messages.CLT_SENSOR_REMOVE_DONE, ch);
o := <-ch
str := o.(string)
GetInstance().removeSensor(str)
observer.Notify(messages.CRM_SENSOR_REMOVE_DONE, nil)
}
func listenUpdateSensor() {
ch := make(chan interface{}, 0)
observer.Add(messages.SCF_SENSOR_UPDATE_DONE, ch);
o := <-ch
container := o.(string)
err := GetInstance().runAndInitContainerOne(&container)
if err != nil {
//FIXME:: noti err
return
}
observer.Notify(messages.CRM_SENSOR_UPDATE_DONE, nil)
}
func listenUpdateCrawler() {
ch := make(chan interface{}, 0)
observer.Add(messages.CLT_CRM_UPDATE_DONE, ch);
o := <-ch
fmt.Println(o)
//FIXME::update crawler
observer.Notify(messages.CRM_UPDATE_DONE, nil)
}