def startHttpServer(self): """ Starts an HTTP server that listens to incoming remote messages. The method will refuse to create a server if there is already one """ if not self.httpServer: self.mylogger.info("Starting HttpServer") self.httpServer = HttpServer(self.httpTree, self.myconfig) self.httpServer.start() else: messg = "Refusing to start HTTP server (there is already one)." self.mylogger.info(messg)
class TQListener(object): """ _TQListener_ """ def __init__(self, config): """ Constructor. Requires a WMCore.Configuration object with configuration information. """ self.myconfig = config # Logging myThread = threading.currentThread() # self._setLogging() self.mylogger = myThread.logger self.mylogger.info("\n\n>>>>>TQListener object being created <<<<<<\n") sections = self.myconfig.listSections_() if not "TQListener" in sections: messg = "Cannot create TQListener object without " messg += "TQListener section in config file" raise Exception(messg) self.user = None self.passwd = None self.handlerMap = {} self.handlerLock = threading.Lock() self.factory = WMFactory('TQListener'); # Get a reference to our invoking component's DB factory self.dbFactory = myThread.dbFactory self.dialect = myThread.dialect # Formatter for responses (change only if in synchronous mode) formatter = listenerFormatter # formatter = "TQComp.DefaultFormatter" if hasattr(self.myconfig.TQListener, "formatter"): formatter = self.myconfig.TQListener.formatter formatterObj = self.factory.loadObject(formatter) params = { "handlerMap": self.handlerMap, "formatter": formatterObj, "dbFactory": self.dbFactory, "dialect": self.dialect, "sandboxBasePath": self.myconfig.TQComp.sandboxBasePath, "specBasePath": self.myconfig.TQComp.specBasePath, "reportBasePath": self.myconfig.TQComp.reportBasePath, "pilotErrorLogPath": self.myconfig.TQComp.pilotErrorLogPath } self.httpTree = HttpTree(params) self.httpServer = None def __del__(self): # Tell cherrypy to die self.mylogger.info("Asking httpServer to die") if self.httpServer: self.httpServer.terminate() self.httpServer.join() def startHttpServer(self): """ Starts an HTTP server that listens to incoming remote messages. The method will refuse to create a server if there is already one """ if not self.httpServer: self.mylogger.info("Starting HttpServer") self.httpServer = HttpServer(self.httpTree, self.myconfig) self.httpServer.start() else: messg = "Refusing to start HTTP server (there is already one)." self.mylogger.info(messg) def setAuthentication(self, user, passwd): """ Sets the user/password for authentication with the remote application. Has to be done before sending a message. """ self.mylogger.debug("Setting user and passwd") self.user = user self.passwd = passwd def setHandler(self, msgType, handler, params): """ Maps the specified handler to the indicated message type. The handler must be the name of a class which can be called (e.g. RemoteMsg.SimpleHandler). The params argument can be used as a dict for any parameter (if needed); it will be passed to the constructor of the handler. """ messg = "Setting new handler %s for msgType %s" % (handler, msgType) self.mylogger.debug(messg) # Factory to dynamically load handlers newHandler = self.factory.loadObject(handler, params) self.handlerLock.acquire() self.handlerMap[msgType] = newHandler self.handlerLock.release()