def start_handlers(self, service_id): """ Starts PyroHandler on each host (non-blocking) and returns a Condition lock object and a FIFO queue that is being filled with their Pyro proxies by a separate thread """ #create a list of unique URIs for each host handler_uris = PyroUtils.create_unique_uri(\ string.join(('PyroHandler', service_id),'.'),\ n = self.n_hosts, ns = self.nshost) #create a FIFO queue of infinite capacity handlers = Queue.Queue(-1) #create the condition lock, see effbot.org/zone/thread-synchronization.htm handlers_lock = threading.Condition() hosts_map = {} for i in range(self.n_hosts): #ssh to each host and fork a PyroHandler thread. self._launch_handler(handler_uris[i], self.hosts[i]) hosts_map[handler_uris[i]] = self.hosts[i] ## sleep here is to avoid errors like ## "Warning: No xauth data; using fake ## authentication data for X11 forwarding." #TODO: speedup things by checking if it is necessary time.sleep(self.X11_delay) #fill the queue asynchronously with the handler proxy objects that were launched. t = threading.Thread(target = self._connect_handlers, \ args = (handler_uris, handlers, handlers_lock, hosts_map)) t.start() return handlers, handlers_lock
def start_instances(self, service_id, instance, handlers, handlers_lock): #create n unique URIs for the instance, out of its service_id. instance_uris = PyroUtils.create_unique_uri(\ service_id, n = self.n_hosts, ns = self.nshost) #queue and lock for managing the launched instances of the 'instance' object #via the PyroHandler launched_instances = Queue.Queue(-1) launched_instances_lock = threading.Condition() instances = Queue.Queue(-1) #lock for the self.handlers dict self_handlers_lock = threading.Condition() servers_lock = threading.Condition() #Call PyroHandler.publish(instance) on each host t0 = threading.Thread(target = self._launch_instances, \ args = (instance, instance_uris, handlers, handlers_lock,\ launched_instances, launched_instances_lock, \ self_handlers_lock)) t0.start() #Create a PyroServer instance for each host, and put #them into #self.queues: a dict[service_id of instance #to be published]=Queue(-1) containing the DerivedServers #self.servers: dict[service_id of instance #to be published]=[list of PyroServer instances] t1 = threading.Thread(target = self._connect_instances, \ args = (service_id, \ launched_instances, launched_instances_lock, \ self_handlers_lock, servers_lock)) t1.start() return servers_lock