Skip to content

Instantly share code, notes, and snippets.

@rkuhn
rkuhn / pipeTo.scala
Created February 16, 2012 11:17
Futures and Resizers
import akka.dispatch.Future
import akka.pattern.pipe
import akka.actor.Actor
case class Work(s: String)
case class Result(s: String)
object MyActor {
// put here to avoid closing over actor’s state
def doWork(work: String): String = {
@rkuhn
rkuhn / typedactordemo.scala
Created March 10, 2012 19:12
TypedActor Demonstration
package typedactordemo
import akka.actor._
import akka.dispatch.Future
import akka.pattern.ask
import akka.util.Timeout
import akka.util.duration._
case class Request(payload: String)
case class Response(payload: String)
@rkuhn
rkuhn / Build.scala
Created April 13, 2012 14:47
Build.scala for merging reference.conf
import sbt._
import Keys._
import classpath.ClasspathUtilities.isArchive
import java.io.FileOutputStream
import sbtassembly.Plugin._
import AssemblyKeys._
object B extends Build {
lazy val merge = TaskKey[File]("merge-reference",
"merge all reference.conf")
@rkuhn
rkuhn / gist:2726426
Created May 18, 2012 17:03 — forked from phaller/gist:2644769
Akka 2.0.1 dependencies for sbt
set resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
set libraryDependencies ++= Seq("com.typesafe.akka" % "akka-actor" % "2.0.1", "com.typesafe.akka" % "akka-remote" % "2.0.1", "com.typesafe.akka" % "akka-testkit" % "2.0.1" % "test", "org.specs2" %% "specs2" % "1.9" % "test", "junit" % "junit" % "4.5" % "test")
@rkuhn
rkuhn / TestKitSampleTest.scala
Created July 4, 2012 15:48
JavaTestKit Sample
/**
* Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
*/
package docs.testkit;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@rkuhn
rkuhn / dsl-demo.scala
Created September 26, 2012 18:47
actor dsl demo
import akka.actor.ActorDSL._
val ref = actor("fred")(new Act {
become {
case "hello" => sender ! "world!"
}
})
implicit val recv = inbox()
ref ! "hello" // uses the `recv` as sender ref
@rkuhn
rkuhn / javatestkit.java
Created November 7, 2012 08:24
JavaTestKit spotlight
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());
@rkuhn
rkuhn / continuation.scala
Created December 6, 2012 19:45
message-based continuation pattern
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 {
@rkuhn
rkuhn / count-repl-session.txt
Created December 9, 2012 20:13
too simple benchmark
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)
@rkuhn
rkuhn / Test.scala
Last active December 10, 2015 22:58
Makkros blog post
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)
}