Пример #1
0
 def restart(self):
     logger.warning("Stopping client stack on node {}".format(self))
     self.stop()
     logger.warning("Starting client stack on node {}".format(self))
     self.start()
     # Sleep to allow disconnected clients to reconnect before sending replies from the server side.
     time.sleep(self.postrestart_wait_time)
Пример #2
0
 def handle_connections_limit(self):
     connections_limit_reached_prev = self.connections_limit_reached
     self.connections_limit_reached = self.connected_clients_num >= self.max_connected_clients_num
     if self.connections_limit_reached:
         if not connections_limit_reached_prev:
             logger.warning(
                 '{}: connections limit reached! Actual: {}, limit: {}.'.
                 format(self, self.connected_clients_num,
                        self.max_connected_clients_num))
         if self.client_stack_restart_enabled:
             if self._can_restart():
                 logger.warning(
                     'Going to restart client stack {} due to reached connections limit! Actual: {}, limit: {}.'
                     .format(self, self.connected_clients_num,
                             self.max_connected_clients_num))
                 self.restart()
                 self.init_stack_restart_params()
             elif not connections_limit_reached_prev:
                 logger.warning(
                     '{}: connections limit reached but too few time spent since client stack start, restart it later.'
                     .format(self))
     elif connections_limit_reached_prev:
         logger.warning(
             '{}: connections number fell below the limit! Actual: {}, limit: {}.'
             .format(self, self.connected_clients_num,
                     self.max_connected_clients_num))
         if self.client_stack_restart_enabled:
             logger.warning(
                 '{}: client stack restart is not needed anymore.'.format(
                     self))
Пример #3
0
 def handle_listener_events(self):
     events = self.get_monitor_events(self.listener_monitor)
     for event in events:
         logger.trace('{} listener event: {}'.format(self, event))
         if event['event'] == zmq.EVENT_ACCEPTED:
             self.connected_clients_num += 1
         if event['event'] == zmq.EVENT_DISCONNECTED:
             assert self.connected_clients_num > 0
             if self.connected_clients_num > 0:
                 self.connected_clients_num -= 1
             else:
                 logger.warning('{}: disconnected event received, but connected clients number is 0'.format(self))
         logger.trace('{}: number of connected clients: {}'.format(self, self.connected_clients_num))