Reputation: 13342
I have this actor that is involved in parallel-word-count-calculation.
It has a state:
private Map<String, Integer> wordCountMap = new HashMap<String, Integer>();
As it received WordCountMapMessage
message, it changed the state to have 9 elements
in it:
{over=1, fell=1, fox=1, quick=1, tried=1, brown=1, lazy=1, dog=2, jump=1}
(there is main class
for that - you can see outputs if you launch it)
Then when it receives ResultMessage
, then wordCountMap
is empty.
Q: How come, all of the sudden it has empty map/state?
Is that possible that Actor is re-initializing its state somehow with no message passed?
--
Update:
If I ovveride methods preStart
in AggregateWordCountActor
, then I can see output like this:
pre-start pre-start pre-start pre-start pre-start
It seems it starts 5 times ! But it does not launch any preRestart
Upvotes: 0
Views: 136
Reputation: 35443
Your issue seems to be that you are using a RoundRobinPool
for each child actor in the Master
actor. Because your child actors are stateful, when the request comes in to request the current state, it goes to a different actor instance then the one that received the request to process the words (via the round robin routing logic). Remove the routers from your child actor creation in the Master
actor and your code should work.
Upvotes: 1
Reputation: 815
It seems it starts 5 times ! But it does not launch any preRestart
That's because you are using withRouter(new RoundRobinPool(5))
-- it creates 5 actors that will receive messages in round-robin fashion.
Problem is that you are receiving state of different actor than have completed computation: actors that will receive WordCountMapMessage
and ResultMessage
are not the same.
Upvotes: 1