Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2.10.0-M7 base work for the new Spray

  • Loading branch information...
commit 8b63ed8e6ee779e92199baa9f12b0f7ffaee1f32 1 parent adc3fea
@janm janm authored
Showing with 68 additions and 235 deletions.
  1. +1 −1  maven/api/pom.xml
  2. +7 −2 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/boot.scala
  3. +1 −1  maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/dummy.scala
  4. +1 −0  maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/home.scala
  5. +2 −2 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/marshalling.scala
  6. +1 −1  maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/support.scala
  7. +15 −3 maven/core/pom.xml
  8. +1 −1  maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/application.scala
  9. +0 −109 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/casbah.scala
  10. +5 −7 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/customer.scala
  11. +1 −1  maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/boot.scala
  12. +4 −1 ...rc/test/scala/org/cakesolutions/akkapatterns/core/{CustomerActorSpec.scala → CustomerActorSpecx.scala}
  13. +1 −5 maven/main/pom.xml
  14. +0 −6 maven/main/src/main/scala/org/cakesolutions/akkapatterns/main/Main.scala
  15. +26 −80 maven/parent/pom.xml
  16. +0 −4 maven/test/pom.xml
  17. +0 −9 maven/test/src/main/scala/org/cakesolutions/akkapatterns/test/SpecConfiguration.scala
  18. +1 −1  maven/web/pom.xml
  19. +1 −1  maven/web/src/main/scala/org/cakesolutions/akkapatterns/web/boot.scala
