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
package demo | |
class TopLevel extends Actor { | |
val db = context.actorOf(Props[Database]) | |
context.watch(db) | |
val web = context.actorOf(Props[WebServer]) | |
web ! Start(database = db) | |
override val supervisorStrategy = OneForOneStrategy() { |
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
var isDownloading = false | |
// set up a scheduler to sync the registry | |
system.scheduler.schedule(0 millis, 3 hours) { | |
if(!isDownloading) { | |
system.actorOf(Props[Downloader]) ! Download | |
} | |
} | |
/* |
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
private static SupervisorStrategy strategy = | |
new OneForOneStrategy(10, Duration.create("1 minute"), | |
new Function<Throwable, Directive>() { | |
@Override | |
public Directive apply(Throwable t) { | |
if (t instanceof ArithmeticException) { | |
return resume(); | |
} else if (t instanceof NullPointerException) { | |
log.warning("restarting misbehaving child"); | |
return restart(); |
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
final ActorRef child = getContext().actorOf(new Props( | |
new UntypedActorFactory() { | |
@Override public UntypedActor create() { | |
// getSender() will not yield what you think it should | |
return new OtherActor(getSender()); | |
} | |
})) |
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
/** | |
* Copyright (C) 2013 Typesafe Inc. <http://www.typesafe.com> | |
*/ | |
package docs.channels | |
import akka.actor.{ Actor, ActorSystem } | |
import akka.channels._ | |
import akka.util.Timeout | |
import scala.concurrent.duration._ |
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
/** | |
* Copyright (C) 2013 Typesafe Inc. <http://www.typesafe.com> | |
*/ | |
package akka.util | |
import java.util.concurrent.atomic.AtomicReferenceArray | |
import scala.annotation.tailrec | |
import scala.concurrent.ExecutionContext |
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
def eval(code: String, compileOptions: String = | |
"-cp akka-actor/target/classes:akka-macros/target/classes"): Any = { | |
val tb = mkToolbox(compileOptions) | |
tb.eval(tb.parse(code)) | |
} | |
def mkToolbox(compileOptions: String = ""): ToolBox[_ <: Universe] = { | |
val m = scala.reflect.runtime.currentMirror | |
m.mkToolBox(options = compileOptions) | |
} |
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
Welcome to Scala version 2.10.0-RC5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> system=ActorSystem("repl",ConfigFactory.parseString("pinned{type=PinnedDispatcher;executor=thread-pool-executor}").withFallback(config)) | |
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] logger log1-Logging$DefaultLogger started | |
[DEBUG] [12/09/2012 21:23:23.535] [run-main] [EventStream(akka://repl)] Default Loggers started | |
system: akka.actor.ActorSystem = akka://repl | |
scala> case class Add(x: Int) |
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
import akka.actor.ActorDSL._ | |
case object Work | |
case object StopIt | |
implicit val system = akka.actor.ActorSystem() | |
actor(new Act { | |
case class ToDo(items: Int, client: ActorRef, v: Double) | |
become { |
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
new JavaTestKit(system) {{ | |
final Props props = new Props(SomeActor.class); | |
final ActorRef subject = system.actorOf(props); | |
subject.tell("request", getRef()); | |
expectMsgEquals(duration("1 second"), "response"); | |
new Within(duration("3 seconds")) { | |
protected void run() { | |
subject.tell("hello", getRef()); |