Permalink
Browse files

Build

  • Loading branch information...
janm399 committed Jul 3, 2012
1 parent 6c71672 commit 7cbbd6481ddc700bc4c874d4967b963ab3eec735
Showing with 1,052 additions and 1 deletion.
  1. +44 −0 .gitignore
  2. +1 −1 README.md
  3. +55 −0 maven/api/pom.xml
  4. +23 −0 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/boot.scala
  5. +39 −0 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/home.scala
  6. +36 −0 maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/marshalling.scala
  7. +20 −0 maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/HomeServiceSpec.scala
  8. +26 −0 maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/RootSprayTest.scala
  9. +31 −0 maven/core/pom.xml
  10. +7 −0 maven/core/src/main/resources/META-INF/aop.xml
  11. +18 −0 maven/core/src/main/resources/META-INF/spring/module-context.xml
  12. +40 −0 maven/core/src/main/resources/application.conf
  13. +77 −0 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/application.scala
  14. +5 −0 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/exceptions.scala
  15. +25 −0 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/boot.scala
  16. +35 −0 maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/configuration.scala
  17. +50 −0 maven/domain/pom.xml
  18. +7 −0 maven/domain/src/main/scala/org/cakesolutions/akkapatterns/domain/domain.scala
  19. +89 −0 maven/main/pom.xml
  20. +21 −0 maven/main/src/main/scala/org/cakesolutions/akkapatterns/main/Main.scala
  21. +287 −0 maven/parent/pom.xml
  22. +36 −0 maven/pom.xml
  23. +44 −0 maven/web/pom.xml
  24. +36 −0 maven/web/src/main/scala/org/cakesolutions/akkapatterns/web/boot.scala
