I was thinking about how to create PersistentActor instance that represents 
a domain entity, with some initial state that is not determined by the 
actor itself. To make the discussion more concrete, let's say it's an 
AuctionActor representing a single auction. At creation time you know the 
endDate, description and reservePrice (they all come from user input). I 
came up with several options, all with their own tradeoffs:

1) pass the initial state with props of the actor to the constructor of 
AuctionActor. Pro: simple, intuitive, no impact on design of rest of logic 
in actor. Con: setting the initial state is not a persistent event. Hence, 
when the AuctionActor is re-created the same state must be passed to 
through the props, defeating the purpose of the journal. Also, Views don't 
see the initial values because it is not an event. Not a good solution.
2) create AuctionActor with empty state (no endDate, description, 
reservePrice set) and wait for a InitializeAuction(endDate, description, 
reservePrice) message that in turn persists/applies an event with these 
values. Then, the actor can react to other commands such as Bids etc. Pro: 
setting the initial state is a persistent event, available in Views etc. 
Con: creating the actor and sending initial state are separated even though 
it is logically one step for our application. It does not make sense to 
have an AuctionActor without its initial state. We need to use become() 
just to transition from this created-but-not-initialized state to the 
auction-ready-for-action state, which is our actual logic. State value of 
the actor now has to optional even though we always know it has will be 
initialized (or we could just start with a null state value until 
InitializeAuction arrives *shudder*)
3) a hybrid (which I haven't tested yet): pass in the initial values 
through props, but persist/apply an event at construction time of the 
AuctionActor. Not sure if you are allowed to persist events in the 
constructor af a PersistentActor?

How are other people handling this scenario? 


Thanks,
Sander

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to