config_manager_go/init_method.go
2017-04-28 11:55:57 +09:00

49 lines
1.2 KiB
Go

package config_manager_go
import (
"loafle.com/overflow/agent_api/observer"
"loafle.com/overflow/agent_api/observer/messages"
)
func agentStartHandler() {
agentStart := make(chan interface{}, 0)
observer.Add(messages.AGENT_STARTED, agentStart)
go func() {
data := <-agentStart
path := data.(string)
// load global config
_configManager.loadGlobalConfig(path + "/" + "global.yaml")
// load all crawler configs
if err := _configManager.loadCrawlerConfigAll(); err != nil {
// error process
}
observer.Remove(messages.AGENT_STARTED, agentStart)
observer.Notify(messages.CONFIGMANAGER_LOADED, _configManager)
}()
}
func agentEndHandler() {
agentEnd := make(chan interface{}, 0)
observer.Add(messages.AGENT_WILL_STOPPED, agentEnd)
go func() {
_ = <-agentEnd
observer.Remove(messages.AGENT_WILL_STOPPED, agentEnd)
observer.Remove(messages.ADD_SENSOR_0,_configManager.addCh)
observer.Remove(messages.REMOVE_SENSOR_0,_configManager.removeCh)
}()
}
func addSensorHandler() {
observer.Add(messages.ADD_SENSOR_0,_configManager.addCh)
go _configManager.addConfig()
}
func removeSensorHandler() {
observer.Add(messages.REMOVE_SENSOR_0,_configManager.removeCh)
go _configManager.removeConfig()
}