Skip to content

Instantly share code, notes, and snippets.

@remeniuk
Created November 21, 2010 10:06
Show Gist options
  • Save remeniuk/708616 to your computer and use it in GitHub Desktop.
Save remeniuk/708616 to your computer and use it in GitHub Desktop.
Futures with local actors
class SimpleActor extends Actor {
def receive = {
case message: String =>
log.info("STARTED: %s @ %s" format(message, self.uuid))
Thread.sleep(3000)
self.reply_?("[%s] received %s" format(self.uuid, message))
log.info("FINISHED: %s @ %s" format(message, self.uuid))
}
}
// Starting local actors
for(i <- 1 to 3) Actor.actorOf[SimpleActor].start
// Making futures of calls to actors
ActorRegistry.actorsFor[SimpleActor].foreach(_ !!! "hi")
// Output
[INFO] [2010-11-21 11:58:59,328] [akka:event-driven:dispatcher:global-1] line4$object$$iw$$iw$SimpleActor: STARTE
D: hi @ 1290598341565
[INFO] [2010-11-21 11:58:59,328] [akka:event-driven:dispatcher:global-2] line4$object$$iw$$iw$SimpleActor: STARTED: hi @
1290598341722
[INFO] [2010-11-21 11:58:59,328] [akka:event-driven:dispatcher:global-3] line4$object$$iw$$iw$SimpleActor: STARTED: hi @
1290598341721
[INFO] [2010-11-21 11:59:02,328] [akka:event-driven:dispatcher:global-1] line4$object$$iw$$iw$SimpleActor: FINISHED: hi
@ 1290598341565
[INFO] [2010-11-21 11:59:02,328] [akka:event-driven:dispatcher:global-2] line4$object$$iw$$iw$SimpleActor: FINISHED: hi
@ 1290598341722
[INFO] [2010-11-21 11:59:02,343] [akka:event-driven:dispatcher:global-3] line4$object$$iw$$iw$SimpleActor: FINISHED: hi
@ 1290598341721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment