コード例 #1
0
    def makeService(self, options):
        if options['conf']:
            settings.conf = settings.load(options['conf'])

        # we better add 
        reactor.suggestThreadPoolSize(settings.conf['threadpool size'])

        if options['memdebug']:
            from twisted.internet import task
            import objgraph
            import gc
            def stats():
                print gc.collect()
                print
                print '\n'.join(map(str, objgraph.most_common_types(limit=10)))
            task.LoopingCall(stats).start(2)

        cp = adbapi.ConnectionPool(settings.conf['database']['module'],
                                   host=settings.conf['database']['host'],
                                   database=settings.conf['database']['db'],
                                   user=settings.conf['database']['user'],
                                   password=settings.conf['database']['password'],
                                   port=settings.conf['database']['port'],
                                   cp_min=5, cp_max=30,
                                   cp_reconnect=True)

        if options['subscribe']:
            subscribe(cp, settings)


        # create a single republisher to send the data out on
        http_repub = republisher.ReResource(cp)
        websocket_repub = republisher.WebSocketRepublishResource(cp)
        if settings.conf['mongo']['enabled']:
            mongo_repub = republisher.MongoRepublisher(cp)
        else:
            mongo_repub = None

        service = MultiService()
        for svc in settings.conf['server']:
            scfg = settings.conf['server'][svc]
            site = getSite(cp, 
                           resources=scfg['resources'],
                           http_repub=http_repub, 
                           websocket_repub=websocket_repub,
                           mongo_repub=mongo_repub)

            if not len(scfg['ssl']) > 1:
                service.addService(internet.TCPServer(scfg['port'],
                                                      site,
                                                      interface=scfg['interface']))
            else:
                service.addService(internet.SSLServer(scfg['port'],
                                                      site,
                                                      SslServerContextFactory(scfg['ssl']),
                                                      interface=scfg['interface']))

        return service
コード例 #2
0
ファイル: smap_archiver_plugin.py プロジェクト: rraabb/smap
    def makeService(self, options):
        if options['conf']:
            settings.conf = settings.load(options['conf'])

        # we better add
        reactor.suggestThreadPoolSize(settings.conf['threadpool size'])

        if options['memdebug']:
            from twisted.internet import task
            import objgraph
            import gc

            def stats():
                print gc.collect()
                print
                print '\n'.join(map(str, objgraph.most_common_types(limit=10)))

            task.LoopingCall(stats).start(2)

        cp = adbapi.ConnectionPool(
            settings.conf['database']['module'],
            host=settings.conf['database']['host'],
            database=settings.conf['database']['db'],
            user=settings.conf['database']['user'],
            password=settings.conf['database']['password'],
            port=settings.conf['database']['port'],
            cp_min=5,
            cp_max=30,
            cp_reconnect=True)

        if options['subscribe']:
            subscribe(cp, settings)

        # create a single republisher to send the data out on
        http_repub = republisher.ReResource(cp)
        websocket_repub = republisher.WebSocketRepublishResource(cp)
        service = MultiService()
        for svc in settings.conf['server']:
            scfg = settings.conf['server'][svc]
            site = getSite(cp,
                           resources=scfg['resources'],
                           http_repub=http_repub,
                           websocket_repub=websocket_repub)
            if not len(scfg['ssl']) > 1:
                service.addService(
                    internet.TCPServer(scfg['port'],
                                       site,
                                       interface=scfg['interface']))
            else:
                service.addService(
                    internet.SSLServer(scfg['port'],
                                       site,
                                       SslServerContextFactory(scfg['ssl']),
                                       interface=scfg['interface']))

        return service
コード例 #3
0
    def makeService(self, options):
        if options['conf']:
            settings.conf = settings.load(options['conf'])

        # we better add
        reactor.suggestThreadPoolSize(settings.conf['threadpool size'])

        if options['memdebug']:
            from twisted.internet import task
            import objgraph
            import gc

            def stats():
                print gc.collect()
                print
                print '\n'.join(map(str, objgraph.most_common_types(limit=10)))

            task.LoopingCall(stats).start(2)

        def connection_callback(conn):
            # switch client charset to utf8 and enable hstore
            conn.set_client_encoding("UTF8")
            psycopg2.extras.register_hstore(conn)

        cp = adbapi.ConnectionPool(
            settings.conf['database']['module'],
            host=settings.conf['database']['host'],
            database=settings.conf['database']['db'],
            user=settings.conf['database']['user'],
            password=settings.conf['database']['password'],
            port=settings.conf['database']['port'],
            cp_min=5,
            cp_max=30,
            cp_reconnect=True,
            cp_openfun=connection_callback)

        if options['subscribe']:
            subscribe(cp, settings)

        # create a single republisher to send the data out on
        http_repub = republisher.ReResource(cp)
        websocket_repub = republisher.WebSocketRepublishResource(cp)
        if settings.conf['mongo']['enabled']:
            mongo_repub = republisher.MongoRepublisher(cp)
        else:
            mongo_repub = None

        if settings.conf['database']['republish']:
            print "enabling pg republishing"
            pg_repub = republisher.PostgresEndpoint(cp)
        else:
            pg_repub = None

        service = MultiService()
        for svc in settings.conf['server']:
            scfg = settings.conf['server'][svc]
            site = getSite(cp,
                           resources=scfg['resources'],
                           http_repub=http_repub,
                           websocket_repub=websocket_repub,
                           mongo_repub=mongo_repub,
                           pg_repub=pg_repub)

            if not len(scfg['ssl']) > 1:
                service.addService(
                    internet.TCPServer(scfg['port'],
                                       site,
                                       interface=scfg['interface']))
            else:
                service.addService(
                    internet.SSLServer(scfg['port'],
                                       site,
                                       SslServerContextFactory(scfg['ssl']),
                                       interface=scfg['interface']))

        return service