代码拉取完成,页面将自动刷新
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()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。