11# For the moment this is just a Connection pooler to keep compatibility with other clients
2+ import copy
23import logging
34from typing import Annotated , Callable , Optional , TypeVar
45
@@ -23,46 +24,58 @@ class Environment:
2324 _connections (list[Connection]): List of active connections managed by this environment
2425 """
2526
26- def __init__ (self ): # type: ignore
27+ def __init__ (
28+ self , # single-node mode
29+ uri : Optional [str ] = None ,
30+ # multi-node mode
31+ uris : Optional [list [str ]] = None ,
32+ ssl_context : Optional [SslConfigurationContext ] = None ,
33+ on_disconnection_handler : Optional [CB ] = None , # type: ignore
34+ ):
2735 """
2836 Initialize a new Environment instance.
2937
3038 Creates an empty list to track active connections.
39+
40+ Args:
41+ uri: Single node connection URI
42+ uris: List of URIs for multi-node setup
43+ ssl_context: SSL configuration for secure connections
44+ on_disconnection_handler: Callback for handling disconnection events
45+
3146 """
47+ if uri is not None and uris is not None :
48+ raise ValueError (
49+ "Cannot specify both 'uri' and 'uris'. Choose one connection mode."
50+ )
51+ if uri is None and uris is None :
52+ raise ValueError ("Must specify either 'uri' or 'uris' for connection." )
53+ self ._uri = uri
54+ self ._uris = uris
55+ self ._ssl_context = ssl_context
56+ self ._on_disconnection_handler = on_disconnection_handler
3257 self ._connections : list [Connection ] = []
3358
3459 def connection (
3560 self ,
36- # single-node mode
37- uri : Optional [str ] = None ,
38- # multi-node mode
39- uris : Optional [list [str ]] = None ,
40- ssl_context : Optional [SslConfigurationContext ] = None ,
41- on_disconnection_handler : Optional [CB ] = None , # type: ignore
4261 ) -> Connection :
4362 """
4463 Create and return a new connection.
4564
4665 This method supports both single-node and multi-node configurations, with optional
4766 SSL/TLS security and disconnection handling.
4867
49- Args:
50- uri: Single node connection URI
51- uris: List of URIs for multi-node setup
52- ssl_context: SSL configuration for secure connections
53- on_disconnection_handler: Callback for handling disconnection events
54-
5568 Returns:
5669 Connection: A new connection instance
5770
5871 Raises:
5972 ValueError: If neither uri nor uris is provided
6073 """
6174 connection = Connection (
62- uri = uri ,
63- uris = uris ,
64- ssl_context = ssl_context ,
65- on_disconnection_handler = on_disconnection_handler ,
75+ uri = self . _uri ,
76+ uris = self . _uris ,
77+ ssl_context = self . _ssl_context ,
78+ on_disconnection_handler = self . _on_disconnection_handler ,
6679 )
6780 logger .debug ("Environment: Creating and returning a new connection" )
6881 self ._connections .append (connection )
0 commit comments