-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathss_rpc_client.go
127 lines (104 loc) · 2.93 KB
/
ss_rpc_client.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package states
import (
am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/pancsta/asyncmachine-go/pkg/states"
)
// ClientStatesDef contains all the states of the Client state machine.
type ClientStatesDef struct {
// shadow duplicated StatesBase
*am.StatesBase
// failsafe
RetryingCall string
// TODO should be ErrCallRetry, req:Exception
CallRetryFailed string
RetryingConn string
// TODO should be ErrConnRetry, req:Exception
ConnRetryFailed string
// local docs
// Ready indicates the remote worker is ready to be used.
Ready string
// worker delivers
// WorkerDelivering is an optional indication that the server has started a
// data transmission to the Client.
WorkerDelivering string
// WorkPayload allows the Consumer to bind his handlers and receive data
// from the Client.
WorkerPayload string
// inherit from SharedStatesDef
*SharedStatesDef
// inherit from ConnectedStatesDef
*states.ConnectedStatesDef
}
// ClientGroupsDef contains all the state groups of the Client state machine.
type ClientGroupsDef struct {
*SharedGroupsDef
*states.ConnectedGroupsDef
// TODO
}
// ClientStruct represents all relations and properties of ClientStates.
var ClientStruct = StructMerge(
// inherit from SharedStruct
SharedStruct,
// inherit from ConnectedStruct
states.ConnectedStruct,
am.Struct{
// Try to RetryingConn on ErrNetwork.
ssC.ErrNetwork: {
Require: S{am.Exception},
Remove: S{ssC.Connecting},
},
ssC.Start: {
Add: S{ssC.Connecting},
Remove: S{ssC.ConnRetryFailed},
},
ssC.Ready: {
Auto: true,
Require: S{ssC.HandshakeDone},
},
// inject Client states into Connected
ssC.Connected: StateAdd(
states.ConnectedStruct[states.ConnectedStates.Connected],
am.State{
Remove: S{ssC.RetryingConn},
Add: S{ssC.Handshaking},
}),
// inject Client states into Handshaking
ssC.Handshaking: StateAdd(
SharedStruct[s.Handshaking],
am.State{
Require: S{ssC.Connected},
}),
// inject Client states into HandshakeDone
ssC.HandshakeDone: am.StateAdd(
SharedStruct[ssC.HandshakeDone], am.State{
// HandshakeDone will depend on Connected.
Require: S{ssC.Connected},
}),
// Retrying
ssC.RetryingCall: {Require: S{ssC.Start}},
ssC.CallRetryFailed: {
Remove: S{ssC.RetryingCall},
Add: S{ssC.ErrNetwork, am.Exception},
},
ssC.RetryingConn: {Require: S{ssC.Start}},
ssC.ConnRetryFailed: {Remove: S{ssC.Start}},
// worker delivers
ssC.WorkerDelivering: {
Multi: true,
Require: S{ssC.Connected},
},
ssC.WorkerPayload: {
Multi: true,
Require: S{ssC.Connected},
},
})
// EXPORTS AND GROUPS
var (
ssC = am.NewStates(ClientStatesDef{})
sgC = am.NewStateGroups(ClientGroupsDef{}, states.ConnectedGroups,
SharedGroups)
// ClientStates contains all the states for the Client machine.
ClientStates = ssC
// ClientGroups contains all the state groups for the Client machine.
ClientGroups = sgC
)