-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.go
78 lines (67 loc) · 1.84 KB
/
processor.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
package peas
import (
"errors"
"github.com/procyon-projects/goo"
"sync"
)
type PeaProcessor interface {
BeforePeaInitialization(peaName string, pea interface{}) (interface{}, error)
AfterPeaInitialization(peaName string, pea interface{}) (interface{}, error)
}
type PeaProcessors struct {
processors map[string]PeaProcessor
mu sync.RWMutex
}
func NewPeaProcessors() *PeaProcessors {
return &PeaProcessors{
make(map[string]PeaProcessor, 0),
sync.RWMutex{},
}
}
func (p *PeaProcessors) AddPeaProcessor(processor PeaProcessor) error {
if processor == nil {
return errors.New("processor cannot be null")
}
p.mu.Lock()
processorType := goo.GetType(processor)
if _, ok := p.processors[processorType.GetFullName()]; ok {
return errors.New("You have already registered this processor : " + processorType.GetFullName())
}
p.processors[processorType.GetFullName()] = processor
p.mu.Unlock()
return nil
}
func (p *PeaProcessors) RemoveProcessor(processor PeaProcessor) {
if processor == nil {
return
}
p.mu.Lock()
processorType := goo.GetType(processor)
if _, ok := p.processors[processorType.GetFullName()]; ok {
delete(p.processors, processorType.GetFullName())
}
p.mu.Unlock()
}
func (p *PeaProcessors) GetProcessors() []PeaProcessor {
processors := make([]PeaProcessor, 0)
p.mu.Lock()
for _, val := range p.processors {
processors = append(processors, val)
}
p.mu.Unlock()
return processors
}
func (p *PeaProcessors) GetProcessorsCount() int {
return len(p.processors)
}
func (p *PeaProcessors) RemoveAllProcessor() {
p.mu.Lock()
p.processors = make(map[string]PeaProcessor, 0)
p.mu.Unlock()
}
type PeaDefinitionRegistryProcessor interface {
AfterPeaDefinitionRegistryInitialization(registry PeaDefinitionRegistry)
}
type PeaFactoryProcessor interface {
AfterPeaFactoryInitialization(factory ConfigurablePeaFactory)
}