Search code examples
scalaakkaactorspray

How to have separate long lived pool of actors for business layer in Spray application?


I'm creating a RESTful API with Spray 1.2.0 and Akka 2.2.3. Scala version is 2.10 (all of these versions can be changed if necessary). In my business layer I have to communicate over SSH connections to a legacy system. These connections take a long time (1 - 3 minutes) to set up and will expire if they are idle for too long. I worked on the SSH code separately on a test app and now I've wrapped it in an actor.

How do I designate a pool of the SSH actors that is separate from the actors Spray uses to handle HTTP requests? I need these actors to be created at startup as opposed to when a request comes in, otherwise the request times out while the connection is being established. Also, how do I control the size of that pool of actors independently of Spray's actors?


Solution

  • How do I designate a pool of the SSH actors that is separate from the actors Spray uses to handle HTTP requests?

    You can create a custom dispatcher for this group of actors.

    These connections take a long time (1 - 3 minutes) to set up and will expire if they are idle for too long.

    You can automatically setup connection on actor startup. Each actor may schedule periodic keep-alive actions not to let the connection to time out using scheduler.

    I need these actors to be created at startup. How do I control the size of that pool of actors independently of Spray's actors?

    I guess you have to create a required number of these actors manually on app startup.