Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
janm399 committed Jul 3, 2012
1 parent 6c71672 commit 7cbbd64
Show file tree
Hide file tree
Showing 24 changed files with 1,052 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
55 changes: 55 additions & 0 deletions maven/api/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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"
)

}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -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]
}
}

}
Original file line number Diff line number Diff line change
@@ -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
}
}

}
Original file line number Diff line number Diff line change
@@ -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)
}

}
31 changes: 31 additions & 0 deletions maven/core/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
7 changes: 7 additions & 0 deletions maven/core/src/main/resources/META-INF/aop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<aspectj>

<weaver options="-XnoInline -Xreweavable ">
<include within="org.cakesolutions.akkapatterns..*"/>
</weaver>

</aspectj>
18 changes: 18 additions & 0 deletions maven/core/src/main/resources/META-INF/spring/module-context.xml
Original file line number Diff line number Diff line change
@@ -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>
40 changes: 40 additions & 0 deletions maven/core/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 7cbbd64

Please sign in to comment.