Skip to content

Instantly share code, notes, and snippets.

@RayRoestenburg
Created August 29, 2012 21:39
Show Gist options
  • Save RayRoestenburg/3519303 to your computer and use it in GitHub Desktop.
Save RayRoestenburg/3519303 to your computer and use it in GitHub Desktop.
Venomous!!!
/**
* 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