Ejemplo n.º 1
0
class Master(Singleton):
    """
    BFarm master server
    """

    def initInstance(self):
        """
        Initialize master
        """

        # Set signal handlers
        self.setSignals()

        self.setupLogger()

        # Create servers
        xmlrpc_address = (Config.master['address'], Config.master['port'])
        http_address = (Config.master['http_address'],
                        Config.master['http_port'])

        self.render_server = RenderServer()
        self.xmlrpc_server = XMLRPCServer(xmlrpc_address)
        self.http_server = HTTPServer(http_address)

        # Create ORM mapper
        self.mapper = Mapper(Config.master['database_path'])

        self.unwind(self.mapper)

    def loggerHandler(self, message):
        """
        Handler of new incoming logging message
        """

        self.log_server.logMessage('server', message)

    def setupLogger(self):
        """
        Setup logging infrastructure
        """

        self.log_server = LogServer()
        self.log_server.addSource('server')

        Logger.addLoggerHandler(self.loggerHandler)

    def unwind(self, mapper):
        """
        Unwind all structures stored in database
        """

        self.render_server.unwind(mapper)

    def sigint_handler(self, sig, frame):
        """
        Handler of SIGINT signal
        """

        Logger.log('Caught SIGINT signal, terminating...')

        self.render_server.requestStop()

    def setSignals(self):
        """
        Set signals handlers
        """

        signal.signal(signal.SIGINT,
            lambda sig, frame: self.sigint_handler(sig, frame))

    def run(self):
        """
        Run master logic
        """

        # Start server threads
        self.render_server.start()
        self.xmlrpc_server.start()
        self.http_server.start()

        # Join main render thread
        self.render_server.join()

        # XML and HTTP servers should be stopped
        # after main render server finito
        self.xmlrpc_server.requestStop()
        self.xmlrpc_server.join()

        # Do not join HTTP server due to some clients could
        # still be connected (chrome, i.e. locks handle_request)
        # not sure why this happens, but better use
        # daemon thread for web server

        self.http_server.requestStop()
        #self.http_server.join()

        # Flush all posible changes to database
        self.mapper.flush()

    def getRenderServer(self):
        """
        Get render server instance
        """

        return self.render_server

    def getHTTPServer(self):
        """
        Get render server instance
        """

        return self.http_server

    def getMapper(self):
        """
        Get ORM mapper
        """

        return self.mapper

    def getLogServer(self):
        """
        Get logging server
        """

        return self.log_server
Ejemplo n.º 2
0
class Master(Singleton):
    """
    BFarm master server
    """
    def initInstance(self):
        """
        Initialize master
        """

        # Set signal handlers
        self.setSignals()

        self.setupLogger()

        # Create servers
        xmlrpc_address = (Config.master['address'], Config.master['port'])
        http_address = (Config.master['http_address'],
                        Config.master['http_port'])

        self.render_server = RenderServer()
        self.xmlrpc_server = XMLRPCServer(xmlrpc_address)
        self.http_server = HTTPServer(http_address)

        # Create ORM mapper
        self.mapper = Mapper(Config.master['database_path'])

        self.unwind(self.mapper)

    def loggerHandler(self, message):
        """
        Handler of new incoming logging message
        """

        self.log_server.logMessage('server', message)

    def setupLogger(self):
        """
        Setup logging infrastructure
        """

        self.log_server = LogServer()
        self.log_server.addSource('server')

        Logger.addLoggerHandler(self.loggerHandler)

    def unwind(self, mapper):
        """
        Unwind all structures stored in database
        """

        self.render_server.unwind(mapper)

    def sigint_handler(self, sig, frame):
        """
        Handler of SIGINT signal
        """

        Logger.log('Caught SIGINT signal, terminating...')

        self.render_server.requestStop()

    def setSignals(self):
        """
        Set signals handlers
        """

        signal.signal(signal.SIGINT,
                      lambda sig, frame: self.sigint_handler(sig, frame))

    def run(self):
        """
        Run master logic
        """

        # Start server threads
        self.render_server.start()
        self.xmlrpc_server.start()
        self.http_server.start()

        # Join main render thread
        self.render_server.join()

        # XML and HTTP servers should be stopped
        # after main render server finito
        self.xmlrpc_server.requestStop()
        self.xmlrpc_server.join()

        # Do not join HTTP server due to some clients could
        # still be connected (chrome, i.e. locks handle_request)
        # not sure why this happens, but better use
        # daemon thread for web server

        self.http_server.requestStop()
        #self.http_server.join()

        # Flush all posible changes to database
        self.mapper.flush()

    def getRenderServer(self):
        """
        Get render server instance
        """

        return self.render_server

    def getHTTPServer(self):
        """
        Get render server instance
        """

        return self.http_server

    def getMapper(self):
        """
        Get ORM mapper
        """

        return self.mapper

    def getLogServer(self):
        """
        Get logging server
        """

        return self.log_server