From 41ea4a901bb02874b7244b5120aa6c95b1a5d0f7 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 5 Aug 2022 18:25:00 +0530 Subject: [PATCH] Common: Add IEventQueue --- monkey/common/event_queue/__init__.py | 0 monkey/common/event_queue/i_event_queue.py | 53 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 monkey/common/event_queue/__init__.py create mode 100644 monkey/common/event_queue/i_event_queue.py diff --git a/monkey/common/event_queue/__init__.py b/monkey/common/event_queue/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/common/event_queue/i_event_queue.py b/monkey/common/event_queue/i_event_queue.py new file mode 100644 index 000000000..c0de3aeab --- /dev/null +++ b/monkey/common/event_queue/i_event_queue.py @@ -0,0 +1,53 @@ +from abc import ABC, abstractmethod +from typing import Any, Callable, Sequence + +from common.events import AbstractEvent + + +class IEventQueue(ABC): + """ + Manages subscription and publishing of events + """ + + @abstractmethod + def subscribe_all(self, subscriber: Callable[..., Any]): + """ + Subscribes a subscriber to all events + + :param subscriber: Callable that should subscribe to events + """ + + pass + + @abstractmethod + def subscribe_types(self, types: Sequence[AbstractEvent], subscriber: Callable[..., Any]): + """ + Subscribes a subscriber to all specifed event types + + :param types: Event types to which the subscriber should subscribe + :param subscriber: Callable that should subscribe to events + """ + + pass + + @abstractmethod + def subscribe_tags(self, tags: Sequence[str], subscriber: Callable[..., Any]): + """ + Subscribes a subscriber to all specified event tags + + :param tags: Event tags to which the subscriber should subscribe + :param subscriber: Callable that should subscribe to events + """ + + pass + + @abstractmethod + def publish(self, event: AbstractEvent, data: Any): + """ + Publishes an event with the given data + + :param event: Event to publish + :param data: Data to pass to subscribers with the event publish + """ + + pass