def _create_topic_and_subscription(self) -> str: """ Create the unique topic for the agent that it will listen on for work (task) deliveries that it has requested from the task-pool """ unique_topic = UniqueTopic().topic(TaskPool.POOL_TOPIC_PREFIX) pub.subscribe(self, unique_topic) return unique_topic
def _create_topic_and_subscription(self) -> str: """ Create the unique topic for the agent that it will listen on for work (task) deliveries that it has requested from the task-pool """ topic = UniqueTopic().topic(SimpleEther.ETHER_TOPIC_PREFIX) pub.subscribe(self, topic) # Instance specific pub.subscribe( self, Ether.ETHER_BACK_PLANE_TOPIC) # Back plane discovery topic return topic
def test_unique(self): have_seen = dict() for _ in range(10000): pref = random.choice(TestTopic.pref) ut = UniqueTopic().topic(pref) if pref is None: self.assertTrue(TestTopic.pattern_no_prefix.match(ut)) else: self.assertTrue(TestTopic.pattern_with_prefix.match(ut)) self.assertFalse(ut in have_seen) have_seen[ut] = True
def _create_topic_and_subscriptions(self) -> str: """ Create the unique topic for the agent that it will listen on for work (task) deliveries that it has requested from the task-pool """ topics = list() unique_topic = UniqueTopic().topic(Agent.AGENT_TOPIC_PREFIX) topics.append(unique_topic) for topic in self._work_topics(): topics.append(topic) self.add_subscription_topics(topics=topics) for topic in topics: # do potentially high latency subscriptions outside of the lock. pub.subscribe(self, topic) return unique_topic
def __init__(self, name: str, capability: SimpleCapability = SimpleCapability( capability_name='DummySrcSink'), ping_topic: str = Ether.ETHER_BACK_PLANE_TOPIC): # SrcSink - Standard boot-strap & protected members # self._name = name self._topic = UniqueTopic().topic() self._address_book = AddressBook() super().__init__() self._capabilities = [capability] self._lock = threading.Lock() self._handler = NotificationHandler(object_to_be_handler_for=self, throw_unhandled=True) self._handler.register_handler(self._do_srcsink_ping, SrcSinkPing) self._handler.register_handler(self._do_srcsink_ping_notification, SrcSinkPingNotification) self._handler.register_handler(self._do_notification, TaskNotification) self._handler.register_handler(self._do_work, WorkNotificationDo) self._handler.register_handler(self._do_work_finalise, WorkNotificationFinalise) # Public Members just for Unit Test Asserts # self.pings = list() self.ping_notifications = list() self.task_notification = list() self.work_notification = list() self.work_finalise = list() self._ping_topic = ping_topic # The topic to issue ping's on # Get connected ! self.setup_subscriptions() return
def test_with_prefix(self): ut = UniqueTopic().topic('pref') self.assertTrue(TestTopic.pattern_with_prefix.match(ut))
def __init__(self, name: str): super().__init__() self._name = name self._topic = UniqueTopic.topic("DummySrcSink") return