Already asked this question on Stackoverflow: 
https://stackoverflow.com/questions/56202768/how-to-implement-factory-of-akka-actors


Let's say I have DAO Actors (CassDaoActor, VerticaDaoActor, etc) that 
respond to message 'Read'.


First of all, is there a way to express a interface or abstract class that 
defines the message 'Read' that extending actors should implement?


Now assume it's only at runtime that I could get to know which Actor needs 
to be created based on the configured db. For example, if configured db is 
cassandra, I need to create CassDaoActor, etc. This apparently is a typical 
use case for Factory Method Pattern as we know. I want to understand how 
can we implement such a thing? Evidently we can't pass "context" around 
since it looses content outside the scope of the actor.


Please suggest.


What I have tried so far is that I am returning respective props based on 
the configured db to the actor within which I need to create these actors.


object `package` {
  val CASS = "cass"
  val VERTICA = "vertica"

  def getDAOProps(db: String): Props = db match {
    case CASS => CassDaoActor.props
    case VERTICA => VerticaDaoActor.props
  }}

// SupervisorActorval db = configuredDb()
context.actorOf(getDAOProps(db), db)

-- 
*****************************************************************************************************
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*****************************************************************************************************
>>>>>>>>>> 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/akka-user/954accf7-7df4-4e66-a4ce-6831ea0dbe6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to