-
Notifications
You must be signed in to change notification settings - Fork 198
/
output.go
91 lines (74 loc) · 1.5 KB
/
output.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package kafka
import (
"reflect"
scope_manager "github.com/eolinker/apinto/scope-manager"
"github.com/eolinker/apinto/drivers"
"github.com/eolinker/apinto/output"
"github.com/eolinker/eosc"
)
var _ output.IEntryOutput = (*Output)(nil)
var _ eosc.IWorker = (*Output)(nil)
type Output struct {
drivers.WorkerBase
producer Producer
//scopes []string
config *ProducerConfig
isRunning bool
}
func (o *Output) Output(entry eosc.IEntry) error {
p := o.producer
if p != nil {
return p.output(entry)
}
return eosc.ErrorWorkerNotRunning
}
func (o *Output) Start() error {
o.isRunning = true
p := o.producer
if p != nil {
return nil
}
p = newTProducer(o.config)
err := p.reset(o.config)
if err != nil {
return err
}
o.producer = p
scope_manager.Set(o.Id(), o, o.config.Scopes...)
return nil
}
func (o *Output) Reset(conf interface{}, workers map[eosc.RequireId]eosc.IWorker) error {
cfg, err := check(conf)
if err != nil {
return err
}
if reflect.DeepEqual(cfg, o.config) {
return nil
}
o.config = cfg
if o.isRunning {
p := o.producer
if p == nil {
p = newTProducer(o.config)
}
err = p.reset(o.config)
if err != nil {
return err
}
o.producer = p
}
scope_manager.Set(o.Id(), o, o.config.Scopes...)
return nil
}
func (o *Output) Stop() error {
scope_manager.Del(o.Id())
producer := o.producer
if producer != nil {
o.producer = nil
producer.close()
}
return nil
}
func (o *Output) CheckSkill(skill string) bool {
return output.CheckSkill(skill)
}