Esempio n. 1
0
    def _createInstance(self):
        aClass = self._actorClass
        try:
            aClass = actualActorClass(
                aClass,
                partial(loadModuleFromHashSource, self._sourceHash,
                        self._sources) if self._sourceHash else None)
            # Now instantiate the identified Actor class object
            actorInst = withPossibleInitArgs(capabilities=self.capabilities,
                                             requirements=self._childReqs) \
                                             .create(aClass)
            self._sCBStats.inc('Actor.Instance Created')
        except Exception as ex:
            import traceback
            logging.getLogger(str(self._actorClass)) \
                   .error('Actor %s @ %s instantiation exception',
                          self._actorClass, self.transport.myAddress,
                          exc_info = True)
            thesplog('Actor %s @ %s instantiation exception: %s',
                     self._actorClass,
                     self.transport.myAddress,
                     traceback.format_exc(),
                     level=logging.WARNING,
                     primary=True)
            self._sCBStats.inc('Actor.Instance Create Failed')
            self._sayGoodbye()
            return

        self.actorInst = actorInst
        self.actorInst._myRef = self
Esempio n. 2
0
 def _newRefAndActor(self,
                     actorSystem,
                     parentAddr,
                     actorAddr,
                     actorClass,
                     sourceHash=None,
                     targetActorRequirements=None,
                     isTopLevel=False):
     try:
         actorClass = actualActorClass(
             actorClass,
             functools.partial(loadModuleFromHashSource, sourceHash,
                               self._sources) if sourceHash else None)
         if hasattr(actorClass, 'actorSystemCapabilityCheck') and \
            not actorClass.actorSystemCapabilityCheck(
                self.system.capabilities,
                targetActorRequirements or {}):
             actor = None
         else:
             actor = withPossibleInitArgs(
                 capabilities=self.system.capabilities,
                 requirements=targetActorRequirements) \
                 .create(actorClass)
     except ActorSystemException:
         logging.getLogger('Thespian').warning(
             'Actor total creation failure', exc_info=True)
         actor = None
         if isTopLevel: raise
     except ImportError:
         logging.getLogger('Thespian').warning(
             'Actor create import error for %s (hash %s)',
             actorClass,
             sourceHash,
             exc_info=True)
         raise
     except Exception:
         logging.getLogger('Thespian').warning('Actor total creation error',
                                               exc_info=True)
         actor = None
         if isTopLevel: raise
     nar = ActorRef(actorSystem,
                    parentAddr,
                    actorAddr,
                    actor,
                    mySourceHash=sourceHash)
     if actor:
         nar.instance._myRef = nar
         nar.instance._receive = types.MethodType(actor_base_receive,
                                                  nar.instance)
     return nar
    def __init__(self, requirements=None, foo=None, capabilities=None):
        self.ready = True
        self.reqs = requirements
        self.caps = capabilities


class ReqFooArgs(object):
    def __init__(self, requirements=None, foo=None):
        self.ready = True
        self.reqs = requirements


wpa = withPossibleInitArgs(capabilities={
    'caps': 'here',
    'capa': 'bilities'
},
                           requirements={
                               'reqs': 'requirements',
                               'r': True
                           })


def test_noargs():
    obj = wpa.create(NoArgs)
    assert obj
    assert not hasattr(obj, 'caps')
    assert not hasattr(obj, 'reqs')


def test_reqargs():
    obj = wpa.create(ReqArgs)
    assert obj