예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
    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
예제 #6
0
 def test_with_prefix(self):
     ut = UniqueTopic().topic('pref')
     self.assertTrue(TestTopic.pattern_with_prefix.match(ut))
예제 #7
0
 def __init__(self, name: str):
     super().__init__()
     self._name = name
     self._topic = UniqueTopic.topic("DummySrcSink")
     return