Skip to content

Commit 5711e71

Browse files
authored
Merge pull request #5 from wXwcoder/feature/invokename
activate support invokeName
2 parents 2fad0f2 + 988c14b commit 5711e71

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

actor/actor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Server interface {
4444
// Save state is called at two places: 1. On invocation of this actor instance. 2. When new actor starts.
4545
SaveState() error
4646
// Activate called when actor created by actor manager
47-
Activate() error
47+
Activate(invokeName string) error
4848
// Deactivate called before actor removed by actor manager
4949
Deactivate() error
5050
}

actor/manager/container.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ func NewDefaultActorContainer(actorID string, impl actor.Server, serializer code
4444
daprClient, _ := dapr.NewClient()
4545
// create state manager for this new actor
4646
impl.SetStateManager(state.NewActorStateManager(impl.Type(), actorID, state.NewDaprStateAsyncProvider(daprClient)))
47-
err := impl.Activate()
47+
// move out for Activate param
48+
/*err := impl.Activate()
4849
if err != nil {
4950
return nil, actorErr.ErrSaveStateFailed
5051
}
5152
// save state of this actor
5253
err = impl.SaveState()
5354
if err != nil {
5455
return nil, actorErr.ErrSaveStateFailed
55-
}
56+
}*/
5657
methodType, err := getAbsctractMethodMap(impl)
5758
if err != nil {
5859
log.Printf("failed to get absctract method map from registered provider, err = %s", err)

actor/manager/manager.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,22 @@ func (m *DefaultActorManager) RegisterActorImplFactory(f actor.Factory) {
6868
}
6969

7070
// getAndCreateActorContainerIfNotExist will.
71-
func (m *DefaultActorManager) getAndCreateActorContainerIfNotExist(actorID string) (ActorContainer, actorErr.ActorErr) {
71+
func (m *DefaultActorManager) getAndCreateActorContainerIfNotExist(actorID, invokeName string) (ActorContainer, actorErr.ActorErr) {
7272
val, ok := m.activeActors.Load(actorID)
7373
if !ok {
7474
newContainer, aerr := NewDefaultActorContainer(actorID, m.factory(), m.serializer)
7575
if aerr != actorErr.Success {
7676
return nil, aerr
7777
}
78+
err := newContainer.GetActor().Activate(invokeName)
79+
if err != nil {
80+
return nil, actorErr.ErrSaveStateFailed
81+
}
82+
// save state of this actor
83+
err = newContainer.GetActor().SaveState()
84+
if err != nil {
85+
return nil, actorErr.ErrSaveStateFailed
86+
}
7887
m.activeActors.Store(actorID, newContainer)
7988
val, _ = m.activeActors.Load(actorID)
8089
}
@@ -87,7 +96,7 @@ func (m *DefaultActorManager) InvokeMethod(actorID, methodName string, request [
8796
return nil, actorErr.ErrActorFactoryNotSet
8897
}
8998

90-
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID)
99+
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID, methodName)
91100
if aerr != actorErr.Success {
92101
return nil, aerr
93102
}
@@ -143,7 +152,7 @@ func (m *DefaultActorManager) InvokeReminder(actorID, reminderName string, param
143152
log.Printf("failed to unmarshal reminder param, err: %v ", err)
144153
return actorErr.ErrRemindersParamsInvalid
145154
}
146-
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID)
155+
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID, reminderName)
147156
if aerr != actorErr.Success {
148157
return aerr
149158
}
@@ -166,7 +175,7 @@ func (m *DefaultActorManager) InvokeTimer(actorID, timerName string, params []by
166175
log.Printf("failed to unmarshal reminder param, err: %v ", err)
167176
return actorErr.ErrTimerParamsInvalid
168177
}
169-
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID)
178+
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(actorID, timerName)
170179
if aerr != actorErr.Success {
171180
return aerr
172181
}

actor/mock/mock_factory_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ActorImpl struct {
2727
actor.ServerImplBase
2828
}
2929

30-
func (t *ActorImpl) Activate() error {
30+
func (t *ActorImpl) Activate(invokeName string) error {
3131
return nil
3232
}
3333

actor/mock/mock_server.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)