def message_local(self, actor_id, message): """Send a message to a local actor. Returns True iff the send was sucessful""" local_actor = self.__actor_store.get_ref(actor_id) if local_actor: local_actor.add_message(message) return (True, None) local_port = self.__actor_store.get_port(actor_id) if local_port: actor_id = ids.change_port(actor_id, local_port) conn = rpc.RPCConnector(ids.loc(actor_id)) remote_theatre = conn.connect() success = remote_theatre.incoming_message(actor_id, message) remote_theatre.disconnect() return(success, actor_id) return (False, None)
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)