View
2  maven/api/pom.xml
@@ -44,7 +44,7 @@
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
<dependency>
View
9 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/boot.scala
@@ -1,7 +1,8 @@
package org.cakesolutions.akkapatterns.api
import akka.actor.{ActorRef, Props}
-import cc.spray.{RootService, Route, HttpService}
+import cc.spray._
+import http.{StatusCodes, HttpResponse}
import org.cakesolutions.akkapatterns.core.Core
import akka.util.Timeout
@@ -14,7 +15,11 @@ trait Api {
new CustomerService().route ::
Nil
- val svc: Route => ActorRef = route => actorSystem.actorOf(Props(new HttpService(route)))
+ def rejectionHandler: PartialFunction[scala.List[cc.spray.Rejection], cc.spray.http.HttpResponse] = {
+ case (rejections: List[Rejection]) => HttpResponse(StatusCodes.BadRequest)
+ }
+
+ val svc: Route => ActorRef = route => actorSystem.actorOf(Props(new HttpService(route, rejectionHandler)))
val rootService = actorSystem.actorOf(
props = Props(new RootService(
View
2  maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/dummy.scala
@@ -41,7 +41,7 @@ class DummyService(path: String)(implicit val actorSystem: ActorSystem) extends
scala.io.Source.fromInputStream(getClass.getResourceAsStream(filename)).mkString
}
catch {
- case _ => "{body of file " + filename + " -- Missing File!}"
+ case _: Throwable => "{body of file " + filename + " -- Missing File!}"
}
}
}
View
1  maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/home.scala
@@ -12,6 +12,7 @@ case class SystemInfo(implementation: Implementation, host: String)
class HomeService(implicit val actorSystem: ActorSystem) extends Directives with Marshallers with DefaultTimeout with LiftJSON {
def applicationActor = actorSystem.actorFor("/user/application")
+ import scala.concurrent.ExecutionContext.Implicits.global
val route = {
path(Slash) {
View
4 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/marshalling.scala
@@ -11,10 +11,10 @@ import java.util.UUID
trait Marshallers extends DefaultMarshallers {
this: LiftJSON =>
- implicit def liftJsonMarshaller[A <: Product] = new SimpleMarshaller[A] {
+ implicit def liftJsonMarshaller[A <: AnyRef] = new SimpleMarshaller[A] {
val canMarshalTo = ContentType(`application/json`) :: Nil
def marshal(value: A, contentType: ContentType) = {
- val jsonSource = write(value)
+ val jsonSource = write(value.asInstanceOf[AnyRef])
DefaultMarshallers.StringMarshaller.marshal(jsonSource, contentType)
}
}
View
2  maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/support.scala
@@ -1,7 +1,6 @@
package org.cakesolutions.akkapatterns.api
import cc.spray.test.SprayTest
-import akka.util.Duration
import java.util.concurrent.TimeUnit
import akka.actor.ActorRef
import cc.spray.RequestContext
@@ -10,6 +9,7 @@ import io.Source
import org.specs2.mutable.Specification
import org.cakesolutions.akkapatterns.test.{DefaultTestData, SpecConfiguration}
import org.cakesolutions.akkapatterns.core.Core
+import concurrent.util.Duration
trait RootSprayTest extends SprayTest {
protected def testRoot(request: HttpRequest, timeout: Duration = Duration(10000, TimeUnit.MILLISECONDS))
View
18 maven/core/pom.xml
@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
<dependency>
<groupId>org.cakesolutions.akkapatterns</groupId>
@@ -22,7 +22,7 @@
<version>0.1.RELEASE-SNAPSHOT</version>
</dependency>
- <!-- MongoDB -->
+ <!--
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>casbah-core_${scala.version}</artifactId>
@@ -35,10 +35,11 @@
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
+ -->
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-testkit</artifactId>
+ <artifactId>akka-testkit_${scala.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -47,6 +48,17 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.specs2</groupId>
+ <artifactId>specs2-scalaz-core_${scala.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.cakesolutions.akkapatterns</groupId>
<artifactId>test</artifactId>
<version>0.1.RELEASE-SNAPSHOT</version>
View
2  maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/application.scala
@@ -10,7 +10,7 @@ case class PoisonPill()
class ApplicationActor extends Actor {
- protected def receive = {
+ def receive = {
case GetImplementation() =>
val manifestStream = getClass.getResourceAsStream("/META-INF/MANIFEST.MF")
val manifest = new java.util.jar.Manifest(manifestStream)
View
109 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/casbah.scala
@@ -1,109 +0,0 @@
-package org.cakesolutions.akkapatterns.core.application
-
-import com.mongodb.casbah.Imports._
-import java.util.UUID
-import org.cakesolutions.akkapatterns.domain.{Address, Customer}
-
-/**
- * Contains type classes that deserialize records from Casbah into "our" types.
- */
-trait CasbahDeserializers {
- type CasbahDeserializer[A] = DBObject => A
-
- /**
- * Convenience method that picks the ``CasbahDeserializer`` for the type ``A``
- * @param deserializer implicitly given deserializer
- * @tparam A the type A
- * @return the deserializer for ``A``
- */
- def casbahDeserializer[A](implicit deserializer: CasbahDeserializer[A]) = deserializer
-
- private def inner[A: CasbahDeserializer](o: DBObject, field: String): A = casbahDeserializer[A].apply(o.as[DBObject](field))
-
- private def innerList[A: CasbahDeserializer](o: DBObject, field: String): Seq[A] = {
- val deserializer = casbahDeserializer[A]
- o.as[MongoDBList](field).map {
- inner => deserializer(inner.asInstanceOf[DBObject])
- }
- }
-
- implicit object AddressDeserializer extends CasbahDeserializer[Address] {
- def apply(o: DBObject) =
- Address(o.as[String]("line1"), o.as[String]("line2"), o.as[String]("line3"))
- }
-
- implicit object CustomerDeserializer extends CasbahDeserializer[Customer] {
- def apply(o: DBObject) =
- Customer(o.as[String]("firstName"), o.as[String]("lastName"), o.as[String]("email"),
- innerList[Address](o, "addresses"), o.as[UUID]("id"))
- }
-
-}
-
-/**
- * Contains type classes that serialize "our" types into Casbah records.
- */
-trait CasbahSerializers {
- type CasbahSerializer[A] = A => DBObject
-
- /**
- * Convenience method that picks the ``CasbahSerializer`` for the type ``A``
- * @param serializer implicitly given serializer
- * @tparam A the type A
- * @return the serializer for ``A``
- */
- def casbahSerializer[A](implicit serializer: CasbahSerializer[A]) = serializer
-
- implicit object AddressSerializer extends CasbahSerializer[Address] {
- def apply(address: Address) = {
- val builder = MongoDBObject.newBuilder
-
- builder += "line1" -> address.line1
- builder += "line2" -> address.line2
- builder += "line3" -> address.line2
-
- builder.result()
- }
- }
-
- implicit object CustomerSerializer extends CasbahSerializer[Customer] {
- def apply(customer: Customer) = {
- val builder = MongoDBObject.newBuilder
-
- builder += "firstName" -> customer.firstName
- builder += "lastName" -> customer.lastName
- builder += "email" -> customer.email
- builder += "addresses" -> customer.addresses.map(AddressSerializer(_))
- builder += "id" -> customer.id
-
- builder.result()
- }
- }
-
-}
-
-/**
- * Contains convenience functions that can be used to find "entities-by-id"
- */
-trait SearchExpressions {
-
- def entityId(id: UUID) = MongoDBObject("id" -> id)
-
-// def entityId(id: UUID) = MongoDBObject("id" -> id, "active" -> true)
-
-}
-
-/**
- * Mix this trait into your classes to gain the functionality of the serializers, deserializers and mappers.
- */
-trait TypedCasbah extends CasbahDeserializers with CasbahSerializers {
-
- final def serialize[A: CasbahSerializer](a: A) = casbahSerializer[A].apply(a)
-
- final def deserialize[A: CasbahDeserializer](o: DBObject) = casbahDeserializer[A].apply(o)
-
- final def mapper[A: CasbahDeserializer] = {
- (o: DBObject) => deserialize[A](o)
- }
-
-}
View
12 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/customer.scala
@@ -3,7 +3,6 @@ package org.cakesolutions.akkapatterns.core.application
import akka.actor.Actor
import java.util.UUID
import org.cakesolutions.akkapatterns.domain.{Configured, Customer}
-import com.mongodb.casbah.MongoDB
case class Get(id: UUID)
case class FindAll()
@@ -12,19 +11,18 @@ case class Insert(customer: Customer)
/**
* @author janmachacek
*/
-class CustomerActor extends Actor with Configured with TypedCasbah with SearchExpressions {
+class CustomerActor extends Actor with Configured {
- def customers = configured[MongoDB].apply("customers")
- protected def receive = {
+ def receive = {
case Get(id) =>
- sender ! customers.findOne(entityId(id)).map(mapper[Customer])
+ sender ! None //customers.findOne(entityId(id)).map(mapper[Customer])
case FindAll() =>
- sender ! customers.find().map(mapper[Customer]).toList
+ sender ! List() //customers.find().map(mapper[Customer]).toList
case Insert(customer) =>
- customers += serialize(customer)
+ // customers += serialize(customer)
sender ! customer
}
}
View
2  maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/boot.scala
@@ -1,10 +1,10 @@
package org.cakesolutions.akkapatterns.core
import akka.actor.{Props, ActorSystem}
-import akka.dispatch.Await
import application.ApplicationActor
import akka.pattern.ask
import akka.util.Timeout
+import concurrent.Await
case class Start()
case class Started()
View
5 ...lutions/akkapatterns/core/CustomerActorSpec.scala → ...utions/akkapatterns/core/CustomerActorSpecx.scala
@@ -6,11 +6,14 @@ import org.specs2.mutable.Specification
import akka.testkit.{ImplicitSender, TestActorRef, TestKit}
import akka.actor.ActorSystem
import org.cakesolutions.akkapatterns.domain.Customer
+import org.specs2.runner.JUnitRunner
+import org.junit.runner.RunWith
/**
* @author janmachacek
*/
-class CustomerActorSpec extends TestKit(ActorSystem()) with Specification with SpecConfiguration with DefaultTestData with ImplicitSender {
+@RunWith(classOf[JUnitRunner])
+class CustomerActorSpecx extends TestKit(ActorSystem()) with Specification with SpecConfiguration with DefaultTestData with ImplicitSender {
val customerActor = TestActorRef[CustomerActor]
"Getting a known customer works" in {
View
6 maven/main/pom.xml
@@ -33,10 +33,6 @@
<version>0.1.RELEASE-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-core_${scala.version}</artifactId>
- </dependency>
- <dependency>
<groupId>cc.spray</groupId>
<artifactId>spray-server</artifactId>
</dependency>
@@ -46,7 +42,7 @@
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
</dependencies>
View
6 maven/main/src/main/scala/org/cakesolutions/akkapatterns/main/Main.scala
@@ -5,7 +5,6 @@ import org.cakesolutions.akkapatterns.domain.Configuration
import org.cakesolutions.akkapatterns.core.Core
import org.cakesolutions.akkapatterns.api.Api
import org.cakesolutions.akkapatterns.web.Web
-import com.mongodb.casbah.MongoConnection
object Main extends App {
// -javaagent:/Users/janmachacek/.m2/repository/org/springframework/spring-instrument/3.1.1.RELEASE/spring-instrument-3.1.1.RELEASE.jar -Xmx512m -XX:MaxPermSize=256m
@@ -13,11 +12,6 @@ object Main extends App {
implicit val system = ActorSystem("AkkaPatterns")
class Application(val actorSystem: ActorSystem) extends Core with Api with Web with Configuration {
- configure {
- val mongoDb = MongoConnection()("akka-patterns")
-
- mongoDb
- }
}
new Application(system)
View
106 maven/parent/pom.xml
@@ -11,26 +11,20 @@
<connection>scm:git:git@github.com:janm399/akka-patterns.git</connection>
</scm>
<properties>
- <spring.framework.version>3.1.1.RELEASE</spring.framework.version>
- <scala.version>2.9.2</scala.version>
- <scala.plugin.version>2.15.2</scala.plugin.version>
- <akka.version>2.0.1</akka.version>
- <spring-data-neo4j.version>2.0.1.RELEASE</spring-data-neo4j.version>
- <spring-data-mongodb.version>1.0.1.RELEASE</spring-data-mongodb.version>
+ <scala.version>2.10.0-M7</scala.version>
+ <scala.plugin.version>3.0.1</scala.plugin.version>
+ <akka.version>2.1-M2</akka.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <aspectj.version>1.6.12</aspectj.version>
- <scala.driver.version>0.8.15</scala.driver.version>
<spray.version>1.0-M2</spray.version>
- <shapeless.version>1.2.0</shapeless.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
- <version>${scala.plugin.version}</version>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
+ <version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
@@ -45,8 +39,8 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<goals>
@@ -78,17 +72,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.8</version>
+ <version>2.12</version>
<configuration>
- <argLine>
- -javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.framework.version}/spring-instrument-${spring.framework.version}.jar
- -Xmx512m
- </argLine>
<includes>
<!--<include>**/*Unit.java</include>-->
<include>**/*Spec.java</include>
</includes>
<threadCount>1</threadCount>
+ <additionalClasspathElements>
+ <additionalClasspathElement>${settings.localRepository}/org/scala-lang/scala-reflect/${scala.version}/scala-reflect-${scala.version}.jar</additionalClasspathElement>
+ </additionalClasspathElements>
</configuration>
</plugin>
<plugin>
@@ -121,9 +114,9 @@
<reporting>
<plugins>
<plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
- <version>${scala.plugin.version}</version>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
+ <version>3.1.0</version>
</plugin>
</plugins>
</reporting>
@@ -139,22 +132,22 @@
<!-- Akka Dependencies -->
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-kernel</artifactId>
+ <artifactId>akka-kernel_${scala.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-remote</artifactId>
+ <artifactId>akka-remote_${scala.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-testkit</artifactId>
+ <artifactId>akka-testkit_${scala.version}</artifactId>
<version>${akka.version}</version>
</dependency>
@@ -224,28 +217,6 @@
</exclusions>
</dependency>
- <!-- Scalaz -->
- <dependency>
- <groupId>org.scalaz</groupId>
- <artifactId>scalaz-core_${scala.version}</artifactId>
- <version>7.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.scalaz</groupId>
- <artifactId>scalaz-effect_${scala.version}</artifactId>
- <version>7.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.scalaz</groupId>
- <artifactId>scalaz-xml_${scala.version}</artifactId>
- <version>7.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.scalaz</groupId>
- <artifactId>scalaz-iteratee_${scala.version}</artifactId>
- <version>7.0-SNAPSHOT</version>
- </dependency>
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
@@ -255,16 +226,6 @@
<!-- Cassandra Cascal client -->
<dependency>
- <groupId>com.shorrockin</groupId>
- <artifactId>cascal_${scala.version}</artifactId>
- <version>1.3-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.cassandra</groupId>
- <artifactId>cassandra-all</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-thrift</artifactId>
<version>1.1.1</version>
@@ -275,33 +236,18 @@
<version>1.6</version>
</dependency>
- <!-- Casbah -->
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-core_${scala.version}</artifactId>
- <version>2.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-query_${scala.version}</artifactId>
- <version>2.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-commons_${scala.version}</artifactId>
- <version>2.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>mongo-java-driver</artifactId>
- <version>2.8.0</version>
- </dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_${scala.version}</artifactId>
- <version>1.11</version>
+ <version>1.12.1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.specs2</groupId>
+ <artifactId>specs2-scalaz-core_${scala.version}</artifactId>
+ <version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
View
4 maven/test/pom.xml
@@ -21,10 +21,6 @@
<artifactId>domain</artifactId>
<version>0.1.RELEASE-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-core_${scala.version}</artifactId>
- </dependency>
<!--
<dependency>
View
9 maven/test/src/main/scala/org/cakesolutions/akkapatterns/test/SpecConfiguration.scala
@@ -1,20 +1,11 @@
package org.cakesolutions.akkapatterns.test
import org.cakesolutions.akkapatterns.domain.Configuration
-import io.Source
-import com.mongodb.casbah.MongoConnection
/**
* @author janmachacek
*/
trait SpecConfiguration extends Configuration {
- configure {
- val mongoDb = MongoConnection()("akka-patterns-test")
- val json = Source.fromInputStream(classOf[SpecConfiguration].getResourceAsStream("/org/cakesolutions/akkapatterns/mongodb-base.js")).mkString
- mongoDb.eval(json)
-
- mongoDb
- }
}
View
2  maven/web/pom.xml
@@ -37,7 +37,7 @@
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
</dependencies>
View
2  maven/web/src/main/scala/org/cakesolutions/akkapatterns/web/boot.scala
@@ -19,7 +19,7 @@ trait Web {
// handled by the root service actor
val sprayCanServer = actorSystem.actorOf(
Props(new HttpServer(ioWorker, MessageHandlerDispatch.SingletonHandler(
- actorSystem.actorOf(Props(new SprayCanRootService(rootService)))))),
+ actorSystem.actorOf(Props(new SprayCanRootService(rootService)))), actorSystem.settings.config)),
name = "http-server"
)
Please sign in to comment.
Something went wrong with that request. Please try again.