diff options
author | Paul Phillips <paulp@improving.org> | 2011-12-05 10:05:01 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-05 10:05:01 -0800 |
commit | 09ba583b1e08b96d9b1d703a1c0c6bdaa55ae7f7 (patch) | |
tree | fc8661a15dc929c43a815445507a35e05f266185 /test/disabled/presentation/akka/src/akka/routing/Listeners.scala | |
parent | 8b1e0225fdde17be06d064dece1f1851bd5bde03 (diff) | |
download | scala-09ba583b1e08b96d9b1d703a1c0c6bdaa55ae7f7.tar.gz scala-09ba583b1e08b96d9b1d703a1c0c6bdaa55ae7f7.tar.bz2 scala-09ba583b1e08b96d9b1d703a1c0c6bdaa55ae7f7.zip |
Disabled non-deterministic tests.
Everyone's favorite "will they or won't they" tests, akka and timeofday.
They will be welcomed back into the fold once they can stick to a
decision on whether to pass or fail.
Diffstat (limited to 'test/disabled/presentation/akka/src/akka/routing/Listeners.scala')
-rw-r--r-- | test/disabled/presentation/akka/src/akka/routing/Listeners.scala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/disabled/presentation/akka/src/akka/routing/Listeners.scala b/test/disabled/presentation/akka/src/akka/routing/Listeners.scala new file mode 100644 index 0000000000..04f6c1259f --- /dev/null +++ b/test/disabled/presentation/akka/src/akka/routing/Listeners.scala @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> + */ + +package akka.routing + +import akka.actor.{ Actor, ActorRef } +import java.util.concurrent.ConcurrentSkipListSet +import scala.collection.JavaConversions._ + +sealed trait ListenerMessage +case class Listen(listener: ActorRef) extends ListenerMessage +case class Deafen(listener: ActorRef) extends ListenerMessage +case class WithListeners(f: (ActorRef) => Unit) extends ListenerMessage + +/** + * Listeners is a generic trait to implement listening capability on an Actor. + * <p/> + * Use the <code>gossip(msg)</code> method to have it sent to the listeners. + * <p/> + * Send <code>Listen(self)</code> to start listening. + * <p/> + * Send <code>Deafen(self)</code> to stop listening. + * <p/> + * Send <code>WithListeners(fun)</code> to traverse the current listeners. + */ +trait Listeners { self: Actor => + private val listeners = new ConcurrentSkipListSet[ActorRef] + + protected def listenerManagement: Receive = { + case Listen(l) => listeners add l + case Deafen(l) => listeners remove l + case WithListeners(f) => listeners foreach f + } + + protected def gossip(msg: Any) = listeners foreach (_ ! msg) +} |