Skip to content

Commit 5e0f3b6

Browse files
authored
Merge branch 'main' into feature/334
Signed-off-by: wXwcoder <996268132@qq.com>
2 parents 180311d + e54f38a commit 5e0f3b6

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

actor/actor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type Server interface {
4343
// SaveState is impl by ServerImplBase, It saves the state cache of this actor instance to state store component by calling api of daprd.
4444
// Save state is called at two places: 1. On invocation of this actor instance. 2. When new actor starts.
4545
SaveState() error
46+
// Activate called when actor created by actor manager
47+
Activate() error
48+
// Deactivate called before actor removed by actor manager
49+
Deactivate() error
4650
}
4751

4852
type ReminderCallee interface {

actor/manager/container.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
type ActorContainer interface {
2929
Invoke(methodName string, param []byte) ([]reflect.Value, actorErr.ActorErr)
3030
GetActor() actor.Server
31+
Deactivate() error
3132
}
3233

3334
// DefaultActorContainer contains actor instance and methods type info generated from actor.
@@ -43,8 +44,12 @@ func NewDefaultActorContainer(actorID string, impl actor.Server, serializer code
4344
daprClient, _ := dapr.NewClient()
4445
// create state manager for this new actor
4546
impl.SetStateManager(state.NewActorStateManager(impl.Type(), actorID, state.NewDaprStateAsyncProvider(daprClient)))
47+
err := impl.Activate()
48+
if err != nil {
49+
return nil, actorErr.ErrSaveStateFailed
50+
}
4651
// save state of this actor
47-
err := impl.SaveState()
52+
err = impl.SaveState()
4853
if err != nil {
4954
return nil, actorErr.ErrSaveStateFailed
5055
}
@@ -84,3 +89,7 @@ func (d *DefaultActorContainer) Invoke(methodName string, param []byte) ([]refle
8489
returnValue := methodType.method.Func.Call(argsValues)
8590
return returnValue, actorErr.Success
8691
}
92+
93+
func (d *DefaultActorContainer) Deactivate() error {
94+
return d.actor.Deactivate()
95+
}

actor/manager/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ func (m *DefaultActorManager) InvokeMethod(actorID, methodName string, request [
122122

123123
// DeactivateActor removes actor from actor manager.
124124
func (m *DefaultActorManager) DeactivateActor(actorID string) actorErr.ActorErr {
125-
_, ok := m.activeActors.Load(actorID)
125+
actor, ok := m.activeActors.Load(actorID)
126126
if !ok {
127127
return actorErr.ErrActorIDNotFound
128128
}
129+
actor.(ActorContainer).Deactivate()
129130
m.activeActors.Delete(actorID)
130131
return actorErr.Success
131132
}

actor/mock/mock_factory_impl.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ type ActorImpl struct {
2727
actor.ServerImplBase
2828
}
2929

30+
func (t *ActorImpl) Activate() error {
31+
return nil
32+
}
33+
34+
func (t *ActorImpl) Deactivate() error {
35+
return nil
36+
}
37+
3038
func (t *ActorImpl) Type() string {
3139
return "testActorType"
3240
}
@@ -46,6 +54,14 @@ type NotReminderCalleeActor struct {
4654
actor.ServerImplBase
4755
}
4856

57+
func (t *NotReminderCalleeActor) Activate() error {
58+
return nil
59+
}
60+
61+
func (t *NotReminderCalleeActor) Deactivate() error {
62+
return nil
63+
}
64+
4965
func (t *NotReminderCalleeActor) Type() string {
5066
return "testActorNotReminderCalleeType"
5167
}

actor/mock/mock_server.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)