Esempio n. 1
0
 def _init_callback_handler(self):
     self.handlers = PeerCallbackHandlers(self._get_name(),
                                            self._cache_config.get_report_interval())
     self.handlers.register_handler(PeerReporter(self._get_name()))
     self.handlers.register_handler(CacheActiveDownloadTracker())
     
     if self._cache_config.get_sis_url() is not None:
         ip_addr = net_utils.get_own_ip_addr()
         iop_url = self._cache_config.get_sis_iop_url()
         self.handlers.register_handler(PeerActivityReportEmitter(
                 (ip_addr, self._cache_config.get_port()),
                 self._cache_config.get_report_interval(),
                 sis_iop_endpoint_url=iop_url))
     
     if self._cache_config.get_report_to() is not None:
         if self._cache_config.get_report_to() == 'local_report':
             global local_reporter
             local_reporter = PeerLocalReporter(self._get_name(), self._cache_config.get_id(),
                                            self.session, self._cache_config.get_directory())
             self.handlers.register_handler(local_reporter)
         else:
             self.handlers.register_handler(PeerHTTPReporter(self._get_name(),
                                                               self._cache_config.get_id(),
                                                               self._cache_config.get_report_to(),
                                                               self.sconfig,
                                                               self._cache_config.get_compress_xml_reports(),
                                                               self._cache_config.get_serialization_method(),
                                                               is_iop=True))
Esempio n. 2
0
        def setup_callback_handlers(session, scfg):
            self._handlers = PeerCallbackHandlers(
                self._get_name(), self._config.get_report_interval())
            self._handlers.register_handler(PeerReporter(self._get_name()))
            self._handlers.register_handler(
                ClientStatistics(self._config.get_directory(),
                                 self._config.get_id()))

            if self._config.is_hap_enabled():
                self._logger.info("HAP support enabled")
                self._handlers.register_handler(ClientHAPHandler(self._config))

            if self._config.get_sis_url() != None:
                ip_addr = net_utils.get_own_ip_addr()
                self._handlers.register_handler(
                    PeerActivityReportEmitter(
                        (ip_addr, self._config.get_port()),
                        self._config.get_activity_report_interval(),
                        sis_iop_endpoint_url=self._config.get_sis_iop_url()))

            if self._config.get_exit_on() == constants.EXIT_ON_ALL_FINISHED:
                self._handlers.register_handler(
                    ClientUptimeHandler(session,
                                        method=constants.EXIT_ON_ALL_FINISHED,
                                        callback=self._on_exit))
            elif self._config.get_exit_on() == constants.EXIT_ON_PLAYBACK_DONE:
                self._handlers.register_handler(
                    ClientUptimeHandler(session,
                                        method=constants.EXIT_ON_PLAYBACK_DONE,
                                        callback=self._on_exit))
            elif self._config.get_exit_on() == constants.EXIT_ON_SEEDING_TIME:
                self._handlers.register_handler(
                    ClientUptimeHandler(
                        session,
                        method=constants.EXIT_ON_SEEDING_TIME,
                        max_seeding_time=self._config.get_seeding_time(),
                        callback=self._on_exit))

            if self._config.get_report_to() is not None:
                if self._config.get_report_to() == 'local_report':
                    self._local_reporter = PeerLocalReporter(
                        self._get_name(), self._config.get_id(), session,
                        self._config.get_directory())
                    self._handlers.register_handler(self._local_reporter)
                else:
                    self._handlers.register_handler(
                        PeerHTTPReporter(
                            self._get_name(),
                            self._config.get_id(),
                            self._config.get_report_to(),
                            scfg,
                            self._config.get_compress_xml_reports(),
                            self._config.get_serialization_method(),
                            report_interval=self._config.get_report_interval())
                    )