This file contains hidden or 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
| import akka.actor.{ActorSystem, ActorRef, Props, Actor} | |
| import com.typesafe.config.{Config, ConfigFactory} | |
| class Echo extends Actor { | |
| def receive = { | |
| case m => | |
| println("%s: %s".format(m, sender.path)) | |
| sender ! m | |
| } | |
| } |
This file contains hidden or 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
| trait SomeTrait { | |
| case class X(s: String) | |
| def getThings: Set[X] | |
| } | |
| object SomeTraitStub { | |
| var things = Set.empty[SomeTrait#X] | |
| } | |
| trait SomeTraitStub extends SomeTrait { |
This file contains hidden or 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
| import shapeless._ | |
| import HList._ | |
| import Record._ | |
| object Shapeless { | |
| type MyFunction = PartialFunction[Any, String] | |
| object behaviourA extends Field[MyFunction] { override def toString = "BehaviourA" } | |
| object behaviourB extends Field[MyFunction] { override def toString = "BehaviourB" } |
This file contains hidden or 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
| trait ReceiveComposiingActor extends Actor { | |
| trait Key | |
| lazy val receivePartials = scala.collection.mutable.Map.empty[Key, Receive] | |
| // Fronts 'context.become' to alter map before recomposition | |
| def becomeNew(key: Key, behaviour: Receive) { | |
| receivePartials += (key -> behaviour) | |
| context.become(composeReceive) | |
| } |
This file contains hidden or 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
| import akka.actor.{Actor, ActorRef, ActorSystem, Props} | |
| import akka.dispatch._ | |
| import akka.dispatch.Future.flow | |
| import akka.pattern.ask | |
| import akka.util.duration._ | |
| import akka.util.Timeout | |
| import akka.util.Timeout._ | |
| case object Ping |
This file contains hidden or 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
| def tryActorFor(path: String)(implicit ctx: ActorContext): Option[ActorRef] = ctx.actorFor(path) match { | |
| case a if a.isTerminated => None | |
| case a => Some(a) | |
| } | |
| def tryAncestorActorFor(name: String)(implicit ctx: ActorContext, me: ActorRef): Option[ActorRef] = { | |
| def helper(revPath: Seq[String]): Option[ActorRef] = revPath match { | |
| case Seq() => None | |
| case Seq(`name`, _*) => Some(ctx.actorFor("/" + revPath.reverse.mkString("/"))) | |
| case _ => helper(revPath.tail) | |
| } |
This file contains hidden or 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
| trait SyncStopper { this: TestKit => | |
| def syncActorStop(name: String) { | |
| val a = system.actorFor(name) | |
| watch(a) | |
| system.stop(a) | |
| expectMsg(akka.actor.Terminated(a)) | |
| unwatch(a) | |
| } | |
| } |
This file contains hidden or 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
| // Examples showing how to use the specification helpers | |
| // | |
| import akka.actor.ActorSystem | |
| import akka.testkit.{TestKit, ImplicitSender} | |
| import org.scalatest.{WordSpec, BeforeAndAfterAll} | |
| import org.scalatest.matchers.MustMatchers | |
| // Sequentially runs the tests, isolating the Fixture in each test. The Fixture carries the TestKit | |
| // so each test gets its own ActorSystem | |
| class MyAkkaTestSpec extends SequentialAkkaSpecWithIsolatedFixture { |
This file contains hidden or 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
| import akka.actor.ActorSystem | |
| import akka.util.duration._ | |
| import akka.util.Timeout | |
| import akka.agent.Agent | |
| import scala.concurrent.stm._ | |
| object Main { | |
| implicit val sys = ActorSystem() | |
| implicit val awaitTimeout = Timeout(5 seconds) |
This file contains hidden or 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
| object MasterWorkerProtocol { | |
| // Messages from Workers | |
| case class WorkerCreated(worker: ActorRef) | |
| case class WorkerRequestsWork(worker: ActorRef) | |
| case class WorkIsDone(worker: ActorRef) | |
| // Messages to Workers | |
| case class WorkToBeDone(work: Any) | |
| case object WorkIsReady | |
| case object NoWorkToBeDone |