Beispiel #1
0
    def __init__(self, dsp_endpoints, event_endpoint, balance_conn_timeout):
        '''
            Constructor
            dsp_endpoints : is a list of tuples(endpoint, qps) where
                enpoint is a string like '192.168.10.152:5869'
                and qps is the value indicating queries per
                second for that enpoint.
            balance_conn_timeout : is the time period for rebalancing
                available connections.
        '''
        # list containing tuples in the form
        # (endpoint, expected qps, current qps)
        self.dest_eps = [[ep[0], ep[1], 0] for ep in dsp_endpoints]
        self.event_endpoint = event_endpoint
        self.conns = {}
        self.awaiting_conns = {}
        self.event_conn_queue = []
        self.event_conns = {}
        self.event_connections = 0
        self.keep_alive_resp_waiting = {}
        self.balance_conn_to = balance_conn_timeout
        self.loop = pyev.default_loop()
        self.watchers = [
            pyev.Signal(sig, self.loop, self.signal_cb) for sig in STOPSIGNALS
        ]

        self.watchers.append(
            pyev.Timer(self.balance_conn_to, self.balance_conn_to, self.loop,
                       self.balance))

        self.watchers.append(
            pyev.Timer(CHECK_CONNS_TO, CHECK_CONNS_TO, self.loop,
                       self.check_established_connections))

        self.watchers.append(
            pyev.Timer(CHECK_PENDING_TO, CHECK_PENDING_TO, self.loop,
                       self.check_pending_wins))

        if EVENT_CONN_KEEP_ALIVE_TO:
            self.watchers.append(
                pyev.Timer(EVENT_CONN_KEEP_ALIVE_TO, EVENT_CONN_KEEP_ALIVE_TO,
                           self.loop, self.send_keep_alives))

        self.current_connections = 0
        self.request_fact = RTBRequestFactory(TEMPLATE_FILENAME)
        self.adserver = AdServer(self.loop)
        self.request_fact.initialize()
        self.request_fact.set_parameter_plug(PARAMETER_PLUGIN, self.adserver)
        if PLUGIN_DO_TO:
            self.watchers.append(
                pyev.Timer(PLUGIN_DO_TO, PLUGIN_DO_TO, self.loop,
                           self.request_fact.plugin_instance.do))
        self.pending_wins = []