cfha/monitor/engine.go

49 lines
868 B
Go
Raw Normal View History

2015-08-21 17:27:26 +00:00
package monitor
type Engine struct {
Input chan Result
output []*GenericHandler
2015-08-21 17:27:26 +00:00
}
func CreateEngine(handlers []*GenericHandler) *Engine {
2015-08-21 17:27:26 +00:00
input := make(chan Result)
engine := Engine{
input,
handlers,
}
e := &engine
go e.startProcessor()
return e
}
func (this *Engine) startProcessor() {
statuses := make(map[string]Status)
for true {
result := <-this.Input
//No transition if we don't exist
if result.Status == statuses[result.RecordValue] {
continue
}
//Create a record with to, from
change := Transition{
result.Status,
statuses[result.RecordValue],
result.RecordValue,
}
//Send the record to everyone who cares
for _, relay := range this.output {
relay.channel<- change
}
//And set our new status
statuses[result.RecordValue] = result.Status
}
}