@@ -41,53 +41,24 @@ class EndpointBasedConnectionHandler(ConnectionHandler):
4141 """Endpoint based implementation of connection handling logic."""
4242
4343 def __init__ (self , plugin_service : PluginService , props : Properties ):
44- srw_read_endpoint = WrapperProperties .SRW_READ_ENDPOINT .get (props )
45- if srw_read_endpoint is None :
46- raise AwsWrapperError (
47- Messages .get_formatted (
48- "SimpleReadWriteSplittingPlugin.MissingRequiredConfigParameter" ,
49- WrapperProperties .SRW_READ_ENDPOINT .name ,
50- )
51- )
52- self ._read_endpoint : str = srw_read_endpoint
53-
54- srw_write_endpoint = WrapperProperties .SRW_WRITE_ENDPOINT .get (props )
55- if srw_write_endpoint is None :
56- raise AwsWrapperError (
57- Messages .get_formatted (
58- "SimpleReadWriteSplittingPlugin.MissingRequiredConfigParameter" ,
59- WrapperProperties .SRW_WRITE_ENDPOINT .name ,
60- )
61- )
62- self ._write_endpoint : str = srw_write_endpoint
44+ self ._read_endpoint : str = EndpointBasedConnectionHandler ._verify_parameter (
45+ WrapperProperties .SRW_READ_ENDPOINT , props , str , required = True
46+ )
47+ self ._write_endpoint : str = EndpointBasedConnectionHandler ._verify_parameter (
48+ WrapperProperties .SRW_WRITE_ENDPOINT , props , str , required = True
49+ )
6350
64- self ._verify_new_connections : bool = (
65- WrapperProperties .SRW_VERIFY_NEW_CONNECTIONS . get_bool ( props )
51+ self ._verify_new_connections : bool = self . _verify_parameter (
52+ WrapperProperties .SRW_VERIFY_NEW_CONNECTIONS , props , bool
6653 )
67- if self ._verify_new_connections is True :
68- srw_connect_retry_timeout_ms : int = (
69- WrapperProperties .SRW_CONNECT_RETRY_TIMEOUT_MS .get_int (props )
70- )
71- if srw_connect_retry_timeout_ms <= 0 :
72- raise ValueError (
73- Messages .get_formatted (
74- "SimpleReadWriteSplittingPlugin.IncorrectConfiguration" ,
75- WrapperProperties .SRW_CONNECT_RETRY_TIMEOUT_MS .name ,
76- )
77- )
78- self ._connect_retry_timeout_ms : int = srw_connect_retry_timeout_ms
7954
80- srw_connect_retry_interval_ms : int = (
81- WrapperProperties .SRW_CONNECT_RETRY_INTERVAL_MS .get_int (props )
55+ if self ._verify_new_connections :
56+ self ._connect_retry_timeout_ms : int = self ._verify_parameter (
57+ WrapperProperties .SRW_CONNECT_RETRY_TIMEOUT_MS , props , int , lambda x : x > 0
58+ )
59+ self ._connect_retry_interval_ms : int = self ._verify_parameter (
60+ WrapperProperties .SRW_CONNECT_RETRY_INTERVAL_MS , props , int , lambda x : x > 0
8261 )
83- if srw_connect_retry_interval_ms <= 0 :
84- raise ValueError (
85- Messages .get_formatted (
86- "SimpleReadWriteSplittingPlugin.IncorrectConfiguration" ,
87- WrapperProperties .SRW_CONNECT_RETRY_INTERVAL_MS .name ,
88- )
89- )
90- self ._connect_retry_interval_ms : int = srw_connect_retry_interval_ms
9162
9263 self ._verify_opened_connection_type : Optional [HostRole ] = (
9364 EndpointBasedConnectionHandler ._parse_connection_type (
@@ -305,6 +276,27 @@ def _create_host_info(self, endpoint, role: HostRole) -> HostInfo:
305276 host = host , port = port , role = role , availability = HostAvailability .AVAILABLE
306277 )
307278
279+ @staticmethod
280+ def _verify_parameter (prop , props , expected_type , validator = None , required = False ):
281+ value = prop .get_type (props , expected_type )
282+ if required :
283+ if value is None :
284+ raise AwsWrapperError (
285+ Messages .get_formatted (
286+ "SimpleReadWriteSplittingPlugin.MissingRequiredConfigParameter" ,
287+ prop .name ,
288+ )
289+ )
290+
291+ if validator and not validator (value ):
292+ raise ValueError (
293+ Messages .get_formatted (
294+ "SimpleReadWriteSplittingPlugin.IncorrectConfiguration" ,
295+ prop .name ,
296+ )
297+ )
298+ return value
299+
308300 def _delay (self ):
309301 sleep (self ._connect_retry_interval_ms / 1000 )
310302
0 commit comments