package sample.scala import javax.ws.rs.{GET, POST, Path, Produces, WebApplicationException, Consumes} import se.scalablesolutions.akka.kernel.state.{TransactionalState, TransactionalMap, CassandraStorageConfig} import se.scalablesolutions.akka.kernel.actor.{Supervisor, SupervisorFactory, Actor, StartSupervisor} import se.scalablesolutions.akka.kernel.config.ScalaConfig._ import javax.ws.rs.core.MultivaluedMap import _root_.scala.xml.{NodeSeq} import se.scalablesolutions.akka.kernel.util.{Logging} import org.atmosphere.core.annotation.{Broadcast, BroadcastFilter, Suspend} import org.atmosphere.util.{XSSHtmlFilter} class Boot { object factory extends SupervisorFactory { override def getSupervisorConfig: SupervisorConfig = { SupervisorConfig( RestartStrategy(OneForOne, 3, 100), Supervise( new Chat, LifeCycle(Permanent, 100)) :: Nil) } } val supervisor = factory.newSupervisor supervisor.startSupervisor } /** * 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 { uuid = "SimpleService" makeTransactionRequired case object Tick private val KEY = "COUNTER"; private var hasStartedTicking = false; private val storage = TransactionalState.newPersistentMap(CassandraStorageConfig()) @GET @Produces(Array("text/html")) def count() = { (this !! Tick).getOrElse(
{who} says: {msg}
) case _ => throw new WebApplicationException(422) } } } @Broadcast @Consumes(Array("application/x-www-form-urlencoded")) @POST @Produces(Array("text/html")) //@BroadcastFilter(Array(classOf[XSSHtmlFilter]))//,classOf[JsonpFilter])) def publishMessage(form: MultivaluedMap[String, String]) = (this !! Chat(form.getFirst("name"),form.getFirst("action"),form.getFirst("message"))).getOrElse(Error
) }