-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontroller.go
59 lines (50 loc) · 1.41 KB
/
controller.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
package mmoa
// Monolithic Message-Oriented Application (MMOA)
// Controller
// Copyright © 2016 Eduard Sesigin. All rights reserved. Contacts: <claygod@yandex.ru>
import (
"github.com/claygod/mmoa/support"
"github.com/claygod/mmoa/tools"
)
// NewController - create a new Controller
func NewController(chBus chan *tools.Message) *Controller {
c := &Controller{
cid: NewCid(),
the: tools.NewThemes(),
chBus: chBus,
}
c.addBus()
c.addAggregator()
c.addTrash()
return c
}
// Controller - main struct.
type Controller struct {
the *tools.Themes
cid *Cid
bus *support.Bus
aggregator *support.Aggregator
chBus chan *tools.Message
}
// Handler - create a new handler
func (c *Controller) Handler(template string) *Handler {
h := NewHandler(template, c.chBus, c.aggregator, c.cid)
return h
}
// AddService - add the service to the handler
func (c *Controller) AddService(nameService tools.TypeSERVICE, chIn chan *tools.Message) {
c.bus.Set(nameService, chIn)
}
func (c *Controller) addBus() {
c.bus = support.NewBus(c.chBus)
}
func (c *Controller) addAggregator() {
chAggregator := make(chan *tools.Message, 1000)
c.aggregator = support.NewAggregator(chAggregator, c.chBus)
c.bus.Set(c.the.Service.Aggregator, chAggregator)
}
func (c *Controller) addTrash() {
chTrash := make(chan *tools.Message, 1000)
support.NewTrash(chTrash, c.chBus)
c.bus.Set(c.the.Service.Trash, chTrash)
}