예제 #1
0
파일: proxy.py 프로젝트: pedrotgn/pyactor
    def __call__(self, *args, **kwargs):
        if 'future' in kwargs.keys():
            future = kwargs['future']
            del kwargs['future']
        else:
            future = False
        host = get_host()
        if host is not None:
            new_args = host.dumps(list(args))
            new_kwargs = host.dumps(kwargs)
        else:
            raise HostError('No such Host on the context of the call.')

        if future:
            self.__lock = get_lock()
            future_ref = {METHOD: self._method, PARAMS: (new_args, new_kwargs),
                          CHANNEL: self._actor_channel, TO: self.target,
                          'LOCK': self.__lock}

            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref, ref=True)
        else:
            result = super(AskRefWrapper, self).__call__(*new_args,
                                                         **new_kwargs)
            return get_host().loads(result)
예제 #2
0
    def __call__(self, *args, **kwargs):
        future = kwargs['future'] if 'future' in kwargs.keys() else False
        host = get_host()
        if host is not None:
            new_args = host.dumps(list(args))
        else:
            raise HostError('No such Host on the context of the call.')

        if future:
            self.__lock = get_lock()
            future_ref = {
                METHOD: self._method,
                PARAMS: args,
                CHANNEL: self._actor_channel,
                TO: self.target,
                'LOCK': self.__lock
            }

            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref, ref=True)
        else:
            result = super(AskRefWrapper, self).__call__(*new_args, **kwargs)
            return get_host().loads(result)
예제 #3
0
파일: proxy.py 프로젝트: pedrotgn/pyactor
 def __init__(self, actor):
     self.__channel = actor.channel
     self.actor = actor
     self.__lock = get_lock()
     for method in actor.ask_ref:
         setattr(self, method, AskRefWrapper(self.__channel, method,
                                             actor.url))
     for method in actor.tell_ref:
         setattr(self, method, TellRefWrapper(self.__channel, method,
                                              actor.url))
     for method in actor.tell:
         setattr(self, method, TellWrapper(self.__channel, method,
                                           actor.url))
     for method in actor.ask:
         setattr(self, method, AskWrapper(self.__channel, method,
                                          actor.url))
예제 #4
0
 def __init__(self, actor):
     self.__channel = actor.channel
     self.actor = actor
     self.__lock = get_lock()
     for method in actor.ask_ref:
         setattr(self, method,
                 AskRefWrapper(self.__channel, method, actor.url))
     for method in actor.tell_ref:
         setattr(self, method,
                 TellRefWrapper(self.__channel, method, actor.url))
     for method in actor.tell:
         setattr(self, method, TellWrapper(self.__channel, method,
                                           actor.url))
     for method in actor.ask:
         setattr(self, method, AskWrapper(self.__channel, method,
                                          actor.url))
예제 #5
0
    def __call__(self, *args, **kwargs):
        future = kwargs['future'] if 'future' in kwargs.keys() else False

        self.__lock = get_lock()
        if not future:
            self.__channel = actorm.Channel()
            timeout = kwargs['timeout'] if 'timeout' in kwargs.keys() else 10
            #  SENDING MESSAGE ASK
            # msg = AskRequest(ASK, self._method, args, self.__channel,
            #                  self.target)
            msg = {
                TYPE: ASK,
                METHOD: self._method,
                PARAMS: args,
                CHANNEL: self.__channel,
                TO: self.target
            }
            self._actor_channel.send(msg)
            if self.__lock is not None:
                self.__lock.release()
            try:
                response = self.__channel.receive(timeout)
                result = response[RESULT]
            except Empty:
                if self.__lock is not None:
                    self.__lock.acquire()
                raise TimeoutError(self._method)
            if self.__lock is not None:
                self.__lock.acquire()
            if isinstance(result, Exception):
                raise result
            else:
                return result
        else:
            future_ref = {
                METHOD: self._method,
                PARAMS: args,
                CHANNEL: self._actor_channel,
                TO: self.target,
                'LOCK': self.__lock
            }
            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref)
예제 #6
0
파일: proxy.py 프로젝트: pedrotgn/pyactor
    def __call__(self, *args, **kwargs):
        if 'future' in kwargs.keys():
            future = kwargs['future']
            del kwargs['future']
        else:
            future = False

        self.__lock = get_lock()
        if not future:
            self.__channel = actorm.Channel()
            if 'timeout' in kwargs.keys():
                timeout = kwargs['timeout']
                del kwargs['timeout']
            else:
                timeout = 10
            #  SENDING MESSAGE ASK
            # msg = AskRequest(ASK, self._method, args, self.__channel,
            #                  self.target)
            msg = {TYPE: ASK, METHOD: self._method, PARAMS: (args, kwargs),
                   CHANNEL: self.__channel, TO: self.target}
            self._actor_channel.send(msg)
            if self.__lock is not None:
                self.__lock.release()
            try:
                response = self.__channel.receive(timeout)
                result = response[RESULT]
            except Empty:
                if self.__lock is not None:
                    self.__lock.acquire()
                raise TimeoutError(self._method)
            if self.__lock is not None:
                self.__lock.acquire()
            if isinstance(result, Exception):
                raise result
            else:
                return result
        else:
            future_ref = {METHOD: self._method, PARAMS: (args, kwargs),
                          CHANNEL: self._actor_channel, TO: self.target,
                          'LOCK': self.__lock}
            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref)