X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ricsdl-package%2Fricsdl%2Fbackend%2Fdbbackend_abc.py;h=8805bdd58de5bc99cb8fd72535b51d19168da5fa;hb=e67b9abd75c6ebeda849e5e718a507de4027f65d;hp=4be5737e8252fb77974608016373a051e1b6f433;hpb=dada8463c0fd4c3b90eedc54b6c913f0fa0e7272;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 4be5737..8805bdd --- a/ricsdl-package/ricsdl/backend/dbbackend_abc.py +++ b/ricsdl-package/ricsdl/backend/dbbackend_abc.py @@ -21,13 +21,18 @@ """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 class DbBackendAbc(ABC): """An abstract Shared Data Layer (SDL) class providing database backend interface.""" + @abstractmethod + def is_connected(self): + """Test database backend connection.""" + pass + @abstractmethod def close(self): """Close database backend connection.""" @@ -54,12 +59,12 @@ class DbBackendAbc(ABC): pass @abstractmethod - def find_keys(self, ns: str, key_prefix: str) -> List[str]: + def find_keys(self, ns: str, key_pattern: str) -> List[str]: """"Return all the keys matching search pattern under a namespace in database.""" pass @abstractmethod - def find_and_get(self, ns: str, key_prefix: str, atomic: bool) -> Dict[str, bytes]: + def find_and_get(self, ns: str, key_pattern: str) -> Dict[str, bytes]: """ Return all the keys with their values matching search pattern under a namespace in database. @@ -109,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): """