def run (self): ServerUtil.info ("Starting StatsAggregator on %s:%s" % (self.host, self.port)) self.backend.start () self.serverSocket.bind ((self.host, self.port)) self.running = True inputs = [self.serverSocket] try: while len (inputs) > 0 and self.running is True: (reads, writes, errors) = select.select ( inputs, [], inputs ) for i in reads: rdata = i.recvfrom (256) stats = rdata [0].strip ().rstrip ('\0') try: sobject = json.loads (stats) sobject ['host'] = { 'host': rdata [1][0], 'port': rdata [1][1] } ServerUtil.debug ('Recieved [%s] from [%s:%i] for [%s]' \ % (sobject ['type'], sobject ['host']['host'], sobject ['host']['port'], sobject ['name'])) self.consume (sobject) except: ServerUtil.debug ("%s" % traceback.format_exc ()) ServerUtil.debug ("[%s]" % stats) ServerUtil.error ("%s" % sys.exc_info ()[1]) except KeyboardInterrupt: ServerUtil.info ("Caught Keyboard interupt closing") except: ServerUtil.error ("%s" % traceback.format_exc ()) ServerUtil.error ("%s" % sys.exc_info ()[1]) finally: self.serverSocket.close () ServerUtil.info ("Shutting down Backend") self.backend.running = False ServerUtil.info ("Stats Aggregator exited gracefully")