-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss_rpc_server.go
98 lines (75 loc) · 1.95 KB
/
ss_rpc_server.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package states
import (
am "github.com/pancsta/asyncmachine-go/pkg/machine"
)
// ServerStatesDef contains all the states of the Client state machine.
type ServerStatesDef struct {
// errors
// ErrOnClient indicates an error added on the RPC worker, not the server
// worker.
ErrOnClient string
// basics
// Ready - Client is fully connected to the server.
Ready string
// rpc
RpcStarting string
RpcReady string
// TODO failsafe
// RetryingCall string
// CallRetryFailed string
ClientConnected string
// inherit from SharedStatesDef
*SharedStatesDef
}
// ServerGroupsDef contains all the state groups of the Client state machine.
type ServerGroupsDef struct {
*SharedGroupsDef
// Rpc is a group for RPC ready states.
Rpc S
}
// ServerStruct represents all relations and properties of ClientStates.
var ServerStruct = StructMerge(
// inherit from SharedStruct
SharedStruct,
am.Struct{
ssS.ErrOnClient: {Require: S{ssS.Exception}},
ssS.ErrNetwork: {
Require: S{am.Exception},
Remove: S{ssS.ClientConnected},
},
// inject Server states into HandshakeDone
// ssS.HandshakeDone: StateAdd(
// states.ConnectedStruct[ssS.HandshakeDone],
// am.State{
// Require: S{ssS.ClientConnected},
// }),
// Server
ssS.Start: {Add: S{ssS.RpcStarting}},
ssS.Ready: {
Auto: true,
Require: S{ssS.HandshakeDone, ssS.RpcReady},
},
ssS.RpcStarting: {
Require: S{ssS.Start},
Remove: sgS.Rpc,
},
ssS.RpcReady: {
Require: S{ssS.Start},
Remove: sgS.Rpc,
},
ssS.ClientConnected: {
Require: S{ssS.RpcReady},
},
// TODO ClientBye for graceful shutdowns
})
// EXPORTS AND GROUPS
var (
ssS = am.NewStates(ServerStatesDef{})
sgS = am.NewStateGroups(ServerGroupsDef{
Rpc: S{ssS.RpcStarting, ssS.RpcReady},
}, SharedGroups)
// ServerStates contains all the states for the Client machine.
ServerStates = ssS
// ServerGroups contains all the state groups for the Client machine.
ServerGroups = sgS
)