Sha256: 1c3736c7ca25858f0d2064e8abe9d7b58a95263d082cf6e356c406157d3cb039

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

import uuid
import threading
from javonet.utils.CommandType import CommandType


class DelegatesCache(object):
    _instance = None
    delegates_cache = dict()
    _lock = threading.Lock()  # Initialize a lock object

    def __new__(cls):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super(DelegatesCache, cls).__new__(cls)
        return cls._instance

    def cache_delegate(self, object_delegate):
        with self._lock:
            uuid_ = str(uuid.uuid4())
            self.delegates_cache[uuid_] = object_delegate
            return uuid_

    def resolve_delegate(self, command):
        if command.command_type != CommandType.Reference:
            raise Exception(
                "Failed to find delegate")
        with self._lock:
            try:
                return self.delegates_cache[command.payload[0]]
            except KeyError:
                raise Exception("Object not found in delegates")

    def delete_delegate(self, delegate_guid):
        with self._lock:
            try:
                del self.delegates_cache[delegate_guid]
                return 0
            except KeyError:
                raise Exception("Object not found in delegates")

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/delegateCache/DelegatesCache.py
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/delegateCache/DelegatesCache.py
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/delegateCache/DelegatesCache.py
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/delegateCache/DelegatesCache.py
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/delegateCache/DelegatesCache.py