Exemplo n.º 1
0
    def _broadcast(self, query, starturl, history):
        """
		broadcast to all other nodes
		"""
        mylogger.info('-' * 10)
        mylogger.info('[broadcast]:')
        mylogger.info("knows: {0}".format(self.known))
        mylogger.info("history: {0}".format(history))
        for other in self.known.copy():
            mylogger.info('[broadcast]: other is {0}'.format(other))
            if other in history:
                continue
            s = ServerProxy(other)
            mylogger.info('[broadcast]: Connecting from {0} to {1}'.format(
                self.url, other))
            mylogger.info('*' * 80)
            try:
                code, data = s.query(query, starturl, history)
                mylogger.info(
                    '[broadcast]: query return code {0}'.format(code))
                if code == SUCCESS:
                    mylogger.info('[broadcast]: query SUCCESS!!!')
                    return code, data
                elif code == NOT_EXIST:
                    mylogger.info('[broadcast]: query NOT_EXIST!!!')
                else:
                    mylogger.info('[broadcast]: query ACCESS_DENIED!!!')
            except Fault, f:  # connected to server,but method does not exist(Never happen in this example)
                mylogger.warn(f)
                mylogger.warn("[broadcast]:except fault")
            except socket.error, e:
                mylogger.warn("[broadcast]:except socket error")
                mylogger.error('[broadcast]: {0} for {1}'.format(e, other))
                # added by kzl
                self.known.remove(other)
Exemplo n.º 2
0
	def _broadcast(self,query,starturl,history):
		"""
		broadcast to all other nodes
		"""
		mylogger.info('-'*10)
		mylogger.info('[broadcast]:')
		mylogger.info("knows: {0}".format(self.known))
		mylogger.info("history: {0}".format(history))
		for other in self.known.copy():
			mylogger.info('[broadcast]: other is {0}'.format(other))
			if other in history:
				continue
			s = ServerProxy(other)
			mylogger.info('[broadcast]: Connecting from {0} to {1}'.format(self.url,other))
			mylogger.info('*'*80)
			try:
				code,data = s.query(query,starturl,history)
				mylogger.info('[broadcast]: query return code {0}'.format(code))
				if code == SUCCESS:
					mylogger.info('[broadcast]: query SUCCESS!!!')
					return code,data
				elif code == NOT_EXIST:
					mylogger.info('[broadcast]: query NOT_EXIST!!!')
				else:
					mylogger.info('[broadcast]: query ACCESS_DENIED!!!')
			except Fault, f: # connected to server,but method does not exist(Never happen in this example)
				mylogger.warn(f)
				mylogger.warn("[broadcast]:except fault")
			except socket.error, e:
				mylogger.warn("[broadcast]:except socket error")
				mylogger.error('[broadcast]: {0} for {1}'.format(e,other))
				# added by kzl
				self.known.remove(other)
Exemplo n.º 3
0
	def offline(self):
		"""
		inform others about myself's status(off)
		"""
		mylogger.info('[offline]')
		for other in self.known.copy():
			if other == self.url:
				continue
			s = ServerProxy(other)
			try:
				# inform other node to remove local node 
				s.remove_node(self.url)
			except Fault,f:
				mylogger.warn(f)
				mylogger.warn('[offline]: {0} started but inform failed'.format(other))
			except socket.error,e:
				mylogger.error('[offline]: {0} for {1}'.format(e,other))
Exemplo n.º 4
0
    def offline(self):
        """
		inform others about myself's status(off)
		"""
        mylogger.info('[offline]')
        for other in self.known.copy():
            if other == self.url:
                continue
            s = ServerProxy(other)
            try:
                # inform other node to remove local node
                s.remove_node(self.url)
            except Fault, f:
                mylogger.warn(f)
                mylogger.warn(
                    '[offline]: {0} started but inform failed'.format(other))
            except socket.error, e:
                mylogger.error('[offline]: {0} for {1}'.format(e, other))
Exemplo n.º 5
0
	def online(self):
		"""
		inform others about myself's status(on)
		"""
		mylogger.info('[online]')
		for other in self.known.copy():
			if other == self.url:
				continue
			s = ServerProxy(other)
			try:
				# inform other node to add local node 
				files = self.get_local_files()
				s.add_node(self.url,files)
			except Fault,f:
				mylogger.warn(f)
				mylogger.warn('[online]: {0} started but inform failed'.format(other))
			except socket.error,e:
				mylogger.error('[online]: {0} for {1}'.format(e,other))
Exemplo n.º 6
0
    def online(self):
        """
		inform others about myself's status(on)
		"""
        mylogger.info('[online]')
        for other in self.known.copy():
            if other == self.url:
                continue
            s = ServerProxy(other)
            try:
                # inform other node to add local node
                files = self.get_local_files()
                s.add_node(self.url, files)
            except Fault, f:
                mylogger.warn(f)
                mylogger.warn(
                    '[online]: {0} started but inform failed'.format(other))
            except socket.error, e:
                mylogger.error('[online]: {0} for {1}'.format(e, other))
Exemplo n.º 7
0
        lt = []
        s = ServerProxy(other)
        try:
            #mylogger.info("[list_other]: call list_local 3")
            # since we connect to other,introduce self.url to other
            # inform other node to add local node
            files = self.get_local_files()
            s.add_node(self.url, files)
            # introduce self.url to other
            lt = s.list_local()
        except Fault, f:
            mylogger.warn(f)
            mylogger.warn(
                '[list_other]: {0} started but list failed'.format(other))
        except socket.error, e:
            mylogger.error('[list_other]: {0} for {1}'.format(e, other))
            #mylogger.warn('[list_other]: {0} not started'.format(other))
        except Exception, e:
            mylogger.warn(e)
            mylogger.warn("[online]: Exception")
        finally:
            return lt

    def update_local_list(self):
        """
		update method
		list all files in local node
		"""
        mylogger.info('[update_local_list]: update local list')
        temp = self.list_local()
        if not list_equal(temp, self.local_files):
Exemplo n.º 8
0
		mylogger.info('[list_other]: list files in {0}'.format(other))
		lt = []
		s = ServerProxy(other)
		try:
			#mylogger.info("[list_other]: call list_local 3")
			# since we connect to other,introduce self.url to other
			# inform other node to add local node 
			files = self.get_local_files()
			s.add_node(self.url,files)
			# introduce self.url to other
			lt = s.list_local()
		except Fault,f:
			mylogger.warn(f)
			mylogger.warn('[list_other]: {0} started but list failed'.format(other))
		except socket.error,e:
			mylogger.error('[list_other]: {0} for {1}'.format(e,other))
			#mylogger.warn('[list_other]: {0} not started'.format(other))
		except Exception, e:
			mylogger.warn(e)
			mylogger.warn("[online]: Exception")
		finally:
			return lt

	def update_local_list(self):
		"""
		update method
		list all files in local node
		"""
		mylogger.info('[update_local_list]: update local list')
		temp = self.list_local()
		if not list_equal(temp,self.local_files):