Frage

I'm struggling with new method of creating actors that have a self type.

Let's assume I have an Actor

trait BarPolicy {
  val maxDrinksNumber:Int
}

trait ProductionPolicy extends BarPolicy {
  val maxDrinksNumber = 5
}

object FooActor { 
   def apply()  = new FooActor with ProductionPolicy 
}

class FooActor extends Actor {
   this: BarPolicy =>
}

Having that code I could write something like this:

context.actorOf(Props(FooActor()))

now this is deprecated and I just cannot find another way of doing this properly.

The "apply()" method should now look something like this according to what akka guys suggest:

def apply() : Props = Props(classOf[FooActor])

but where can I put the mixin?

War es hilfreich?

Lösung

object FooActor { 
  private class ProductionFooActor extends FooActor with ProductionPolicy
  def apply() : Props = Props(classOf[ProductionFooActor])
}

Perhaps something like that?

Andere Tipps

Something like this?

object FooActor { 
   def apply() : Props = Props(new FooActor with ProductionPolicy)
}

val actor = system.actorOf(FooActor())
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top