forked from janm399/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
6 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/addressbook.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,12 @@ | ||
package org.cakesolutions.akkapatterns.core.application | ||
|
||
import akka.actor.Actor | ||
|
||
case class GetAddresses(person: String) | ||
|
||
class AddressBookActor extends Actor { | ||
protected def receive = { | ||
case GetAddresses(person) => | ||
sender ! List(person + "@cakesolutions.net", person + "@gmail.com", person + "@hotmail.com") | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...n/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/messagesender.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,12 @@ | ||
package org.cakesolutions.akkapatterns.core.application | ||
|
||
import akka.actor.Actor | ||
|
||
case class Message(address: String, body: String) | ||
|
||
class MessageSenderActor extends Actor { | ||
protected def receive = { | ||
case Message(address, body) => | ||
// do something | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
maven/core/src/main/scala/org/cakesolutions/akkapatterns/core/application/notification.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.core.application | ||
|
||
import akka.actor.Actor | ||
import akka.pattern.ask | ||
import akka.util.Timeout | ||
|
||
case class Notify(person: String) | ||
|
||
class NotificationActor extends Actor { | ||
implicit val timeout = Timeout(1000) | ||
def messageSender = context.actorFor("/user/application/messageSender") | ||
def addressBook = context.actorFor("/user/application/addressBook") | ||
|
||
protected def receive = { | ||
case Notify(person) => | ||
val addrs = (addressBook ? GetAddresses(person)).mapTo[List[String]] | ||
// do some work to construct the body and then | ||
val body = "Dummy body" | ||
|
||
// notify all | ||
addrs.foreach(_.foreach(messageSender ! Message(_, body))) | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...rc/test/scala/org/cakesolutions/akkapatterns/core/application/NotificationActorSpec.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,21 @@ | ||
package org.cakesolutions.akkapatterns.core.application | ||
|
||
import org.specs2.mutable.Specification | ||
import akka.actor.ActorSystem | ||
import akka.testkit.{TestActorRef, TestKit, ImplicitSender} | ||
|
||
class NotificationActorSpec extends TestKit(ActorSystem()) with Specification with ImplicitSender { | ||
|
||
"x" in { | ||
val n = TestActorRef[NotificationActor] | ||
|
||
val person = "Jan Machacek" | ||
n ! Notify(person) | ||
|
||
// D_expectAndReply(GetAddress(person), List("A")) | ||
// D_expectMsgAllOf(Message("A", "Dummy body")) | ||
|
||
success | ||
} | ||
|
||
} |