Created
February 26, 2011 02:26
-
-
Save laclefyoshi/844869 to your computer and use it in GitHub Desktop.
Jython and Akka
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
#!/usr/bin/jython | |
# -*- coding: utf-8 -*- | |
# Copyright : (c) SAEKI Yoshiyasu | |
# License : MIT-style license | |
# <http://www.opensource.org/licenses/mit-license.php> | |
# last updated: 2011/02/26 | |
from akka.actor import Actors, UntypedActor | |
class MyActor(UntypedActor): | |
def onReceive(self, message): | |
print "From client> " + message | |
for i in range(10): | |
print self, i | |
def preStart(self): | |
print "Starting actor..." | |
def postStop(self): | |
print "Stopping actor..." | |
## create ActorRef object | |
ar1 = Actors.actorOf(MyActor) | |
ar2 = Actors.actorOf(MyActor) | |
## set dispatcher | |
# from akka.dispatch import Dispatchers | |
# ar1.setDispatcher(Dispatchers.newThreadBasedDispatcher(ar1)) | |
## start actor: call preStart | |
ar1.start() | |
ar2.start() | |
## send message to actor: call onReceive(message) | |
ar1.sendOneWay("ar1") | |
ar2.sendOneWay("ar2") | |
## stop actor: call postStop | |
ar1.stop() | |
ar2.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment