diff --git a/akka-samples/akka-sample-lift/src/main/scala/akka/SimpleService.scala b/akka-samples/akka-sample-lift/src/main/scala/akka/SimpleService.scala
index 7557404da9..4d20b60448 100644
--- a/akka-samples/akka-sample-lift/src/main/scala/akka/SimpleService.scala
+++ b/akka-samples/akka-sample-lift/src/main/scala/akka/SimpleService.scala
@@ -1,35 +1,24 @@
package sample.lift
-import se.scalablesolutions.akka.actor.{Transactor, Actor}
+import se.scalablesolutions.akka.actor._
+import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.config.ScalaConfig._
import se.scalablesolutions.akka.stm.TransactionalMap
import se.scalablesolutions.akka.persistence.cassandra.CassandraStorage
-import Actor._
-
+import scala.xml.Node
import java.lang.Integer
import javax.ws.rs.{GET, Path, Produces}
import java.nio.ByteBuffer
+import net.liftweb.http._
+import net.liftweb.http.rest._
-/**
- * Try service out by invoking (multiple times):
- *
- * curl http://localhost:9998/liftcount
- *
- * Or browse to the URL from a web browser.
- */
-@Path("/liftcount")
-class SimpleService extends Transactor {
- case object Tick
+class SimpleServiceActor extends Transactor {
private val KEY = "COUNTER"
private var hasStartedTicking = false
private lazy val storage = TransactionalMap[String, Integer]()
- @GET
- @Produces(Array("text/html"))
- def count = (self !! Tick).getOrElse(Error in counter
)
-
def receive = {
- case Tick => if (hasStartedTicking) {
+ case "Tick" => if (hasStartedTicking) {
val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue
storage.put(KEY, new Integer(counter + 1))
self.reply(Tick: {counter + 1}
)
@@ -41,27 +30,14 @@ class SimpleService extends Transactor {
}
}
-/**
- * Try service out by invoking (multiple times):
- *
- * curl http://localhost:9998/persistentliftcount
- *
- * Or browse to the URL from a web browser.
- */
-@Path("/persistentliftcount")
-class PersistentSimpleService extends Transactor {
+class PersistentServiceActor extends Transactor {
- case object Tick
private val KEY = "COUNTER"
private var hasStartedTicking = false
private lazy val storage = CassandraStorage.newMap
- @GET
- @Produces(Array("text/html"))
- def count = (self !! Tick).getOrElse(Error in counter
)
-
def receive = {
- case Tick => if (hasStartedTicking) {
+ case "Tick" => if (hasStartedTicking) {
val bytes = storage.get(KEY.getBytes).get
val counter = ByteBuffer.wrap(bytes).getInt
storage.put(KEY.getBytes, ByteBuffer.allocate(4).putInt(counter + 1).array)
@@ -73,3 +49,46 @@ class PersistentSimpleService extends Transactor {
}
}
}
+
+
+/**
+ * Try service out by invoking (multiple times):
+ *
+ * curl http://localhost:8080/liftcount
+ *
+ * Or browse to the URL from a web browser.
+ */
+
+object SimpleRestService extends RestHelper {
+ serve {
+ case Get("liftcount" :: _, req) =>
+ //Fetch the first actor of type SimpleServiceActor
+ //Send it the "Tick" message and expect a Node back
+ val result = for( a <- ActorRegistry.actorsFor(classOf[SimpleServiceActor]).headOption;
+ r <- (a !! "Tick").as[Node] ) yield r
+
+ //Return either the resulting NodeSeq or a default one
+ (result getOrElse Error in counter
).asInstanceOf[Node]
+ }
+}
+
+
+/**
+ * Try service out by invoking (multiple times):
+ *
+ * curl http://localhost:8080/persistentliftcount
+ *
+ * Or browse to the URL from a web browser.
+ */
+ object PersistentRestService extends RestHelper {
+ serve {
+ case Get("persistentliftcount" :: _, req) =>
+ //Fetch the first actor of type SimpleServiceActor
+ //Send it the "Tick" message and expect a Node back
+ val result = for( a <- ActorRegistry.actorsFor(classOf[PersistentServiceActor]).headOption;
+ r <- (a !! "Tick").as[Node] ) yield r
+
+ //Return either the resulting NodeSeq or a default one
+ (result getOrElse Error in counter
).asInstanceOf[Node]
+ }
+ }
\ No newline at end of file
diff --git a/akka-samples/akka-sample-lift/src/main/scala/bootstrap/liftweb/Boot.scala b/akka-samples/akka-sample-lift/src/main/scala/bootstrap/liftweb/Boot.scala
index 0f4a0e9020..2e56a5857a 100644
--- a/akka-samples/akka-sample-lift/src/main/scala/bootstrap/liftweb/Boot.scala
+++ b/akka-samples/akka-sample-lift/src/main/scala/bootstrap/liftweb/Boot.scala
@@ -13,7 +13,7 @@ import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.config.ScalaConfig._
import se.scalablesolutions.akka.util.Logging
-import sample.lift.{PersistentSimpleService, SimpleService}
+import sample.lift._
/**
* A class that's instantiated early and run. It allows the application
@@ -35,6 +35,8 @@ class Boot extends Logging {
true
}
}
+ LiftRules.statelessDispatchTable.append(SimpleRestService)
+ LiftRules.statelessDispatchTable.append(PersistentRestService)
LiftRules.passNotFoundToChain = true
@@ -42,10 +44,10 @@ class Boot extends Logging {
SupervisorConfig(
RestartStrategy(OneForOne, 3, 100, List(classOf[Exception])),
Supervise(
- actorOf[SimpleService],
+ actorOf[SimpleServiceActor],
LifeCycle(Permanent)) ::
Supervise(
- actorOf[PersistentSimpleService],
+ actorOf[PersistentServiceActor],
LifeCycle(Permanent)) ::
Nil))
factory.newInstance.start
diff --git a/akka-samples/akka-sample-lift/src/main/webapp/WEB-INF/web.xml b/akka-samples/akka-sample-lift/src/main/webapp/WEB-INF/web.xml
index 23348604bb..3a1b672cec 100644
--- a/akka-samples/akka-sample-lift/src/main/webapp/WEB-INF/web.xml
+++ b/akka-samples/akka-sample-lift/src/main/webapp/WEB-INF/web.xml
@@ -13,7 +13,7 @@
AkkaServlet
- se.scalablesolutions.akka.rest.AkkaServlet
+ se.scalablesolutions.akka.comet.AkkaServlet
AkkaServlet
diff --git a/config/akka-reference.conf b/config/akka-reference.conf
index 23412db3d3..c504598e31 100644
--- a/config/akka-reference.conf
+++ b/config/akka-reference.conf
@@ -57,7 +57,9 @@ akka {
hostname = "localhost"
port = 9998
filters = ["se.scalablesolutions.akka.security.AkkaSecurityFilterFactory"] # List with all jersey filters to use
- resource_packages = ["sample.rest.scala","sample.rest.java","sample.security"] # List with all resource packages for your Jersey services
+ resource_packages = ["sample.rest.scala",
+ "sample.rest.java",
+ "sample.security"] # List with all resource packages for your Jersey services
authenticator = "sample.security.BasicAuthenticationService" # The authentication service to use. Need to be overridden (uses sample now)
#maxInactiveActivity = 60000 #Atmosphere CometSupport maxInactiveActivity
#IF you are using a KerberosAuthenticationActor
diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala
index 8020b848af..b642b977ea 100644
--- a/project/build/AkkaProject.scala
+++ b/project/build/AkkaProject.scala
@@ -310,13 +310,14 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
class AkkaSampleChatProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) with CodeFellowPlugin
class AkkaSamplePubSubProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) with CodeFellowPlugin
- class AkkaSampleLiftProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) with CodeFellowPlugin {
+ class AkkaSampleLiftProject(info: ProjectInfo) extends DefaultWebProject(info) with DeployProject with CodeFellowPlugin {
+ def deployPath = AkkaParent.this.deployPath
val commons_logging = "commons-logging" % "commons-logging" % "1.1.1" % "compile"
val lift = "net.liftweb" % "lift-webkit" % LIFT_VERSION % "compile"
val lift_util = "net.liftweb" % "lift-util" % LIFT_VERSION % "compile"
val servlet = "javax.servlet" % "servlet-api" % "2.5" % "compile"
// testing
- val jetty = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test"
+ val jettyServer = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test"
val junit = "junit" % "junit" % "4.5" % "test"
}
@@ -403,7 +404,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) {
// ------------------------------------------------------------
class AkkaDefaultProject(info: ProjectInfo, val deployPath: Path) extends DefaultProject(info) with DeployProject
- trait DeployProject extends DefaultProject {
+ trait DeployProject { self: Project =>
// defines where the deployTask copies jars to
def deployPath: Path