forked from monicasarbu/topbeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
48 lines (38 loc) · 1.07 KB
/
sync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package publisher
import (
"github.com/elastic/libbeat/common"
"github.com/elastic/libbeat/outputs"
)
type syncPublisher struct {
messageWorker
pub *PublisherType
}
type syncClient func(message) bool
func newSyncPublisher(pub *PublisherType) *syncPublisher {
s := &syncPublisher{pub: pub}
s.messageWorker.init(&pub.wsPublisher, 1000, newPreprocessor(pub, s))
return s
}
func (p *syncPublisher) client() eventPublisher {
return syncClient(p.forward)
}
func (p *syncPublisher) onStop() {}
func (p *syncPublisher) onMessage(m message) {
signal := outputs.NewSplitSignaler(m.context.signal, len(p.pub.Output))
m.context.signal = signal
for _, o := range p.pub.Output {
o.send(m)
}
}
func (c syncClient) PublishEvent(ctx *context, event common.MapStr) bool {
return c(message{context: *ctx, event: event})
}
func (c syncClient) PublishEvents(ctx *context, events []common.MapStr) bool {
return c(message{context: *ctx, events: events})
}
func (p *syncPublisher) forward(m message) bool {
sync := outputs.NewSyncSignal()
m.context.signal = sync
p.send(m)
return sync.Wait()
}