-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 1.49 KB
/
main.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
package main
import (
"log"
"main/actor"
messages "main/messages/proto"
"main/remote"
"time"
"github.com/google/uuid"
)
type Sender struct {
adderPid uuid.UUID
}
func (s *Sender) Recieve(context *actor.ActorContext) {
switch msg := context.Message.Message().(type) {
case *messages.AdderMessage:
msg.IsAdd = true
context.Send(s.adderPid, msg)
context.Become(s.Subtract)
default:
log.Printf("Ivalid message type")
}
}
func (s *Sender) Subtract(context *actor.ActorContext) {
switch msg := context.Message.Message().(type) {
case *messages.AdderMessage:
msg.IsAdd = false
context.Send(s.adderPid, msg)
context.Become(s.Recieve)
default:
log.Printf("Ivalid message type")
}
}
func main() {
system := actor.NewSystem()
context := system.Root
remote := remote.NewRemote(system, remote.NewConfig("192.168.1.105:8000"))
remote.Start()
adder, _ := remote.SpawnPid("Adder", "192.168.1.125:8080")
sender := context.InitActor(&Sender{
adderPid: *adder,
}, "Sender")
context.Send(*sender, &messages.AdderMessage{Amount: 6})
context.Send(*sender, &messages.AdderMessage{Amount: 1})
context.Send(*sender, &messages.AdderMessage{Amount: 8})
context.Send(*sender, &messages.AdderMessage{Amount: 1})
context.Send(*sender, &messages.AdderMessage{Amount: 4})
context.Send(*sender, &messages.AdderMessage{Amount: 10})
context.Send(*sender, &messages.AdderMessage{Amount: 89})
context.Send(*sender, &messages.AdderMessage{Amount: 6})
system.PrintValues()
time.Sleep(60 * time.Second)
}