View
@@ -0,0 +1,44 @@
+.DS_Store
+._.DS_Store*
+.metadata
+.project
+.classpath
+.settings
+.history
+gen
+**/*.swp
+**/*~.nib
+**/build/
+**/*.pbxuser
+**/*.perspective
+**/*.perspectivev3
+**/*.xcodeproj/xcuserdata/*
+**/*.xcodeproj/project.xcworkspace/xcuserdata/*
+**/target
+target
+*.iml
+project/*.ipr
+project/*.iml
+project/*.iws
+project/out
+project/*/target
+project/target
+project/*/bin
+project/*/build
+project/*.iml
+project/*/*.iml
+project/.idea
+project/.idea/*
+.idea
+.idea/*
+.idea/**/*
+.DS_Store
+project/.DS_Store
+project/*/.DS_Store
+tm.out
+tmlog*.log
+*.tm*.epoch
+out/
+provisioning/.vagrant
+provisioning/*/.vagrant
+provisioning/*/*.known
View
@@ -14,4 +14,4 @@ The topics I shall cover include:
* User interface
* And many more
-See the [Wiki](wiki/Home) for documentation of the various patterns; and please do share your ideas!
+See the [Wiki](akka-patterns/wiki/Home) for documentation of the various patterns; and please do share your ideas!
View
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.cakesolutions.akkapatterns</groupId>
+ <artifactId>server-parent</artifactId>
+ <version>0.1.RELEASE-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>api</artifactId>
+ <packaging>jar</packaging>
+ <name>Akka Patterns - API</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.cakesolutions.akkapatterns</groupId>
+ <artifactId>core</artifactId>
+ <version>0.1.RELEASE-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>cc.spray</groupId>
+ <artifactId>spray-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cc.spray</groupId>
+ <artifactId>spray-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>cc.spray</groupId>
+ <artifactId>spray-base</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-actor</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>net.liftweb</groupId>
+ <artifactId>lift-json_2.9.1</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.specs2</groupId>
+ <artifactId>specs2_${scala.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,23 @@
+package org.cakesolutions.akkapatterns.api
+
+import akka.actor.{ActorRef, Props}
+import cc.spray.{RootService, Route, HttpService, SprayCanRootService}
+import org.cakesolutions.akkapatterns.core.Core
+
+trait Api {
+ this: Core =>
+
+ val routes =
+ new HomeService().route :: Nil
+
+ val svc: Route => ActorRef = route => actorSystem.actorOf(Props(new HttpService(route)))
+
+ val rootService = actorSystem.actorOf(
+ props = Props(new RootService(
+ svc(routes.head),
+ routes.tail.map(svc):_*
+ )),
+ name = "root-service"
+ )
+
+}
@@ -0,0 +1,39 @@
+package org.cakesolutions.akkapatterns.api
+
+import akka.actor.ActorSystem
+import cc.spray.Directives
+import cc.spray.directives.Slash
+import java.net.InetAddress
+import akka.pattern.ask
+import akka.util.Timeout
+import org.cakesolutions.akkapatterns.core.application.{PoisonPill, GetImplementation, Implementation}
+
+case class SystemInfo(implementation: Implementation, host: String)
+
+class HomeService(implicit val actorSystem: ActorSystem) extends Directives with Marshallers {
+ implicit val timeout = Timeout(3000)
+
+ def applicationActor = actorSystem.actorFor("/user/application")
+
+ val route = {
+ path(Slash) {
+ get {
+ completeWith {
+ (applicationActor ? GetImplementation()).mapTo[Implementation].map {
+ SystemInfo(_, InetAddress.getLocalHost.getCanonicalHostName)
+ }
+ }
+ }
+ } ~
+ path("poisonpill") {
+ post {
+ completeWith {
+ applicationActor ! PoisonPill()
+
+ "Goodbye"
+ }
+ }
+ }
+ }
+
+}
@@ -0,0 +1,36 @@
+package org.cakesolutions.akkapatterns.api
+
+import cc.spray.typeconversion._
+import net.liftweb.json._
+import cc.spray.http.{HttpContent, ContentType}
+import cc.spray.http.MediaTypes._
+import net.liftweb.json.Serialization._
+import cc.spray.http.ContentTypeRange
+
+trait Marshallers extends DefaultMarshallers {
+ implicit def liftJsonFormats: Formats =
+ DefaultFormats + FieldSerializer[AnyRef]()
+
+ implicit def liftJsonMarshaller[A <: Product] = new SimpleMarshaller[A] {
+ val canMarshalTo = ContentType(`application/json`) :: Nil
+ def marshal(value: A, contentType: ContentType) = {
+ val jsonSource = write(value)
+ DefaultMarshallers.StringMarshaller.marshal(jsonSource, contentType)
+ }
+ }
+
+}
+
+trait Unmarshallers extends DefaultMarshallers {
+ implicit def liftJsonFormats: Formats =
+ DefaultFormats + FieldSerializer[AnyRef]()
+
+ implicit def liftJsonUnmarshaller[A <: Product : Manifest] = new SimpleUnmarshaller[A] {
+ val canUnmarshalFrom = ContentTypeRange(`application/json`) :: Nil
+ def unmarshal(content: HttpContent) = protect {
+ val jsonSource = DefaultUnmarshallers.StringUnmarshaller(content).right.get
+ parse(jsonSource).extract[A]
+ }
+ }
+
+}
@@ -0,0 +1,20 @@
+package org.cakesolutions.akkapatterns.api
+
+import org.specs2.mutable.Specification
+import org.cakesolutions.akkapatterns.core.Core
+import cc.spray.http.HttpMethods._
+import cc.spray.http._
+import org.specs2.runner.JUnitRunner
+import org.junit.runner.RunWith
+
+@RunWith(classOf[JUnitRunner])
+class HomeServiceSpec extends Specification with RootSprayTest with Core with Api with Unmarshallers {
+
+ "root URL shows the System version" in {
+ testRoot(HttpRequest(GET, "/"))(rootService).response.content.as[SystemInfo] match {
+ case Right(info) => success
+ case Left(failure) => anError
+ }
+ }
+
+}
@@ -0,0 +1,26 @@
+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
+import cc.spray.http._
+
+trait RootSprayTest extends SprayTest {
+ protected def testRoot(request: HttpRequest, timeout: Duration = Duration(10000, TimeUnit.MILLISECONDS))
+ (root: ActorRef): ServiceResultWrapper = {
+ val routeResult = new RouteResult
+ root !
+ RequestContext(
+ request = request,
+ responder = routeResult.requestResponder,
+ unmatchedPath = request.path
+ )
+
+ // since the route might detach we block until the route actually completes or times out
+ routeResult.awaitResult(timeout)
+ new ServiceResultWrapper(routeResult, timeout)
+ }
+
+}
View
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.cakesolutions.akkapatterns</groupId>
+ <artifactId>server-parent</artifactId>
+ <version>0.1.RELEASE-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>core</artifactId>
+ <packaging>jar</packaging>
+ <name>Akka Patterns - Core</name>
+ <dependencies>
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-actor</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-testkit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.specs2</groupId>
+ <artifactId>specs2_${scala.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,7 @@
+<aspectj>
+
+ <weaver options="-XnoInline -Xreweavable ">
+ <include within="org.cakesolutions.akkapatterns..*"/>
+ </weaver>
+
+</aspectj>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
+ xmlns:mongo="http://www.springframework.org/schema/data/mongo"
+ xmlns:repository="http://www.springframework.org/schema/data/repository"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd
+ http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
+ http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd">
+
+
+
+</beans>
@@ -0,0 +1,40 @@
+akka {
+ loglevel = DEBUG
+
+ actor {
+ debug {
+ event-stream = on
+ receive = on
+ lifecycle = on
+ }
+
+ default-dispatcher {
+ type = "Dispatcher"
+
+ executor = "fork-join-executor"
+
+ fork-join-executor {
+ # Min number of threads to cap factor-based parallelism number to
+ parallelism-min = 8
+ # Parallelism (threads) ... ceil(available processors * factor)
+ parallelism-factor = 15.0
+ # Max number of threads to cap factor-based parallelism number to
+ parallelism-max = 64
+ }
+
+ throughput = 5
+
+ attempt-teamwork = on
+
+ }
+ }
+}
+
+spray {
+ can.server {
+ idle-timeout = 5 s
+ request-timeout = 2 s
+ }
+
+ io.confirm-sends = off
+}
Oops, something went wrong.

0 comments on commit 7cbbd64

Please sign in to comment.