class AxonRootNamespaceClientAgent(object): """ Launch Servers in Root Namespace """ def __init__(self, record_queue): self.mngrs_map = {} self.connected_state = ConnectedStateProcessor(DBConnectedState()) self._primary_ep = None self._record_queue = record_queue self.log = logging.getLogger(__name__) # TODO(Pradeep Singh) MOve below code to a common location @property def primary_endpoint(self): """ Get the primary endpoint address from the DB It assumes in non namespace mode there will be only single interface. """ if not self._primary_ep: endpoints = self.connected_state.get_connected_state() if endpoints: self._primary_ep = endpoints[0]['endpoint'] return self._primary_ep def start_clients(self, namespace='localhost'): if not self.primary_endpoint: self.log.warning("Clients will not be started since " "no connected state exists yet") return clients = self.connected_state.get_clients(self.primary_endpoint) clients = clients if clients else [] if clients: src = self.primary_endpoint mngr = self.mngrs_map.get((namespace, src), RootNsClientManager(self._record_queue)) mngr.start_client(src, clients) self.mngrs_map[(namespace, src)] = mngr def stop_clients(self, namespace='localhost'): """ Stop all Clients :return: None """ for mngr in self.mngrs_map.values(): mngr.stop_clients() def stop_client(self, namespace='localhost', endpoint=None): ns_list = [namespace] endpoint = endpoint or self.primary_endpoint for (ns, src), mngr in self.mngrs_map.items(): if ns not in ns_list: continue if src == endpoint: mngr.stop_client() break
class AxonRootNamespaceClientAgent(object): """ Launch Servers in Root Namespace """ def __init__(self): self.mngrs_map = {} self.connected_state = ConnectedStateProcessor(DBConnectedState()) self._primary_ep = None self.log = logging.getLogger(__name__) # TODO(Pradeep Singh) MOve below code to a common location @property def primary_endpoint(self): """ Get the primary endpoint address from the DB It assumes in non namespace mode there will be only single interface. """ if not self._primary_ep: endpoints = self.connected_state.get_connected_state() if endpoints: self._primary_ep = endpoints[0]['endpoint'] return self._primary_ep def start_clients(self): if not self.primary_endpoint: self.log.warning("Clients will not be started since " "no connected state exists yet") return clients = self.connected_state.get_clients(self.primary_endpoint) clients = clients if clients else [] if clients: mngr = RootNsClientManager() if not \ self.mngrs_map.get('localhost') else \ self.mngrs_map.get('localhost') mngr.start_client(self.primary_endpoint, clients) self.mngrs_map['localhost'] = mngr def stop_clients(self, namespace='localhost'): """ Stop all Clients :return: None """ for mngr in self.mngrs_map.values(): mngr.stop_clients() def stop_client(self, namespace='localhost'): for mngr in self.mngrs_map.values(): mngr.stop_client()