Example #1
0
class _BaseConfigurator(Configurator):
    _user: User = None

    def __init__(self, user: User = None, shared_dictionary: dict = None):
        if user is None:
            user = UserFactory.get_current_user()

        self._user = user
        self.init(shared_dictionary)

    __manager: Manager

    def init(self, shared_dictionary: dict):
        self._machine_name = socket.gethostname()
        self._ip_address = str(socket.gethostbyname(self._machine_name))
        self._process_id = os.getpid()

        self.__manager = Manager()
        if shared_dictionary is None:
            shared_dictionary = self.__manager.dict()
            shared_dictionary[
                Configurator.GLOBAL_LOCK_KEY] = self.__manager.Lock()
            proxy = self.__manager.ManagedObjectFactory()
            proxy._manager = self.__manager
            shared_dictionary[Configurator.GLOBAL_MANAGER_PROXY] = proxy
        else:
            self._application_id = shared_dictionary[
                Configurator.GLOBAL_APPLICATION_ID_KEY]
        self._shared_dictionary = shared_dictionary

    _machine_name: str
    _ip_address: str
    _process_id: int

    @property
    def machine_name(self) -> str:
        return self._machine_name

    @property
    def address(self):
        return self._ip_address

    @property
    def username(self) -> str:
        return self._user.userid

    @property
    def unique_instance_id_per_machine(self) -> int:
        return self._process_id

    @property
    def region(self) -> str:
        return self._user.region

    @property
    def user(self) -> User:
        return self._user

    @property
    def mode(self) -> str:
        return os.environ[Configurator.GYOMU_COMMON_MODE]

    _application_id: int = 0

    @property
    def application_id(self) -> int:
        return self._application_id

    def set_application_id(self, application_id: int):
        self._application_id = application_id
        self._shared_dictionary[
            Configurator.GLOBAL_APPLICATION_ID_KEY] = application_id

    _shared_dictionary: dict = None

    @property
    def shared_dictionary(self) -> dict:
        return self._shared_dictionary

    def _get_manager(self):
        return self.__manager