def _connect_to_cluster(self):
        addresses = get_possible_addresses(
            self._config.network_config.addresses, self.members)

        current_attempt = 1
        attempt_limit = self._config.network_config.connection_attempt_limit
        retry_delay = self._config.network_config.connection_attempt_period
        while current_attempt <= attempt_limit:
            for address in addresses:
                try:
                    self.logger.info("Connecting to %s", address)
                    self._connect_to_address(address)
                    return
                except:
                    self.logger.warning("Error connecting to %s ",
                                        address,
                                        exc_info=True)

            if current_attempt >= attempt_limit:
                self.logger.warning(
                    "Unable to get alive cluster connection, attempt %d of %d",
                    current_attempt, attempt_limit)
                break

            self.logger.warning(
                "Unable to get alive cluster connection, attempt %d of %d, trying again in %d seconds",
                current_attempt, attempt_limit, retry_delay)
            current_attempt += 1
            time.sleep(retry_delay)

        error_msg = "Could not connect to any of %s after %d tries" % (
            addresses, attempt_limit)
        raise HazelcastError(error_msg)
 def shutdown(self):
     for connection in self._map.values():
         try:
             connection.close(HazelcastError("Client is shutting down"))
         except OSError, connection:
             if connection.args[0] == socket.EBADF:
                 pass
             else:
                 raise
 def shutdown(self):
     for connection in self._connections:
         try:
             self.logger.debug("Shutdown connection: %s", str(connection))
             connection.close(HazelcastError("Client is shutting down"))
         except OSError, err:
             if err.args[0] == socket.EBADF:
                 pass
             else:
                 raise
Exemplo n.º 4
0
 def shutdown(self):
     if not self._is_live:
         return
     self._is_live = False
     for connection in list(self._map.values()):
         try:
             connection.close(HazelcastError("Client is shutting down"))
         except OSError as connection:
             if connection.args[0] == socket.EBADF:
                 pass
             else:
                 raise
     self._map.clear()
     self._thread.join()
    def register_listener(self, registration_request, decode_register_response, encode_deregister_request, handler):
        if self.is_smart:
            self.try_sync_connect_to_all_members()

        with self._registration_lock:
            user_registration_id = str(uuid4())
            listener_registration = ListenerRegistration(registration_request, decode_register_response,
                                                         encode_deregister_request, handler)
            self._active_registrations[user_registration_id] = listener_registration

            active_connections = self._client.connection_manager.connections
            for connection in active_connections.values():
                try:
                    self.register_listener_on_connection_async(user_registration_id, listener_registration, connection)\
                        .result()
                except:
                    if connection.live():
                        self.deregister_listener(user_registration_id)
                        raise HazelcastError("Listener cannot be added ")
            return user_registration_id