1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
runner.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Nicolas Ruflin 提交于 2017-02-03 16:07 . Unify reloading (#3439)
package module
import (
"sync"
"github.com/elastic/beats/libbeat/publisher"
)
// Runner is a facade for a Wrapper that provides a simple interface
// for starting and stopping a Module.
type Runner interface {
// Start starts the Module. If Start is called more than once, only the
// first will start the Module.
Start()
// Stop stops the Module and waits for module's MetricSets to exit. The
// publisher.Client will be closed by Stop. If Stop is called more than
// once, only the first stop the Module and wait for it to exit.
Stop()
// Added to be consistent with cfgfile.Runner
ID() uint64
}
// NewRunner returns a Runner facade. The events generated by
// the Module will be published to a new publisher.Client generated from the
// pubClientFactory.
func NewRunner(pubClientFactory func() publisher.Client, mod *Wrapper) Runner {
return &runner{
done: make(chan struct{}),
mod: mod,
client: pubClientFactory(),
}
}
type runner struct {
done chan struct{}
wg sync.WaitGroup
startOnce sync.Once
stopOnce sync.Once
mod *Wrapper
client publisher.Client
}
func (mr *runner) Start() {
mr.startOnce.Do(func() {
output := mr.mod.Start(mr.done)
mr.wg.Add(1)
go func() {
defer mr.wg.Done()
PublishChannels(mr.client, output)
}()
})
}
func (mr *runner) Stop() {
mr.stopOnce.Do(func() {
close(mr.done)
mr.client.Close()
mr.wg.Wait()
})
}
func (mr *runner) ID() uint64 {
return mr.mod.Hash()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.6.9

搜索帮助

0d507c66 1850385 C8b1a773 1850385