85
85
PoolConfig ,
86
86
WorkspaceConfig ,
87
87
)
88
+ from neo4j .api import (
89
+ READ_ACCESS ,
90
+ WRITE_ACCESS ,
91
+ )
88
92
89
93
# Set up logger
90
94
log = getLogger ("neo4j" )
@@ -413,11 +417,12 @@ def time_remaining():
413
417
raise ClientError ("Failed to obtain a connection from pool "
414
418
"within {!r}s" .format (timeout ))
415
419
416
- def acquire (self , access_mode = None , timeout = None ):
420
+ def acquire (self , access_mode = None , timeout = None , database = None ):
417
421
""" Acquire a connection to a server that can satisfy a set of parameters.
418
422
419
423
:param access_mode:
420
424
:param timeout:
425
+ :param database:
421
426
"""
422
427
423
428
def release (self , * connections ):
@@ -459,7 +464,7 @@ def deactivate(self, address):
459
464
if not connections :
460
465
self .remove (address )
461
466
462
- def on_write_failure (self , * , address ):
467
+ def on_write_failure (self , address ):
463
468
raise WriteServiceUnavailable ("No write service available for pool {}" .format (self ))
464
469
465
470
def remove (self , address ):
@@ -488,7 +493,15 @@ def close(self):
488
493
class BoltPool (IOPool ):
489
494
490
495
@classmethod
491
- def open (cls , address , * , auth = None , pool_config , workspace_config ):
496
+ def open (cls , address , * , auth , pool_config , workspace_config ):
497
+ """Create a new BoltPool
498
+
499
+ :param address:
500
+ :param auth:
501
+ :param pool_config:
502
+ :param workspace_config:
503
+ :return: BoltPool
504
+ """
492
505
493
506
def opener (addr , timeout ):
494
507
return Bolt .open (addr , auth = auth , timeout = timeout , ** pool_config )
@@ -505,7 +518,7 @@ def __init__(self, opener, pool_config, workspace_config, address):
505
518
def __repr__ (self ):
506
519
return "<{} address={!r}>" .format (self .__class__ .__name__ , self .address )
507
520
508
- def acquire (self , * , access_mode = None , timeout = None , database = None ):
521
+ def acquire (self , access_mode = None , timeout = None , database = None ):
509
522
# The access_mode and database is not needed for a direct connection, its just there for consistency.
510
523
return self ._acquire (self .address , timeout )
511
524
@@ -515,7 +528,16 @@ class Neo4jPool(IOPool):
515
528
"""
516
529
517
530
@classmethod
518
- def open (cls , * addresses , auth = None , routing_context = None , pool_config = None , workspace_config = None ):
531
+ def open (cls , * addresses , auth , pool_config , workspace_config , routing_context = None ):
532
+ """Create a new Neo4jPool
533
+
534
+ :param addresses: one or more address as positional argument
535
+ :param auth:
536
+ :param pool_config:
537
+ :param workspace_config:
538
+ :param routing_context:
539
+ :return: Neo4jPool
540
+ """
519
541
520
542
def opener (addr , timeout ):
521
543
return Bolt .open (addr , auth = auth , timeout = timeout , ** pool_config )
@@ -842,7 +864,12 @@ def _select_address(self, *, access_mode, database):
842
864
raise WriteServiceUnavailable ("No write service currently available" )
843
865
return choice (addresses_by_usage [min (addresses_by_usage )])
844
866
845
- def acquire (self , * , access_mode , timeout , database ):
867
+ def acquire (self , access_mode = None , timeout = None , database = None ):
868
+ if access_mode not in (WRITE_ACCESS , READ_ACCESS ):
869
+ raise ClientError ("Non valid 'access_mode'; {}" .format (access_mode ))
870
+ if not timeout :
871
+ raise ClientError ("'timeout' must be a float larger than 0; {}" .format (timeout ))
872
+
846
873
from neo4j .api import check_access_mode
847
874
access_mode = check_access_mode (access_mode )
848
875
while True :
@@ -859,7 +886,7 @@ def acquire(self, *, access_mode, timeout, database):
859
886
else :
860
887
return connection
861
888
862
- def deactivate (self , * , address ):
889
+ def deactivate (self , address ):
863
890
""" Deactivate an address from the connection pool,
864
891
if present, remove from the routing table and also closing
865
892
all idle connections to that address.
@@ -874,7 +901,7 @@ def deactivate(self, *, address):
874
901
log .debug ("[#0000] C: <ROUTING> table=%r" , self .routing_tables )
875
902
super (Neo4jPool , self ).deactivate (address )
876
903
877
- def on_write_failure (self , * , address ):
904
+ def on_write_failure (self , address ):
878
905
""" Remove a writer address from the routing table, if present.
879
906
"""
880
907
log .debug ("[#0000] C: <ROUTING> Removing writer %r" , address )
0 commit comments