def run(self): """run() -> void Handles the communication events and errors with a client. """ CommandHandler._registerThread(CommandHandler, self) sock = self.sock sock.settimeout(self.timeout) try: while True: data = common.recvEnd(sock, '\n') # Connection closed if not data: break data = data.strip() if helper.isCmdQuit(data): # QUIT break elif helper.isCmdList(data): # LIST self._sendMonitorsList() elif helper.isCmdGetAll(data): # GET ALL self._sendGetAll() elif helper.isCmdUpdateAll(data): # UPDATE ALL self._sendUpdateAll() else: cmd, sep, body = data.partition(' ') body = body.strip() if helper.isCmdGet(cmd): # GET self._handleGet(body) elif helper.isCmdUpdate(cmd): # UPDATE self._handleUpdate(body) else: logging.info("Unknown command from %s:%d" % self.addr) self.sock.sendall( helper.getUnknownCmdError( "Unknown command: %s" % data) ) except socket.timeout: logging.debug("Socket TIMEOUT %s:%d" % self.addr) sock.sendall( helper.getTimeoutError( "Reached timeout of %.1f seconds" % self.timeout) ) except IOError: logging.warning("Error sending data to %s:%d" % self.addr) finally: sock.close() logging.debug("Command handler closed socket to %s:%s" % self.addr) CommandHandler._unregisterThread(CommandHandler, self)
def run(self): """run() -> void Handles the communication events and errors with a client. """ CommandHandler._registerThread(CommandHandler, self) sock = self.sock sock.settimeout(self.timeout) try: while True: data = common.recvEnd(sock, '\n') # Connection closed if not data: break data = data.strip() if helper.isCmdQuit(data): # QUIT break elif helper.isCmdList(data): # LIST self._sendMonitorsList() elif helper.isCmdGetAll(data): # GET ALL self._sendGetAll() elif helper.isCmdUpdateAll(data): # UPDATE ALL self._sendUpdateAll() else: cmd, sep, body = data.partition(' ') body = body.strip() if helper.isCmdGet(cmd): # GET self._handleGet(body) elif helper.isCmdUpdate(cmd): # UPDATE self._handleUpdate(body) else: logging.info("Unknown command from %s:%d" % self.addr) self.sock.sendall( helper.getUnknownCmdError("Unknown command: %s" % data)) except socket.timeout: logging.debug("Socket TIMEOUT %s:%d" % self.addr) sock.sendall( helper.getTimeoutError("Reached timeout of %.1f seconds" % self.timeout)) except IOError: logging.warning("Error sending data to %s:%d" % self.addr) finally: sock.close() logging.debug("Command handler closed socket to %s:%s" % self.addr) CommandHandler._unregisterThread(CommandHandler, self)
def run(self): """run() -> void Handles the communication events and errors with a resource monitor. """ MonitorHandler._registerThread(MonitorHandler, self) sock = self.sock sock.settimeout(self.timeout) try: data = common.recvEnd(sock, gdata.ETX) if data: logging.debug("%s:%d Data:\n%s" % (self.addr[0], self.addr[1], data)) head, sep, body = data.partition(' ') head = head.strip() body = body.strip() if helper.isBEL(head): # New monitor self._newMonitor(body) elif helper.isSOH(head): # Monitor data update self._updateMonitor(body) else: # Unknown data logging.info("Unknown monitor message '%s' from %s:%d" % (data, self.addr[0], self.addr[1])) sock.sendall(helper.getBadMessageError("Wrong message")) except socket.timeout: logging.debug("Socket TIMEOUT %s:%d" % self.addr) sock.sendall( helper.getTimeoutError("Reached timeout of %.1f seconds" % self.timeout)) except AttributeError, e: sock.sendall(helper.getGenericError(str(e)))
def run(self): """run() -> void Handles the communication events and errors with a resource monitor. """ MonitorHandler._registerThread(MonitorHandler, self) sock = self.sock sock.settimeout( self.timeout ) try: data = common.recvEnd(sock, gdata.ETX) if data: logging.debug("%s:%d Data:\n%s" % (self.addr[0], self.addr[1], data)) head, sep, body = data.partition(' ') head = head.strip() body = body.strip() if helper.isBEL(head): # New monitor self._newMonitor(body) elif helper.isSOH(head): # Monitor data update self._updateMonitor(body) else: # Unknown data logging.info("Unknown monitor message '%s' from %s:%d" % (data, self.addr[0], self.addr[1]) ) sock.sendall( helper.getBadMessageError("Wrong message") ) except socket.timeout: logging.debug("Socket TIMEOUT %s:%d" % self.addr) sock.sendall( helper.getTimeoutError( "Reached timeout of %.1f seconds" % self.timeout) ) except AttributeError, e: sock.sendall( helper.getGenericError(str(e)) )