Created
August 29, 2012 21:39
-
-
Save RayRoestenburg/3519303 to your computer and use it in GitHub Desktop.
Venomous!!!
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
/** | |
* Venomous spiders kill slow Actors... | |
*/ | |
trait Venom extends WebNode[Poisoned, KillSlowActors] { | |
var time = 0L | |
var timeBefore: Long = 0 | |
def now = System.currentTimeMillis() | |
override def sendSpiders(ref: ActorRef, data: Poisoned, msg: (KillSlowActors, Spider), collected: Set[ActorRef]) { | |
super.sendSpiders(ref, data, msg, collected) | |
val (kill, _) = msg | |
// the least you can do is phone home that the actor has been killed. | |
kill.home ! Poisoned(self) | |
self ! PoisonPill | |
} | |
def before: Receive = { | |
case m => timeBefore = now | |
} | |
def after: Receive = { | |
case m => time = now - timeBefore | |
} | |
// Slower than a second and I'll kill ya! | |
def collect(req: KillSlowActors): Option[Poisoned] = if (time > 1000) Some(Poisoned(self)) else None | |
} | |
case class KillSlowActors(time:Long, home:ActorRef) | |
case class Poisoned(actorRef:ActorRef) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment