Skip to content

Instantly share code, notes, and snippets.

case ConversationTimeout =>
sessionHandler ! SessionTimeout(conversationID)
// This will also stop the event sourced actor
Behaviors.stopped
private def idle(): ConversationBehavior = {
timers.startSingleTimer(TimerKey, ConversationTimeout, sessionTimeout)
this
}
def postMessage(conversationID: ConversationID, sender: UserID, message: String)(
session: ActorRef[SessionCommand]
): Unit =
session ! PostMessage(conversationID, sender, message)
onComplete(maybeSessionGranted) {
case Success(SessionGranted(session)) =>
postMessage(conversationID, pmr.userID, pmr.message)(session)
complete(OK, PostMessageResponse(pmr.message))
case Failure(_) =>
complete(BadRequestError, "Authentication Failed")
case _ => complete(InternalServerError)
}
def getSession(conversationID: ConversationID, userID: UserID): Future[SessionEvent] =
sessionHandler.ask(GetSession(conversationID, userID, _))
lazy val conversationRoutes: Route = {
concat(
pathPrefix(version / "conversation" / LongNumber) { conversationID =>
post {
entity(as[PostMessageRequest]) {
pmr =>
val maybeSessionGranted: Future[SessionEvent] =
getSession(conversationID, pmr.userID)
onComplete(maybeSessionGranted) {
class ConversationRoutes(sessionHandler: ActorRef[SessionHandlerCommand])(implicit
val system: ActorSystem[_]
) extends JsonSupport { ... }
case class PostMessageRequest(userID: UserID, message: String) extends ConversationRestEntities
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
implicit val postMessageRequestFormat = jsonFormat2(PostMessageRequest)
}
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>gameoflife</artifactId>
<groupId>com.wakaleo.gameoflife</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wakaleo.gameoflife</groupId>
<artifactId>gameoflife-web</artifactId>
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "CloudFormation template for testing",
"Metadata": {
"AWS::CloudFormation::Designer": {
"2042eff7-d31c-4904-afb0-4d2358ae7b40": {
"size": {
"width": 60,
"height": 60
},