Esempio n. 1
0
 def _select_address(self, *, access_mode, database):
     from neo4j.api import READ_ACCESS
     """ Selects the address with the fewest in-use connections.
     """
     self.create_routing_table(database)
     self.ensure_routing_table_is_fresh(access_mode=access_mode,
                                        database=database)
     log.debug("[#0000]  C: <ROUTING TABLE ENSURE FRESH> %r",
               self.routing_tables)
     if access_mode == READ_ACCESS:
         addresses = self.routing_tables[database].readers
     else:
         addresses = self.routing_tables[database].writers
     addresses_by_usage = {}
     for address in addresses:
         addresses_by_usage.setdefault(
             self.in_use_connection_count(address), []).append(address)
     if not addresses_by_usage:
         if access_mode == READ_ACCESS:
             raise ReadServiceUnavailable(
                 "No read service currently available")
         else:
             raise WriteServiceUnavailable(
                 "No write service currently available")
     return choice(addresses_by_usage[min(addresses_by_usage)])
Esempio n. 2
0
 def _select_address(self, access_mode=None):
     from neo4j.api import READ_ACCESS
     """ Selects the address with the fewest in-use connections.
     """
     self.ensure_routing_table_is_fresh(access_mode)
     if access_mode == READ_ACCESS:
         addresses = self.routing_table.readers
     else:
         addresses = self.routing_table.writers
     addresses_by_usage = {}
     for address in addresses:
         addresses_by_usage.setdefault(self.in_use_connection_count(address), []).append(address)
     if not addresses_by_usage:
         if access_mode == READ_ACCESS:
             raise ReadServiceUnavailable("No read service currently available")
         else:
             raise WriteServiceUnavailable("No write service currently available")
     return choice(addresses_by_usage[min(addresses_by_usage)])
Esempio n. 3
0
 def on_write_failure(self, *, address):
     raise WriteServiceUnavailable("No write service available for pool {}".format(self))