Ejemplo n.º 1
0
    def acquire(self, access_mode=None, timeout=None, database=None):
        if access_mode not in (WRITE_ACCESS, READ_ACCESS):
            raise ClientError(
                "Non valid 'access_mode'; {}".format(access_mode))
        if not timeout:
            raise ClientError(
                "'timeout' must be a float larger than 0; {}".format(timeout))

        from neo4j.api import check_access_mode
        access_mode = check_access_mode(access_mode)
        while True:
            try:
                # Get an address for a connection that have the fewest in-use connections.
                address = self._select_address(access_mode=access_mode,
                                               database=database)
                log.debug(
                    "[#0000]  C: <ACQUIRE ADDRESS> database=%r address=%r",
                    database, address)
            except (ReadServiceUnavailable, WriteServiceUnavailable) as err:
                raise SessionExpired(
                    "Failed to obtain connection towards '%s' server." %
                    access_mode) from err
            try:
                connection = self._acquire(
                    address,
                    timeout=timeout)  # should always be a resolved address
            except ServiceUnavailable:
                self.deactivate(address=address)
            else:
                return connection
Ejemplo n.º 2
0
 def acquire(self, access_mode=None, timeout=None):
     from neo4j.api import check_access_mode
     access_mode = check_access_mode(access_mode)
     while True:
         try:
             address = self._select_address(access_mode)
         except (ReadServiceUnavailable, WriteServiceUnavailable) as err:
             raise SessionExpired("Failed to obtain connection towards '%s' server." % access_mode) from err
         try:
             connection = self._acquire(address, timeout=timeout)  # should always be a resolved address
         except ServiceUnavailable:
             self.deactivate(address)
         else:
             return connection
Ejemplo n.º 3
0
 def acquire(self, *, access_mode, timeout, database):
     from neo4j.api import check_access_mode
     access_mode = check_access_mode(access_mode)
     while True:
         try:
             # Get an address for a connection that have the fewest in-use connections.
             address = self._select_address(access_mode=access_mode, database=database)
             log.debug("[#0000]  C: <ACQUIRE ADDRESS> database=%r address=%r", database, address)
         except (ReadServiceUnavailable, WriteServiceUnavailable) as err:
             raise SessionExpired("Failed to obtain connection towards '%s' server." % access_mode) from err
         try:
             connection = self._acquire(address, timeout=timeout)  # should always be a resolved address
         except ServiceUnavailable:
             self.deactivate(address=address)
         else:
             return connection