/
framework.go
executable file
·47 lines (35 loc) · 987 Bytes
/
framework.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
package framework
import (
"sync"
"github.com/TIBCOSoftware/flogo-contrib/activity/inference/model"
)
var (
frameworksMu sync.Mutex
frameworks = make(map[string]model.Framework)
)
func init() {
frameworks = make(map[string]model.Framework)
}
// Register is used by the init() func from each framework to register
func Register(framework model.Framework) {
frameworksMu.Lock()
defer frameworksMu.Unlock()
if framework == nil {
panic("framework.Register: framework is nil")
}
id := framework.FrameworkTyp()
if _, dup := frameworks[id]; dup {
panic("framework.Register: framework already registered " + id)
}
// copy on write to avoid synchronization on access
newFrameworks := make(map[string]model.Framework, len(frameworks))
for k, v := range frameworks {
newFrameworks[k] = v
}
newFrameworks[id] = framework
frameworks = newFrameworks
}
// Get is used to fecth the specified framework
func Get(id string) model.Framework {
return frameworks[id]
}