2014-01-06 3 views
2

자체 유형이있는 액터를 만드는 새로운 방법에 어려움을 겪고 있습니다. 지금은 사용되지 않으며 그냥 제대로이 일을 다른 방법을 찾을 수 없습니다자체 유형을 포함하는 소품을 사용하여 액터 만들기

context.actorOf(Props(FooActor())) 

:

의 내가 배우

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 => 
} 

나는 이런 식으로 뭔가를 쓸 수있는 코드를 갖는 있다고 가정하자.

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

을하지만, 어디는 믹스 인을 넣을 수 있습니다 : akka 사람이 제안하는 어떤

"적용()"방법은 지금에 따라 다음과 비슷한 모습이 될 것입니다?

답변

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

아마도 그렇게 할 수 있을까요?

+0

그 해결책은 내 머리 속에서 매달 렸습니다. 그러나 나는이 것을 매우 우아하지 않은 것으로 생각했습니다. 하지만 다른 옵션을 사용할 수없는 경우에는 그냥 대처해야합니다. – almendar

0

이와 비슷한?

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

val actor = system.actorOf(FooActor()) 
+0

이 버전은 지금 akka에 의해 낙담하고 있습니다 : http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Deprecated_Variants – almendar

+0

감사합니다. – Peter

+1

여기에 표시된 사용법은 문제가있는 경우 (Actor 내부에서 사용하는 경우) 중 하나가 아니므로이를 반영하도록 문서를 업데이트합니다. –

관련 문제