def add_message(self, message): """Entry point for external (message) interaction with an actor and is thread safe.""" self.ready.acquire() while not self.state: self.ready.wait() self.ready.release() log.debug(self.state, "received message - %s" % message) self.state.messages.add(message)
def __process_request(self, request): log.debug(self, "processing: " + str(request)) method = self.__actor.state.get_method(request.name) try: result = self.__callmethod(method, request.args, request.kwds) except Exception: return if request.origin: reply = ResponseMessage(request.id, result) self.__actor.theatre.send(request.origin, reply)
def sendmessage(self, to, name, args, kwds): # Generate a new unique ID for the message id = self.state.messages.new_request() message = RequestMessage(id, name, args, kwds) # Add ourselfves as the origin such that we are # notified when the message has been processed message.add_origin(self.state.actor_id) # Attempt to send the message (success, new_actor_id) = self.theatre.send(to, message) if not success: log.debug(self, "cannot find actor with id %s" % to) self.state.joinactor('actorlost', [Reference(to), message]) return (Result(self, id), new_actor_id)
def incoming_actor(self, actorstate): # Create actor but don't start # TODO: FIX- generation of id, handle local and non-local migrations. log.debug(self, 'receieved migrating actor %s' % actorstate) actor = Actor(local_theatre()) actor.state = actorstate old_actor_id = actor.state.actor_id type = actor.state.actortype if ids.ip(old_actor_id) == ids.ip_from_loc(self.here): # Migration has been local actor_id = ids.change_port(old_actor_id, ids.port_from_loc(self.here)) else: actor_id = ids.change_host(old_actor_id, self.here, self.shared_data.next_id_num()) actor.state.actor_id = actor_id self.__local_actor_store.add_network_actor(actor, actor_id) actor.start() # At the moment even core migrations trigger re-registrations # Could probably forgo these if core migrations are frequent. local_theatre().globally_reregister_network_actor(actor_id, type, old_actor_id) names = actor.state.names for name in names: local_theatre().name(name, actor_id)
def migrate_to(self, actor, address): print 'in migrator' log.debug(self, 'about to migrate %s to %s' % (actor, address)) if address == local_theatre().gethostname(): # Still add an arrive message since the actor requested a local # migration and may be relying the arrived notification actor.state.add_arrived() log.debug(self, 'pointless (local) migration') return True # Inform the local locator that the actor cannot service any # further requests on this host self.__local_actor_store.remove(actor.state.actor_id) # try: self.__migrate_remote(actor, address) # except: # return False # Stop the actor's process loop actor.stop() log.debug(self, 'stopped local runner for actor %s' % actor) return True