forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.go
58 lines (47 loc) · 1.18 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
49
50
51
52
53
54
55
56
57
58
package publisher
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs"
)
type syncPublisher struct {
pub *PublisherType
}
type syncClient func(message) bool
func newSyncPublisher(pub *PublisherType, hwm, bulkHWM int) *syncPublisher {
return &syncPublisher{pub: pub}
}
func (p *syncPublisher) client() eventPublisher {
return p
}
func (p *syncPublisher) PublishEvent(ctx Context, event common.MapStr) bool {
msg := message{context: ctx, event: event}
return p.send(msg)
}
func (p *syncPublisher) PublishEvents(ctx Context, events []common.MapStr) bool {
msg := message{context: ctx, events: events}
return p.send(msg)
}
func (p *syncPublisher) send(m message) bool {
if p.pub.disabled {
debug("publisher disabled")
outputs.SignalCompleted(m.context.Signal)
return true
}
signal := m.context.Signal
sync := outputs.NewSyncSignal()
if len(p.pub.Output) > 1 {
m.context.Signal = outputs.NewSplitSignaler(sync, len(p.pub.Output))
} else {
m.context.Signal = sync
}
for _, o := range p.pub.Output {
o.send(m)
}
ok := sync.Wait()
if ok {
outputs.SignalCompleted(signal)
} else if signal != nil {
signal.Failed()
}
return ok
}