コード例 #1
0
def getHandle():
    #open database
    db.open(dbparams.db_class)
    #create in-memory session manager
    sessionManager.open(inMemorySessionManager.SessionManager, 1200)
    oSystemUser = db.getItem('system')
    currentThread().session = sessionManager.create(oSystemUser)
    currentThread().trans = None
    return db
コード例 #2
0
    def __init__(self):

        self.running = False
        self.sessionManager = None
        self.mgtServer = None
        logger = serverLogging.logger

        self.shutdownEvt = Event()
        self.shutdownThread = Thread(
            target=self.shutdown,
            name='Shutdown thread'
        )
        self.shutdownThread.start()

        try:
            # initialize logging
            serverLogging.initialize_logging()
            
            logger.info('Server starting...')

            # get server parameters
            from porcupine.config import serverSettings

            # get request interfaces
            from porcupine.config import requesttypes
            logger.info('Succesfullly registered %i request interfaces' % \
                len(requesttypes.requestInterfaces))

            # load registrations
            logger.info('Loading store & web apps registrations...')
            from porcupine.config import registrations

            logger.info('Starting management server...')
            from porcupine.config import mgtparams
            Mgt.open(mgtparams.serverAddress, mgtparams.worker_threads)

            # open database
            logger.info('Opening database...')
            from porcupine.config import dbparams
            db.open(dbparams.db_class)

            # create session manager
            logger.info('Creating session manager...')
            from porcupine.config import smparams
            sessionManager.open(smparams.sm_class, smparams.timeout)

            Mgt.mgtServer.mainServer = self
            
            # replication
            if db.db_handle.supports_replication or \
                    sessionManager.sm.supports_replication:
                from porcupine.config import replication

                # check if we have consistent interfaces
                if db.db_handle.supports_replication != \
                        sessionManager.sm.supports_replication:
                    if db.db_handle.supports_replication and \
                            not(sessionManager.sm.supports_replication):
                        sError = 'Database supports replication but the ' + \
                                    'session manager does not.'
                    else:
                        sError = 'Session manager supports replication but ' + \
                                    'the store does not.'
                    raise serverExceptions.ConfigurationError, \
                        'Mismatched interfaces.\n%s' % sError

                Mgt.mgtServer.sync(replication.host_priority, \
                    replication.hostaddr)

            # start server
            logger.info('Starting main service...')
            from porcupine.core import thread
            asyncBaseServer.BaseServer.__init__(self, "Porcupine Server",
                serverSettings.serverAddress, serverSettings.worker_threads,
                thread.PorcupineThread, requestHandler)

        except serverExceptions.ConfigurationError, e:
            logger.error(e.info)
            self.initiateShutdown()
            raise e