示例#1
0
    def _connect_instances(self, service_id, \
                           launched_instances, launched_instances_lock, \
                           self_handlers_lock, servers_lock):

        ## connect to instances sequentially

        _ns = PyroUtils.get_nameserver(self.nshost)

        for i in range(self.n_hosts):

            launched_instances_lock.acquire()
            if launched_instances.empty(): launched_instances_lock.wait()
            instance_uri = launched_instances.get()
            launched_instances_lock.release()

            try:
                instance_proxy = PyroUtils.get_proxy(instance_uri, ns = _ns)
            except:
                print 'PyroGrid._connect_instances: failed to connect to "%s"' % instance_uri
                raise

            if self.debug:
                print 'PyroGrid._connect_instances: instance "%s" on "%s" is ready' \
                      % (instance_uri, instance_proxy._pyro_suppl['host'])

            self._append_instance(service_id, instance_proxy, \
                                  self_handlers_lock, servers_lock)

        self.__published[service_id] = True
示例#2
0
    def _connect_handlers(self, handler_uris, handlers, handlers_lock, hosts_map):

        #handlers: a FIFO queue,
        #handlers_lock: a Condition lock
        #handler (see below): the PyroHandler proxy

        ## connect to handlers sequentially

        _ns = PyroUtils.get_nameserver(self.nshost)

        for i in range(self.n_hosts):
            try:
                handler = PyroUtils.get_proxy(handler_uris[i], ns = _ns)
            except:
                print 'PyroGrid._connect_handlers: failed to connect to "%s"' % handler_uris[i]
                raise

            #tell the pyro proxy to close the socket for now.
            handler._release()
            #tell the handler on which host he's running.
            handler.host = hosts_map[handler_uris[i]]

            if self.debug:
                print 'PyroGrid._connect_handlers: handler "%s" on "%s" is ready' \
                      % (handler_uris[i], handler._pyro_suppl['host'])

            #acquire the lock
            handlers_lock.acquire()
            #put the handler proxy object into the queue
            handlers.put(handler)

            if self.debug:
                print 'PyroGrid._connect_handlers: notifies "%s" is in the queue' % handler_uris[i]
            #update queue status and release lock
            handlers_lock.notify()
            handlers_lock.release()