forked from eigengo/akka-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,052 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
23 changes: 23 additions & 0 deletions
23
maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/boot.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/home.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
maven/api/src/main/scala/org/cakesolutions/akkapatterns/api/marshalling.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/HomeServiceSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
maven/api/src/test/scala/org/cakesolutions/akkapatterns/api/RootSprayTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
maven/core/src/main/resources/META-INF/spring/module-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.