don...@bigass.local  committed b4666f8

isolate actors from each other by copying messages as they are sent.

  • Participants
  • Parent commits 4b2f094

Comments (0)

Files changed (2)

File pyact/

 import uuid
 import weakref
+import simplejson
 from eventlet import api
 from eventlet import coros
     return spawnable.address
+def handle_address(obj):
+    if isinstance(obj, Address):
+        return {'address': obj.actor_id}
+    raise TypeError(obj)
+def generate_address(obj):
+    if obj.keys() == ['address']:
+        return Actor.all_actors[obj['address']].address
+    return obj
 class Address(object):
     """An Address is a reference to another Actor.  Any Actor which has an
         ## TODO: Copy message or come up with some way of "freezing" message
         ## so that actors do not share mutable state.
-        self._actor._cast(message)
+        self._actor._cast(simplejson.dumps(message, default=handle_address))
     def call(self, method, message, timeout=None):
         """Send a message to the Actor this object addresses.
         message_id = str(uuid.uuid1())
         my_address = api.getcurrent().address
-            {'call': message_id, 'method': method, 'address': my_address, 'message': message})
+            simplejson.dumps(
+                {'call': message_id, 'method': method,
+                'address': my_address, 'message': message},
+            default=handle_address))
         if timeout is None:
             cancel = None
         Address uses this to insert a message into this Actor's mailbox.
-        self._mailbox.append(message)
+        self._mailbox.append(simplejson.loads(message, object_hook=generate_address))
         if self._waiting:
             api.call_after_global(0, self.switch)

File pyact/

                 return "Not Found\n"
                 body = env['wsgi.input'].read(int(env['CONTENT_LENGTH']))
-                msg = simplejson.loads(body)
+                local_address = 'http://%s/' % (env['HTTP_HOST'], )
+                def generate_address(obj):
+                    if obj.keys() == ['address'] and obj['address'].startswith(local_address):
+                        return actors.generate_address({'address': obj['address'][len(local_address):]})
+                    return obj
+                msg = simplejson.loads(body, generate_address)
             except Exception, e:
                 start_response('406 Not Acceptable', [('Content-type', 'text/plain')])