forked from eigengo/akka-patterns
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First cut of the recog API for eigengo#40
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ provisioning/*/*.known | |
log/ | ||
tmp/ | ||
build/ | ||
akka-patterns-store/ |
36 changes: 36 additions & 0 deletions
36
server/api/src/main/scala/org/eigengo/akkapatterns/api/recog.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("{}") | ||
} | ||
} | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
server/core/src/main/scala/org/eigengo/akkapatterns/core/recog/coordinator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
server/core/src/main/scala/org/eigengo/akkapatterns/core/recog/data.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.eigengo.akkapatterns.core.recog | ||
|
||
/** | ||
* @author janmachacek | ||
*/ | ||
class data { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
server/core/src/main/scala/org/eigengo/akkapatterns/core/recog/instance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ??? | ||
} |