2012-09-21 175 views
1

我的环境是斯卡拉阿卡和玩!框架。我想知道是否有控制演员系统或任何其他想法的创建。Akka演员系统控制

我的想法是创建一个远程演员,当用户点击购买时将处理授权。所以,我创建的操作方法的远程系统的演员和演员,当用户执行后:

def payment = Action { implicit request => 
    var actorObject: Array[String] = new Array[String](23) 

    val system = ActorSystem("RemoteSystem", ConfigFactory.load.getConfig("remotecreation") 

    val worker = system.actorOf(Props[authNetActor.AuthNetActorMain].withRouter(FromConfig()), name = "remoteActor") 
    ... 
    system.shutdown() 
} 

这里是在application.conf

remotecreation {  #user defined name for the configuration 
    include "common" 
    akka { 
      actor { 
        serialize-messages = on 
        serialize-creators = on 

        serializers { 
          proto = "akka.serialization.ProtobufSerializer" 
          java = "akka.serialization.JavaSerializer" 
          arr = "models.ArraySerializer" 
        } 

        serialization-bindings { 
          "com.google.protobuf.Message" = proto 
          "java.lang.String" = java 
          "java.util.Arrays" = java 
          "scala.Array" = arr 
          "akka.actor.ActorRef" = java 
        } 

        deployment { 
          /remoteActor { #Specifically has to be the name of the remote actor 
            remote = "akka://[email protected]:2552" 
            router = "round-robin" 
            nr-of-instances = 1 
          } 
        } 
      } 
      remote.netty.port = 2554 
    } 
} 

的问题remotecreation的定义我遇到的情况是,当我连续两次提交时,我得到一个错误,因为我试图在一个已经有一个actor系统的ip地址上创建一个actor系统。

我绝对认为我需要移动它,但我不确定在哪里,因为这将是一个广泛的多用户游戏!应用程序,我不确定我可以在哪里将创建演员系统的位置在数百个用户使用该应用程序时不会发生冲突。

任何想法,建议或帮助表示赞赏。

回答

3

每次调用都不要启动(远程)ActorSystem。相反,启动一个应用程序范围的角色系统(或者使用默认角色,请参阅integrating Play with Akka)。

添加到您的application.conf

akka { 

    actor { 
    provider = "akka.remote.RemoteActorRefProvider" 
    } 

    remote { 
    transport = "akka.remote.netty.NettyRemoteTransport" 
    netty { 
     hostname = "127.0.0.1" 
     port = 0 # 2552 seems to be bound with play 2.0.2 ? 
    } 
    } 
} 

然后使用例如默认播放actorsystem去你contorller远程演员的引用:

private val interpreters = Akka.system.actorFor(
    "akka://[email protected]:2552/user/interpreters") 

你甚至可能转换的阿卡未来到斯卡拉承诺如果你想渲染演员的回应。我希望继续使用Akka Futures进行组合性分析,然后在最后一步将Future[Result]转换为Promise。

new AkkaPromise(
    interpreters.ask(InterpretersComm.Request(sid, line)).mapTo[String]) map (Ok(_)) 
+0

这些例子来自我的一个使用远程scala解释器的玩具项目。 – ron