@@ -29,17 +29,21 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
2929 tls_port = 0 , use_binary_protocol = True , queue_messages = True , recover = False , endpoint = None ,
3030 environment = None , http_open_timeout = None , http_request_timeout = None ,
3131 realtime_request_timeout = None , http_max_retry_count = None , http_max_retry_duration = None ,
32- fallback_hosts = None , fallback_retry_timeout = None , disconnected_retry_timeout = None ,
33- idempotent_rest_publishing = None , loop = None , auto_connect = True ,
32+ fallback_hosts = None , fallback_retry_timeout = None ,
33+ disconnected_retry_timeout = None , idempotent_rest_publishing = None , loop = None , auto_connect = True ,
3434 suspended_retry_timeout = None , connectivity_check_url = None ,
3535 channel_retry_timeout = Defaults .channel_retry_timeout , add_request_ids = False ,
3636 vcdiff_decoder : VCDiffDecoder = None , transport_params = None , ** kwargs ):
3737
3838 super ().__init__ (** kwargs )
3939
40+ # REC1b1: endpoint is incompatible with deprecated options
4041 if endpoint is not None :
41- if environment is not None or rest_host is not None or realtime_host is not None :
42- raise ValueError ('endpoint is incompatible with any of environment, rest_host or realtime_host' )
42+ if (environment is not None or rest_host is not None or
43+ realtime_host is not None ):
44+ raise ValueError (
45+ 'endpoint is incompatible with any of environment, rest_host, '
46+ 'realtime_host' )
4347
4448 # TODO check these defaults
4549 if fallback_retry_timeout is None :
@@ -70,16 +74,25 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
7074 idempotent_rest_publishing = api_version >= '1.2'
7175
7276 if environment is not None and endpoint is None :
77+ log .warning ("environment client option is deprecated, please use endpoint instead" )
7378 endpoint = environment
7479
80+ # REC1d: restHost or realtimeHost option
81+ # REC1d1: restHost takes precedence over realtimeHost
82+ if rest_host is not None and endpoint is None :
83+ log .warning ("rest_host client option is deprecated, please use endpoint instead" )
84+ endpoint = rest_host
85+ elif realtime_host is not None and endpoint is None :
86+ # REC1d2: realtimeHost if restHost not specified
87+ log .warning ("realtime_host client option is deprecated, please use endpoint instead" )
88+ endpoint = realtime_host
89+
7590 if endpoint is None :
7691 endpoint = Defaults .endpoint
7792
7893 self .__client_id = client_id
7994 self .__log_level = log_level
8095 self .__tls = tls
81- self .__rest_host = rest_host
82- self .__realtime_host = realtime_host
8396 self .__port = port
8497 self .__tls_port = tls_port
8598 self .__use_binary_protocol = use_binary_protocol
@@ -91,6 +104,8 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
91104 self .__realtime_request_timeout = realtime_request_timeout
92105 self .__http_max_retry_count = http_max_retry_count
93106 self .__http_max_retry_duration = http_max_retry_duration
107+ # Field for internal use only
108+ self .__fallback_host = None
94109 self .__fallback_hosts = fallback_hosts
95110 self .__fallback_retry_timeout = fallback_retry_timeout
96111 self .__disconnected_retry_timeout = disconnected_retry_timeout
@@ -101,13 +116,10 @@ def __init__(self, client_id=None, log_level=0, tls=True, rest_host=None, realti
101116 self .__connection_state_ttl = connection_state_ttl
102117 self .__suspended_retry_timeout = suspended_retry_timeout
103118 self .__connectivity_check_url = connectivity_check_url
104- self .__fallback_realtime_host = None
105119 self .__add_request_ids = add_request_ids
106120 self .__vcdiff_decoder = vcdiff_decoder
107121 self .__transport_params = transport_params or {}
108-
109- self .__rest_hosts = self .__get_rest_hosts ()
110- self .__realtime_hosts = self .__get_realtime_hosts ()
122+ self .__hosts = self .__get_hosts ()
111123
112124 @property
113125 def client_id (self ):
@@ -133,23 +145,6 @@ def tls(self):
133145 def tls (self , value ):
134146 self .__tls = value
135147
136- @property
137- def rest_host (self ):
138- return self .__rest_host
139-
140- @rest_host .setter
141- def rest_host (self , value ):
142- self .__rest_host = value
143-
144- # RTC1d
145- @property
146- def realtime_host (self ):
147- return self .__realtime_host
148-
149- @realtime_host .setter
150- def realtime_host (self , value ):
151- self .__realtime_host = value
152-
153148 @property
154149 def port (self ):
155150 return self .__port
@@ -276,12 +271,18 @@ def connectivity_check_url(self):
276271 return self .__connectivity_check_url
277272
278273 @property
279- def fallback_realtime_host (self ):
280- return self .__fallback_realtime_host
274+ def fallback_host (self ):
275+ """
276+ For internal use only, can be deleted in future
277+ """
278+ return self .__fallback_host
281279
282- @fallback_realtime_host .setter
283- def fallback_realtime_host (self , value ):
284- self .__fallback_realtime_host = value
280+ @fallback_host .setter
281+ def fallback_host (self , value ):
282+ """
283+ For internal use only, can be deleted in future
284+ """
285+ self .__fallback_host = value
285286
286287 @property
287288 def add_request_ids (self ):
@@ -295,29 +296,20 @@ def vcdiff_decoder(self):
295296 def transport_params (self ):
296297 return self .__transport_params
297298
298- def __get_rest_hosts (self ):
299+ def __get_hosts (self ):
299300 """
300301 Return the list of hosts as they should be tried. First comes the main
301302 host. Then the fallback hosts in random order.
302303 The returned list will have a length of up to http_max_retry_count.
303304 """
304- # Defaults
305- host = self .rest_host
306- if host is None :
307- host = Defaults .get_hostname (self .endpoint )
305+ host = Defaults .get_hostname (self .endpoint )
306+ # REC2: Determine fallback hosts
307+ fallback_hosts = self .get_fallback_hosts ()
308308
309309 http_max_retry_count = self .http_max_retry_count
310310 if http_max_retry_count is None :
311311 http_max_retry_count = Defaults .http_max_retry_count
312312
313- # Fallback hosts
314- fallback_hosts = self .fallback_hosts
315- if fallback_hosts is None :
316- if self .rest_host is not None :
317- fallback_hosts = []
318- else :
319- fallback_hosts = Defaults .get_fallback_hosts (self .endpoint )
320-
321313 # Shuffle
322314 fallback_hosts = list (fallback_hosts )
323315 random .shuffle (fallback_hosts )
@@ -328,28 +320,22 @@ def __get_rest_hosts(self):
328320 hosts = hosts [:http_max_retry_count ]
329321 return hosts
330322
331- def __get_realtime_hosts (self ):
332- if self .realtime_host is not None :
333- host = self .realtime_host
334- return [host ]
335-
336- host = Defaults .get_hostname (self .endpoint )
337- return [host ] + self .__fallback_hosts
338-
339- def get_rest_hosts (self ):
340- return self .__rest_hosts
341-
342- def get_rest_host (self ):
343- return self .__rest_hosts [0 ]
323+ def get_hosts (self ):
324+ return self .__hosts
344325
345- def get_realtime_hosts (self ):
346- return self .__realtime_hosts
326+ def get_host (self ):
327+ return self .__hosts [ 0 ]
347328
348- def get_realtime_host (self ):
349- return self .__realtime_hosts [0 ]
329+ # REC2: Various client options collectively determine a set of fallback domains
330+ def get_fallback_hosts (self ):
331+ # REC2a: If the fallbackHosts client option is specified
332+ if self .__fallback_hosts is not None :
333+ # REC2a2: the set of fallback domains is given by the value of the fallbackHosts option
334+ return self .__fallback_hosts
350335
351- def get_fallback_rest_hosts (self ):
352- return self .__rest_hosts [1 :]
336+ # REC2c: Otherwise, the set of fallback domains is defined implicitly by the options
337+ # used to define the primary domain as specified in (REC1)
338+ return Defaults .get_fallback_hosts (self .endpoint )
353339
354340 def get_fallback_realtime_hosts (self ):
355- return self .__realtime_hosts [ 1 :]
341+ return self .get_fallback_hosts ()
0 commit comments