Questions by Akka, Scalatra and Web

This is a two-part question: firstly, it is a design question, not how to implement it, and secondly, some problems with Akka implementation.

I use Scalatra to create a REST service endpoint that, when called, will retrieve images from multiple sources, manipulate them and return them. This is a potentially fairly lengthy process and is likely to be longer than is acceptable for a single HTTP request / response cycle.

My thoughts on this are that when the call is completed, I will start with a bunch of Akk actors to pull out the image resources and apply them to the result for image processing. Actors scale, etc. The initial request itself will immediately return some sort of Processing ID, which can be used to call the poll to another endpoint, which will return the results as they are processed, with a flag to determine if there are more results to let the client know to stop poll.

My questions:

  • Does this make sense in terms of design?
  • If I use this approach, then each subsequent request for processed images should have some state awareness in order to know which images the client has already received. How would you deal with this condition?
  • I've never looked at this, but a long-lasting comet-style HTTP request will make more sense than polling in this situation?

Implementation part

Assuming I am running out of a design similar to the above, I am very new to Scalatra and Akka (or any actor paradigm), and I have a few questions.

Ok, first this is a Scala / Scalatra question, which I think. Ok, I looked at the Scalatra docs on akka http://www.scalatra.org/guides/async/akka.html , and in this example they configure application loading as follows:

 // Get a handle to an ActorSystem and a reference to one of your actors
  val system = ActorSystem()
  val myActor = system.actorOf(Props[MyActor])

  // In the init method, mount your servlets with references to the system
  // and/or ActorRefs, as necessary.
  override def init(context: ServletContext) {
    context.mount(new PageRetriever(system), "/*")
    context.mount(new MyActorApp(system, myActor), "/actors/*")
  }

I assume that bootstrap scalars happen once at application startup, just as system.actorOf (Props [MyActor]) creates one instance or one for a request?

Secondly, let's say my MyActor class (or a more sensible name) did the following:

class MyActor extends Actor {
  def receive = {
    //Find the [ImageSearchingActor] actor in akka registry and send search message
    case initiateSearchRequest: InitiateSearchRequestMessage => TODO

    //Find free [ImageProcessingActors] in akka registry and send each Image url to process  
    case imageInformationFound : ImageInformationFoundMessage => TODO

    //Persist the result to a cache, or data store with the ProcessingId that all message will pass  
    case imageProcessed : ImageProcessedMessage =>  TODO
  }
}

, , , . , . , - , ProcessId . , , ProcessId. ?

, , .

. .

+5
1

. :

  • , .

  • , Actor , , . , . , , , , , , Akka 2.1.x, , , , , Scalatra.

  • . Scalatra Atmosphere, websocket/comet. . , , . , , - -, , - , SSL . , , , , .

ActorSystem:

Scalatra ; ActorSystem . , , ActorSystem.

ActorSystem , , .

+3

All Articles