Skip to content

Commit

Permalink
First cut of the recog API for eigengo#40
Browse files Browse the repository at this point in the history
  • Loading branch information
janm committed Apr 15, 2013
1 parent 9c32a2b commit 9b91809
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ provisioning/*/*.known
log/
tmp/
build/
akka-patterns-store/
36 changes: 36 additions & 0 deletions server/api/src/main/scala/org/eigengo/akkapatterns/api/recog.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.eigengo.akkapatterns.api

import akka.util.Timeout
import spray.routing.{RequestContext, HttpService}
import org.eigengo.akkapatterns.domain.RecogSessionId
import scala.reflect.ClassTag
import spray.json.RootJsonFormat
import akka.actor.ActorRef

trait RecogService extends HttpService {
this: EndpointMarshalling =>

implicit val timeout: Timeout

def recogCoordinator: ActorRef

def image[A : ClassTag : RootJsonFormat](sessionId: RecogSessionId)(ctx: RequestContext) {
// coordinatorActor
/*
(coordinator ? ProcessImage(transactionId, Base64.decodeBase64(ctx.request.entity.buffer))).mapTo[A] onSuccess {
case r: A => ctx.complete[A](StatusCodes.OK, RawHeader("Access-Control-Allow-Origin", origin) :: Nil, r)
case x => ctx.complete(StatusCodes.InternalServerError)
}
*/
}

val recogRoute =
path("recog") {
post {
ctx: RequestContext => {
ctx.complete("{}")
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.eigengo.akkapatterns.core.recog

import akka.actor.{Kill, Props, ActorRef, Actor}
import org.eigengo.akkapatterns.domain._
import akka.util.Timeout
import java.util.UUID

/**
* Submits the ``image`` to the session identified by ``recogSessionId``
* @param recogSessionId the recognition session
* @param image the image to be submitted
*/
case class ProcessImage(recogSessionId: RecogSessionId, image: Image)

/**
* Begins the recognition session
*/
case object Begin

/**
* Kills active session identified by id
*
* @param id the session identity
*/
case class KillActiveSession(id: RecogSessionId)

/**
* Finds all active recognition sessions
*/
case object FindActiveSessions

/**
* @author janmachacek
*/
class RecogCoordinatorActor(connectionActor: ActorRef) extends Actor {

private def findInstanceActor(id: RecogSessionId): ActorRef = {
context.actorFor(id.toString)
}

implicit val executionContext = context.dispatcher

def receive = {
case Begin =>
val id = UUID.randomUUID()
val instanceActor = context.actorOf(Props(new InstanceActor(connectionActor)), id.toString)
instanceActor.tell(Begin, sender)
case ProcessImage(id, image) =>
findInstanceActor(id).tell(image, sender)
case KillActiveSession(id) =>
findInstanceActor(id) ! Kill
case FindActiveSessions =>
sender ! context.children.map(c => UUID.fromString(c.path.name)).toList
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.eigengo.akkapatterns.core.recog

/**
* @author janmachacek
*/
class data {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eigengo.akkapatterns.core.recog

import akka.actor.{Actor, ActorRef}

/**
* @author janmachacek
*/
class InstanceActor(connectionActor: ActorRef) extends Actor {
def receive = ???
}

0 comments on commit 9b91809

Please sign in to comment.