X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=ricsdl-package%2Fricsdl%2Fbackend%2Fdbbackend_abc.py;h=8805bdd58de5bc99cb8fd72535b51d19168da5fa;hb=HEAD;hp=4f31554e17ae3da4c70eabe2d4ba7fa04870b6c2;hpb=c979c0db16f873c0f8ea6fe5d1b98c15f79d18de;p=ric-plt%2Fsdlpy.git diff --git a/ricsdl-package/ricsdl/backend/dbbackend_abc.py b/ricsdl-package/ricsdl/backend/dbbackend_abc.py old mode 100644 new mode 100755 index 4f31554..8805bdd --- a/ricsdl-package/ricsdl/backend/dbbackend_abc.py +++ b/ricsdl-package/ricsdl/backend/dbbackend_abc.py @@ -21,7 +21,7 @@ """The module provides Shared Data Layer (SDL) database backend interface.""" -from typing import (Dict, Set, List, Union) +from typing import (Callable, Dict, Set, List, Optional, Tuple, Union) from abc import ABC, abstractmethod @@ -114,6 +114,83 @@ class DbBackendAbc(ABC): """Return the number of members in a group under a namespace in database.""" pass + @abstractmethod + def set_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]], + data_map: Dict[str, bytes]) -> None: + """Publish event to channel after writing data.""" + pass + + @abstractmethod + def set_if_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]], key: str, + old_data: bytes, new_data: bytes) -> bool: + """ + Publish event to channel after writing key value to database under a namespace + if the old value is expected one. + """ + pass + + @abstractmethod + def set_if_not_exists_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]], + key: str, data: bytes) -> bool: + """" + Publish event to channel after writing key value to database under a namespace if + key doesn't exist. + """ + pass + + @abstractmethod + def remove_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]], + keys: List[str]) -> None: + """Publish event to channel after removing data.""" + pass + + @abstractmethod + def remove_if_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]], key: str, + data: bytes) -> bool: + """ + Publish event to channel after removing key and its data from database if the + current data value is expected one. + """ + pass + + @abstractmethod + def remove_all_and_publish(self, ns: str, channels_and_events: Dict[str, List[str]]) -> None: + """ + Publish event to channel after removing all keys in namespace. + """ + pass + + @abstractmethod + def subscribe_channel(self, ns: str, cb: Callable[[str, List[str]], None], + channels: List[str]) -> None: + """ + This takes a callback function and one or many channels to be subscribed. + When an event is received for the given channel, the given callback function + shall be called with channel and notification(s) as parameter. + """ + pass + + @abstractmethod + def unsubscribe_channel(self, ns: str, channels: List[str]) -> None: + """Unsubscribes from channel and removes set callback function.""" + pass + + @abstractmethod + def start_event_listener(self) -> None: + """ + start_event_listener creates an event loop in a separate thread for handling + notifications from subscriptions. + """ + pass + + @abstractmethod + def handle_events(self) -> Optional[Tuple[str, List[str]]]: + """ + handle_events is a non-blocking function that returns a tuple containing channel + name and message(s) received from notification. + """ + pass + class DbBackendLockAbc(ABC): """