From 8da3abbb5b86ce375f20fca797a0422da7d83e46 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 9 Aug 2022 18:54:17 +0530 Subject: [PATCH] Common: Add internal all event types topic to PyPubSubEventQueue --- monkey/common/event_queue/pypubsub_event_queue.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monkey/common/event_queue/pypubsub_event_queue.py b/monkey/common/event_queue/pypubsub_event_queue.py index 0910eee73..b28bea802 100644 --- a/monkey/common/event_queue/pypubsub_event_queue.py +++ b/monkey/common/event_queue/pypubsub_event_queue.py @@ -4,6 +4,8 @@ from common.events import AbstractEvent from .i_event_queue import IEventQueue +INTERNAL_ALL_EVENT_TYPES_TOPIC = "internal_all_event_types" + class PyPubSubEventQueue(IEventQueue): def __init__(self, pypubsub_publisher): @@ -21,6 +23,11 @@ class PyPubSubEventQueue(IEventQueue): event_type_name = event_type.__name__ self._pypubsub_publisher.subscribe(listener=subscriber, topicName=event_type_name) + def subscribe_all_event_types(self, subscriber: Callable[[AbstractEvent], None]): + self._pypubsub_publisher.subscribe( + listener=subscriber, topicName=INTERNAL_ALL_EVENT_TYPES_TOPIC + ) + def subscribe_tag(self, tag: str, subscriber: Callable[[AbstractEvent], None]): self._pypubsub_publisher.subscribe(listener=subscriber, topicName=tag) @@ -31,6 +38,9 @@ class PyPubSubEventQueue(IEventQueue): event_type_name = event.__name__ self._pypubsub_publisher.sendMessage(event_type_name, **data) + # publish to all events' topic + self._pypubsub_publisher.sendMessage(INTERNAL_ALL_EVENT_TYPES_TOPIC, **data) + # publish to tags' topics for tag in event.tags: self._pypubsub_publisher.sendMessage(tag, **data)