forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_reg.go
38 lines (31 loc) · 887 Bytes
/
queue_reg.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
package queue
import (
"fmt"
"github.com/elastic/beats/libbeat/common"
)
// Global queue type registry for configuring and loading a queue instance
// via common.Config
var queueReg = map[string]Factory{}
// RegisterType registers a new queue type.
func RegisterType(name string, f Factory) {
if queueReg[name] != nil {
panic(fmt.Errorf("queue type '%v' exists already", name))
}
queueReg[name] = f
}
// FindFactory retrieves a queue types constructor. Returns nil if queue type is unknown
func FindFactory(name string) Factory {
return queueReg[name]
}
// Load instantiates a new queue.
func Load(eventer Eventer, config common.ConfigNamespace) (Queue, error) {
t, cfg := config.Name(), config.Config()
if t == "" {
t = "mem"
}
factory := FindFactory(t)
if factory == nil {
return nil, fmt.Errorf("queue type %v undefined", t)
}
return factory(eventer, cfg)
}