scala - creating Akka actor hierarchies lazily -


i want create actors can serve resources file system. ideally [1] i'd have 1 actor each directory , each file. don't want create whole actor tree hierarchy save memory , resources as possible.

as understand actor can created if parent exists. best best way create these hierarchies lazily. there hook 1 can use capture failures , create actor hierarchies on fly, , efficiently?

having allow me send fetch, update, delete, ... messages actor , akka actor system thereby deal synchronisation issues. extended more sophisticated actor behaviours later notions of virtual files or such...

some possible solutions can think of:

  1. run context.actorfor(path) , if returns dead letter mailbox, try create actor hierarchies. not sound solution.
  2. send message root actor , have forward child getorcreatechild method. perhaps inefficient? ( or akka under hood... ( should ))
  3. not @ , create 1 actor delegates every message directory actor created on fly each directory of requested file explained in answers stack overflow question "on demand actor or else create". not capturing directory deletion semantics. ( lot more efficient?)

[1] not absolutely sure if ideal, thought should try method out first. method create actor each directory , store in hash map.

first, actors lightweight. can have millions running in jvm extremely small footprint actors itself. changes if actors have custom state can big memory wise, actors have small footprint.

now if still want implement them lazily, 1 approach might have single file or folder master actor receives of initial calls. actor checks system see if actor exists serve request whatever folder or file request for. if not, master creates , forwards message it. if so, forwards message it. no need keep hashmap in memory actorsystem hold of actorrefs , give means them up. need method of equating file name/path actor name. oversimplified example of master this:

case class fetch(path:string) class filemaster extends actor{   def receive = {     case msg @ fetch(path) =>       val ref = lazyfindactor[filehandler](path)       ref.forward(msg)   }    def lazyfindactor[t <: actor: manifest](name:string) = {     val ref = context.actorfor(name)     if (ref == context.system.deadletters){       context.actorof(props[t], name)     }     else{       ref     }   }  } 

all lazyfindactor check if actor path has been created , started. if so, forwards it. if not (and compares deadletters make determination unfortunately, don't see better way check if actor exists), creates 1 under supervision of master , forwards it. next time same path comes in use pre-existing actor.

you may have little work translating file path syntax can used actor name (because akka uses hierarchical file path structure actor paths already), i'm not 100% sure one. wanted throw high level concept @ , see if looking for.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -