cfha/monitor/engine.go

52 lines
878 B
Go
Raw Normal View History

2015-08-21 17:27:26 +00:00
package monitor
import (
)
type Engine struct {
Input chan Result
output []GenericHandler
}
func CreateEngine(handlers []GenericHandler) *Engine {
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
}
}