-
Notifications
You must be signed in to change notification settings - Fork 4
/
vfindcallresponse.go
80 lines (64 loc) · 2.4 KB
/
vfindcallresponse.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
//go:generate sm-uml-gen -f $GOFILE
package handlers
import (
"github.com/insolar/assured-ledger/ledger-core/conveyor"
"github.com/insolar/assured-ledger/ledger-core/conveyor/smachine"
"github.com/insolar/assured-ledger/ledger-core/rms"
"github.com/insolar/assured-ledger/ledger-core/vanilla/injector"
"github.com/insolar/assured-ledger/ledger-core/vanilla/throw"
"github.com/insolar/assured-ledger/ledger-core/virtual/execute"
)
type SMVFindCallResponse struct {
// input arguments
Meta *rms.Meta
Payload *rms.VFindCallResponse
pulseSlot *conveyor.PulseSlot
}
/* -------- Declaration ------------- */
var dSMVFindCallResponseInstance smachine.StateMachineDeclaration = &dSMVFindCallResponse{}
type dSMVFindCallResponse struct {
smachine.StateMachineDeclTemplate
}
func (*dSMVFindCallResponse) InjectDependencies(sm smachine.StateMachine, _ smachine.SlotLink, injector injector.DependencyInjector) {
s := sm.(*SMVFindCallResponse)
injector.MustInject(&s.pulseSlot)
}
func (*dSMVFindCallResponse) GetInitStateFor(sm smachine.StateMachine) smachine.InitFunc {
s := sm.(*SMVFindCallResponse)
return s.Init
}
/* -------- Instance ------------- */
func (s *SMVFindCallResponse) GetStateMachineDeclaration() smachine.StateMachineDeclaration {
return dSMVFindCallResponseInstance
}
func (s *SMVFindCallResponse) Init(ctx smachine.InitializationContext) smachine.StateUpdate {
if s.pulseSlot.State() != conveyor.Present {
ctx.Log().Warn("stop processing VFindCallResponse since we are not in present pulse")
return ctx.Stop()
}
ctx.SetDefaultMigration(s.migrationDefault)
return ctx.Jump(s.stepProcess)
}
func (s *SMVFindCallResponse) migrationDefault(ctx smachine.MigrationContext) smachine.StateUpdate {
ctx.Log().Trace("stop processing VFindCallResponse since pulse was changed")
return ctx.Stop()
}
func (s *SMVFindCallResponse) stepProcess(ctx smachine.ExecutionContext) smachine.StateUpdate {
key := execute.DeduplicationBargeInKey{
LookAt: s.Payload.LookedAt,
Callee: s.Payload.Callee.GetValue(),
Outgoing: s.Payload.Outgoing.GetValue(),
}
link, bargeInCallback := ctx.GetPublishedGlobalAliasAndBargeIn(key)
if link.IsZero() {
return ctx.Error(throw.E("no one is waiting"))
}
if bargeInCallback == nil {
return ctx.Error(throw.Impossible())
}
done := bargeInCallback.CallWithParam(s.Payload)
if !done {
return ctx.Error(throw.E("no one is waiting anymore"))
}
return ctx.Stop()
}