문제

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?

도움이 되었습니까?

해결책

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

Perhaps something like that?

다른 팁

Something like this?

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

val actor = system.actorOf(FooActor())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top