title: Akka cluster-sharding: Can Entry actors have dynamic props
body: <p>Akka Cluster-Sharding looks like it matches well with a use case I have to create single instances of stateful persistent actors across Akka nodes.</p>
  
  <p>I'm not clear if it is possible though to have an Entry actor type that requires arguments to construct it. Or maybe I need to reconsider how the Entry actor gets this information.</p>
  
  <pre><code>Object Account {
    def apply(region: String, accountId: String): Props = Props(new Account(region, accountId))
  }
  
  class Account(val region: String, val accountId: String) extends Actor with PersistentActor { ... }
  </code></pre>
  
  <p>Whereas the <code>ClusterSharding.start</code> takes in a single Props instance for creating all Entry actors.</p>
  
  <p>From <a href="http://doc.akka.io/docs/akka/2.3.6/contrib/cluster-sharding.html#cluster-sharding">akka cluster-sharding</a>:</p>
  
  <pre><code>val counterRegion: ActorRef = ClusterSharding(system).start(
    typeName = "Counter",
    entryProps = Some(Props[Counter]),
    idExtractor = idExtractor,
    shardResolver = shardResolver)
  </code></pre>
  
  <p>And then it resolves the Entry actor that receives the message based on how you define the idExtractor. From the source code for shard it can be seen it uses the id as the name for a given Entry actor instance:</p>
  
  <pre><code>def getEntry(id: EntryId): ActorRef = {
  val name = URLEncoder.encode(id, "utf-8")
  context.child(name).getOrElse {
    log.debug("Starting entry [{}] in shard [{}]", id, shardId)
  
    val a = context.watch(context.actorOf(entryProps, name))
    idByRef = idByRef.updated(a, id)
    refById = refById.updated(id, a)
    state = state.copy(state.entries + id)
    a
  }
  </code></pre>
  
  <p>}</p>
  
  <p>It seems I should instead have my Entry actor figure out its region and accountId by the name it is given, although this does feel a bit hacky now that I'll be parsing it out of a string instead of directly getting the values. Is this my best option?</p>