Created
April 6, 2013 17:56
-
-
Save banshee/5326974 to your computer and use it in GitHub Desktop.
Phantom errors
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
package com.restphone | |
import scala.collection.mutable | |
import akka.actor.Actor | |
import akka.actor.ActorRef | |
import akka.actor.ActorSystem | |
import akka.actor.Props | |
import akka.actor.actorRef2Scala | |
import akka.actor.ActorSystem | |
import com.typesafe.config.ConfigFactory | |
import akka.event.LoggingReceive | |
import akka.actor.{ Actor, ActorRef, FSM } | |
import scala.concurrent.duration._ | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.Future | |
import scala.concurrent.{ ExecutionContext, Promise } | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import java.util.concurrent.atomic.AtomicInteger | |
import akka.pattern.pipe | |
import scala.concurrent.Await | |
import akka.channels._ | |
import akka.actor.{ Actor, ActorSystem } | |
import akka.channels._ | |
import akka.util.Timeout | |
import scala.concurrent.duration._ | |
import scala.concurrent.Await | |
import scalaz._ | |
import Scalaz._ | |
case class Location(x: Int, y: Int) | |
sealed abstract class KittenMessage | |
case class RequestLocation(l: Location) extends KittenMessage | |
case class GrantedLocation(l: Location) extends KittenMessage | |
case class RejectedLocation(l: Location) extends KittenMessage | |
class Kitten extends Actor with Channels[TNil, (KittenMessage, KittenMessage) :+: TNil] { | |
channel[KittenMessage] { (req, snd) => | |
req match { | |
} | |
} | |
def snark(value: Int): Receive = { | |
case x => | |
} | |
def napping(alreadyNappedMilliseconds: Int = 0) : Receive = { | |
case x => | |
} | |
} | |
case class Kitten(startingLocation: Location, uiContext: UiContext) extends Actor { | |
def receive = { | |
case Draw(c) => | |
println(f"draw: $c") | |
val cx = context | |
sender ! "done" | |
} | |
} | |
class ThreadRunnerMessages | |
case class RunInContext(fn: () => Unit)(implicit val foo: Int) extends ThreadRunnerMessages | |
case object Result extends ThreadRunnerMessages | |
class ThreadRunnerResponses | |
case class NewThreadRunner extends Actor { | |
def receive = { | |
case x @ RunInContext(fn) => | |
println(f"got run: $x ${x.foo}") | |
val originalSender = sender | |
class Runner(s: String) extends Thread(s) { | |
override def run = { | |
fn() | |
originalSender ! 'finished | |
} | |
} | |
new Runner("new thread runner").start | |
} | |
} | |
object KittenSimulator extends App { | |
val customConf = ConfigFactory.parseString(""" | |
akka { | |
loglevel = "DEBUG" | |
# log-config-on-start = on | |
actor { | |
debug { | |
# enable DEBUG logging of all AutoReceiveMessages (Kill, PoisonPill and the like) | |
receive = on | |
send = on | |
autoreceive = on | |
lifecycle = on | |
fsm = on | |
} | |
} | |
} | |
""") | |
// ConfigFactory.load sandwiches customConfig between default reference | |
// config and default overrides, and then resolves it. | |
val system = ActorSystem("MySystem", ConfigFactory.load(customConf)) | |
val context = new UiContext() | |
val kittenActor = system.actorOf(Props(Kitten(Location(1, 2), context))) | |
val drawmsg = Draw(context) | |
val contextActor = system.actorOf(Props(new NewThreadRunner())) | |
implicit val fnord: Int = 3 | |
for { | |
r <- (kittenActor ? drawmsg).mapTo[String] | |
_ = contextActor ! RunInContext { | |
() => println("in context!" + Thread.currentThread.getName) | |
} | |
} yield { | |
println(f"r is $r") | |
} | |
system.shutdown | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment