brew install sbt
Create an akka project
mkdir akka-dynamo cd akka-dynamo mkdir -p src/main/scala mkdir -p src/test/scala
name := "Akka Dynamo" scalaVersion := "2.9.2" resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" retrieveManaged := true libraryDependencies ++= Seq("com.typesafe.akka" % "akka-actor" % "2.0.3", "com.typesafe.akka" % "akka-remote" % "2.0.3", "com.typesafe.akka" % "akka-testkit" % "2.0.3" % "test", "org.specs2" %% "specs2" % "1.9" % "test", "junit" % "junit" % "4.5" % "test")
Scala is a strongly typed language so the message types have to be defined. [Case classes] (http://www.scala-lang.org/node/107) are ideal for defining value types like akka messages and enable pattern matching in the actors. Note
Stop do not require any parameters so are defined as singltons with
case object instead.
Erlang is weakly typed and most data structures are a combination of list, tuples and litterals. In scala tuples are replaced cases classes, these are like named tuple types. Litterals are either case objects or java primatives.
Akka actors are classes that extend
Actor the method recieve is called for each message. Unlike Erlang the this method does not have to recursivelly call itself.
The import statements are standard scala imports and are required to use the Akka api. However the
akka.pattern imports enable the
pipe patterns. These enable actors to recieve responses to messages they send with the
? operator and
pipe the responses back as their own reply.
Start message starts the server and spawns the database
NodeActors and replies with
Stop message stops the nodes and itself by sending a
PoisonPill to terminate the actor after processing the remaining messages.
GetRequest simply passes the message to the first
NodeActor and pipes the reply back to the sender. This makes the GetRequest a simple proxy for the first node.
SetRequest forwards the message to all
NodeActors and reduces the replies to a single success if they all succeed or a single failure if any of them fail
- Create specs2 unit test
- Create server actor
- have to define message classes (scala is strongly typed)
- initial version only uses server actor (no nodes)