Akka ActorSystem Control

my environment is scala akka and the play! framework. I was wondering if there is anyway to control the creation of an actor system or any other ideas that can .

My idea is to create remote actors that will handle authorization when a user hits buy. And so, I create the remote actor system and actors in an action method, when a user does a post:

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()
}

Here is the definition of remotecreation in the 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://ActorApplication@172.17.100.232:2552"
                                    router = "round-robin"
                                    nr-of-instances = 1
                            }
                    }
            }
            remote.netty.port = 2554
    }
}

The problem I am having is that, when I submit twice in a row, I get an error because I am trying to create an actor system on an ip address that already has an actor system on it.

I definitely think I need to move it, but I'm not sure where because since this is going to be a wide, multi user play! application, I'm not sure where I can put the creation of the actor system without being conflicted when hundreds of users use the application.

Any thoughts, suggestions, or help is appreciated.

Answers


Don't start a (remote) ActorSystem per call. Instead, start up an application-wide actor system (or use the default one, see integrating Play with Akka).

Add to your 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 ?
    }
  }
}

Then use the default Play actorsystem for example to get a reference to the remote actor in your contorller:

private val interpreters = Akka.system.actorFor(
  "akka://interpreter_system@127.0.0.1:2552/user/interpreters")

You might even convert an Akka Future to a Scala Promise if you want to render the actor response. I avice to keep using Akka Futures for composability, then at the very last stem convert the Future[Result] to a Promise.

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

Need Your Help

Kerberos SSO with mod_auth_kerb: Verification code 589824 and Token seems to be NTLM

apache kerberos mod-auth

I've run into some difficulties kerberizing a host, t.p.no. I'm follwing http://grolmsnet.de/kerbtut, which have worked for others kerberizing a host not added to the windows domain.

=?UTF-8?B??= in Emails sent via php mail problem

php javascript html email

I have a website, and in the "Contact" section I have a form which users may fill in to contact me.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.