-
Notifications
You must be signed in to change notification settings - Fork 0
/
DummyController.go
72 lines (57 loc) · 1.63 KB
/
DummyController.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
package examples
import (
"github.com/pip-services3-go/pip-services3-commons-go/config"
"github.com/pip-services3-go/pip-services3-commons-go/refer"
"github.com/pip-services3-go/pip-services3-commons-go/run"
"github.com/pip-services3-go/pip-services3-components-go/log"
)
type DummyController struct {
timer *run.FixedRateTimer
logger *log.CompositeLogger
message string
counter int
}
func NewDummyController() *DummyController {
c := &DummyController{
logger: log.NewCompositeLogger(),
message: "Hello World!",
counter: 0,
}
c.timer = run.NewFixedRateTimerFromTask(c, 1000, 1000)
return c
}
func (c *DummyController) Message() string {
return c.message
}
func (c *DummyController) SetMessage(value string) {
c.message = value
}
func (c *DummyController) Counter() int {
return c.counter
}
func (c *DummyController) SetCounter(value int) {
c.counter = value
}
func (c *DummyController) Configure(config *config.ConfigParams) {
c.message = config.GetAsStringWithDefault("message", c.message)
}
func (c *DummyController) SetReferences(references refer.IReferences) {
c.logger.SetReferences(references)
}
func (c *DummyController) IsOpen() bool {
return c.timer.IsStarted()
}
func (c *DummyController) Open(correlationId string) error {
c.timer.Start()
c.logger.Trace(correlationId, "Dummy controller opened")
return nil
}
func (c *DummyController) Close(correlationId string) error {
c.timer.Stop()
c.logger.Trace(correlationId, "Dummy controller closed")
return nil
}
func (c *DummyController) Notify(correlationId string, args *run.Parameters) {
c.logger.Info(correlationId, "%d - %s", c.counter, c.message)
c.counter++
}