Ejemplo n.º 1
0
    def handle(self):
        global is_master
        global parser_thread
        global should_continue

        msg = self.request.recv(1024)
        print 'Received a control message: ' + msg
        if 'become_master' in msg:
            status, is_master = recovery.handle_master_request(is_master)
            self.request.send(str(status))
        elif 'is_master' in msg:
            self.request.send(str(is_master))
        elif 'stop_master' in msg:
            is_master = False
        elif 'send_db' in msg:
            thehost = msg.split(';')
            recovery.send_db(thehost[1])
            self.request.send(str('db_sent'))
        elif 'stop_db' in msg:
            should_continue = False
            if parser_thread:
                parser_thread.join()
                parser_thread = None
            self.request.send(str('db_stopped'))
            print 'Stopped DB writes to transfer DB file.'
        elif 'start_db' in msg:
            should_continue = True
            if not parser_thread:
                # Start a thread for parsing
                # Not a daemon because we want it to complete its actions properly
                parser_thread = threading.Thread(target=parse_data_thread)
                parser_thread.start()
            print 'DB writes enabled again.'
Ejemplo n.º 2
0
	def handle(self):
		global is_master
		global parser_thread
		global should_continue
		
		msg = self.request.recv(1024)
		print 'Received a control message: '+msg
		if 'become_master' in msg:
			status,is_master = recovery.handle_master_request(is_master)
			self.request.send(str(status))
		elif 'is_master' in msg:
			self.request.send(str(is_master))
		elif 'stop_master' in msg:
			is_master = False
		elif 'send_db' in msg:
			thehost = msg.split(';')
			recovery.send_db(thehost[1])
			self.request.send(str('db_sent'))
		elif 'stop_db' in msg:
			should_continue = False
			if parser_thread:
				parser_thread.join()
				parser_thread = None
			self.request.send(str('db_stopped'))
			print 'Stopped DB writes to transfer DB file.'
		elif 'start_db' in msg:
			should_continue = True
			if not parser_thread:
				# Start a thread for parsing
				# Not a daemon because we want it to complete its actions properly
				parser_thread = threading.Thread(target=parse_data_thread)
				parser_thread.start()
			print 'DB writes enabled again.'