/
invokers.go
77 lines (68 loc) · 2.01 KB
/
invokers.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
package actorkit
import (
"time"
)
//***********************************
// Supervisor Events
//***********************************
// SupervisorEvent defines an event type which is published by the EventSupervisingInvoker.
type SupervisorEvent struct {
Stat Stat
Addr Addr
Actor string
Time time.Time
Directive Directive
Cause interface{}
}
//****************************************
// EventSupervisingInvoker
//****************************************
// EventSupervisingInvoker implements the SupervisorInvoker interface and simply
// invokes events for all invocation received.
type EventSupervisingInvoker struct {
Event EventStream
}
// InvokedStop emits event containing stopped details.
func (es *EventSupervisingInvoker) InvokedStop(cause interface{}, stat Stat, addr Addr, target Actor) {
es.Event.Publish(SupervisorEvent{
Addr: addr,
Stat: stat,
Cause: cause,
Time: time.Now(),
Actor: target.Addr(),
Directive: StopDirective,
})
}
// InvokedKill emits event containing killed details.
func (es *EventSupervisingInvoker) InvokedKill(cause interface{}, stat Stat, addr Addr, target Actor) {
es.Event.Publish(SupervisorEvent{
Addr: addr,
Stat: stat,
Cause: cause,
Time: time.Now(),
Actor: target.Addr(),
Directive: KillDirective,
})
}
// InvokedDestroy emits event containing destroyed details.
func (es *EventSupervisingInvoker) InvokedDestroy(cause interface{}, stat Stat, addr Addr, target Actor) {
es.Event.Publish(SupervisorEvent{
Addr: addr,
Stat: stat,
Cause: cause,
Time: time.Now(),
Actor: target.Addr(),
Directive: DestroyDirective,
})
}
// InvokedRestart emits event containing restart details.
func (es *EventSupervisingInvoker) InvokedRestart(cause interface{}, stat Stat, addr Addr, target Actor) {
es.Event.Publish(SupervisorEvent{
Addr: addr,
Stat: stat,
Cause: cause,
Time: time.Now(),
Actor: target.Addr(),
Directive: RestartDirective,
})
}