/** * Copyright (C) 2009 Scalable Solutions. */ package sample.scala import se.scalablesolutions.akka.actor.{SupervisorFactory, Actor} import se.scalablesolutions.akka.state.{CassandraStorage, TransactionalState} import se.scalablesolutions.akka.config.ScalaConfig._ import se.scalablesolutions.akka.util.Logging import java.lang.Integer import java.nio.ByteBuffer import javax.ws.rs.core.MultivaluedMap import javax.ws.rs.{GET, POST, Path, Produces, WebApplicationException, Consumes,PathParam} import org.atmosphere.annotation.{Broadcast, Suspend} import org.atmosphere.util.XSSHtmlFilter import org.atmosphere.cpr.{Broadcaster, BroadcastFilter} import org.atmosphere.jersey.Broadcastable class Boot { val factory = SupervisorFactory( SupervisorConfig( RestartStrategy(OneForOne, 3, 100,List(classOf[Exception])), Supervise( new SimpleService, LifeCycle(Permanent)) :: Supervise( new Chat, LifeCycle(Permanent)) :: Supervise( new PersistentSimpleService, LifeCycle(Permanent)) :: Supervise( new PubSub, LifeCycle(Permanent)) :: Nil)) factory.newInstance.start } @Path("/pubsub/") class PubSub extends Actor { case class Msg(topic: String, message: String) @GET @Suspend @Produces(Array("text/plain;charset=ISO-8859-1")) @Path("/topic/{topic}/") def subscribe(@PathParam("topic") topic: Broadcaster): Broadcastable = new Broadcastable("", topic) @GET @Broadcast @Path("/topic/{topic}/{message}/") @Produces(Array("text/plain;charset=ISO-8859-1")) def say(@PathParam("topic") topic: Broadcaster, @PathParam("message") message: String): Broadcastable = new Broadcastable(message, topic) override def receive = { case _ => } } /** * Try service out by invoking (multiple times): *
* curl http://localhost:9998/scalacount ** Or browse to the URL from a web browser. */ @Path("/scalacount") class SimpleService extends Actor { makeTransactionRequired case object Tick private val KEY = "COUNTER" private var hasStartedTicking = false private val storage = TransactionalState.newMap[String, Integer] @GET @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(
* curl http://localhost:9998/persistentscalacount ** Or browse to the URL from a web browser. */ @Path("/persistentscalacount") class PersistentSimpleService extends Actor { makeTransactionRequired case object Tick private val KEY = "COUNTER" private var hasStartedTicking = false private val storage = CassandraStorage.newMap @GET @Produces(Array("text/html")) def count = (this !! Tick).getOrElse(