Created
November 21, 2010 10:11
-
-
Save remeniuk/708619 to your computer and use it in GitHub Desktop.
Futures with remote actors
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
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 remote actors | |
RemoteNode.start | |
for(i <- 1 to 3) RemoteNode.register("sa" + i, Actor.actorOf[SimpleActor]) | |
// Making futures of calls to remote actors | |
(1 to 3).map(i => RemoteClient.actorFor("sa" + i, "localhost", 9999) !!! "hi") | |
// Output at remote node | |
[INFO] [2010-11-21 12:11:46,218] [akka:event-driven:dispatcher:global-1] line4$object$$iw$$iw$SimpleActor: STARTE | |
D: hi @ 1290599082315 | |
[INFO] [2010-11-21 12:11:49,234] [akka:event-driven:dispatcher:global-1] line4$object$$iw$$iw$SimpleActor: FINISHED: hi | |
@ 1290599082315 | |
[INFO] [2010-11-21 12:11:49,265] [akka:event-driven:dispatcher:global-2] line4$object$$iw$$iw$SimpleActor: STARTED: hi @ | |
1290599082471 | |
[INFO] [2010-11-21 12:11:52,265] [akka:event-driven:dispatcher:global-2] line4$object$$iw$$iw$SimpleActor: FINISHED: hi | |
@ 1290599082471 | |
[INFO] [2010-11-21 12:11:52,265] [akka:event-driven:dispatcher:global-3] line4$object$$iw$$iw$SimpleActor: STARTED: hi @ | |
1290599082472 | |
[INFO] [2010-11-21 12:11:55,281] [akka:event-driven:dispatcher:global-3] line4$object$$iw$$iw$SimpleActor: FINISHED: hi | |
@ 1290599082472 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment