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 = 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.ERROR, primary=True)
            self._sCBStats.inc('Actor.Instance Create Failed')
            self._sayGoodbye()
            return

        self.actorInst = actorInst
        self.actorInst._myRef = self
Esempio n. 2
0
 def _not_compatible(self, createActorEnvelope):
     # Called when the current Actor System is not compatible with
     # the Actor's actorSystemCapabilityCheck.  Forward this
     # createActor request to another system that it's compatible
     # with.
     sourceHash = createActorEnvelope.message.sourceHash
     childRequirements = createActorEnvelope.message.targetActorReq
     childCName = createActorEnvelope.message.actorClassName
     childClass = actualActorClass(
         childCName,
         partial(loadModuleFromHashSource, sourceHash, self._sources)
         if sourceHash else None)
     acceptsCaps = lambda caps: checkActorCapabilities(
         childClass, caps, childRequirements)
     if createActorEnvelope.message.forActor is None:
         # Request from external; use sender address
         createActorEnvelope.message.forActor = createActorEnvelope.sender
     iolist = self._cstate.forward_pending_to_remote_system(
         childClass, createActorEnvelope, sourceHash, acceptsCaps)
     if iolist:
         for each in iolist:
             # Expected to be only one; if the transmit fails,
             # route it back here so that the next possible
             # remote can be tried.
             each.addCallback(onFailure=self._pending_send_failed)
             each.orig_create_envelope = createActorEnvelope
         return self._performIO(iolist)
     self._sendPendingActorResponse(
         createActorEnvelope,
         None,
         errorCode=PendingActorResponse.ERROR_No_Compatible_ActorSystem,
         errorStr="")
     # self._retryPendingChildOperations(childInstance, None)
     return True
Esempio n. 3
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 = 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.ERROR,
                     primary=True)
            self._sCBStats.inc('Actor.Instance Create Failed')
            self._sayGoodbye()
            return

        self.actorInst = actorInst
        self.actorInst._myRef = self
Esempio n. 4
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,
                                             globalName=self.globalName) \
                                             .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. 5
0
 def _newRefAndActor(self, actorSystem, parentAddr, actorAddr, actorClass, sourceHash=None, isTopLevel=False):
     try:
         actorClass = actualActorClass(actorClass,
                                       functools.partial(
                                           loadModuleFromHashSource,
                                           sourceHash, self._sources)
                                       if sourceHash else None)
         try:
             actor = actorClass(childActors=None)
         except TypeError as te:
             if "unexpected keyword argument 'childActors'" in str(te):
                 actor = actorClass()
             else:
                 actor = None
     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', actorClass, exc_info=True)
         raise
     except Exception:
         logging.getLogger('Thespian').warning('Actor total creation error', exc_info=True)
         actor = None
     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
Esempio n. 6
0
 def _newRefAndActor(self, actorSystem, parentAddr, actorAddr, actorClass,
                     sourceHash = None, isTopLevel = False):
     try:
         actorClass = actualActorClass(actorClass,
                                       functools.partial(
                                           loadModuleFromHashSource,
                                           sourceHash, self._sources)
                                       if sourceHash else None)
         try:
             actor = actorClass(childActors=None)
         except TypeError as te:
             if "unexpected keyword argument 'childActors'" in str(te):
                 actor = actorClass()
             else:
                 actor = None
     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
     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
Esempio n. 7
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
Esempio n. 8
0
    def h_PendingActor(self, envelope):
        sourceHash = envelope.message.sourceHash
        childRequirements = envelope.message.targetActorReq
        thesplog('Pending Actor request received for %s%s reqs %s from %s',
                 envelope.message.actorClassName,
                 ' (%s)'%sourceHash if sourceHash else '',
                 childRequirements, envelope.sender)

        if sourceHash:
            if sourceHash not in self._sources:
                # If this request was forwarded by a remote Admin and the
                # sourceHash is not known locally, request it from the sending
                # remote Admin
                if self._cstate.sentByRemoteAdmin(envelope) and \
                   self._acceptsRemoteLoadedSourcesFrom(envelope):
                    self._sources[sourceHash] = PendingSource(sourceHash, None)
                    self._sources[sourceHash].pending_actors.append(envelope)
                    self._hysteresisSender.sendWithHysteresis(
                        TransmitIntent(
                            envelope.sender,
                            SourceHashTransferRequest(sourceHash,
                                                      bool(self._sourceAuthority))))
                    # sent with hysteresis, so break out to local _run
                    return False
            if sourceHash in self._sources and \
               not self._sources[sourceHash].source_valid:
                # Still pending, add this create request to the waiting list
                self._sources[sourceHash].pending_actors.append(envelope)
                return True

        # If the requested ActorClass is compatible with this
        # ActorSystem, attempt to start it, otherwise forward the
        # request to any known compatible ActorSystem.
        childClass = envelope.message.actorClassName
        try:
            childClass = actualActorClass(envelope.message.actorClassName,
                                          partial(loadModuleFromHashSource,
                                                  sourceHash,
                                                  self._sources)
                                          if sourceHash else None)
            acceptsCaps = lambda caps: checkActorCapabilities(childClass, caps,
                                                              childRequirements)
            if not acceptsCaps(self.capabilities):
                if envelope.message.forActor is None:
                    # Request from external; use sender address
                    envelope.message.forActor = envelope.sender
                iolist = self._cstate.forward_pending_to_remote_system(
                    childClass, envelope, sourceHash, acceptsCaps)
                for each in iolist:
                    # Expected to be only one; if the transmit fails,
                    # route it back here so that the next possible
                    # remote can be tried.
                    each.addCallback(onFailure=self._pending_send_failed)
                self._performIO(iolist)
                return True
        except NoCompatibleSystemForActor as ex:
            thesplog(str(ex), level=logging.WARNING, primary=True)
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_No_Compatible_ActorSystem)
            return True
        except InvalidActorSourceHash:
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_Invalid_SourceHash)
            return True
        except InvalidActorSpecification as ex:
            thesplog('Error: InvalidActorSpecification: %s', str(ex), exc_info=True)
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
                errorStr=str(ex))
            return True
        except ImportError as ex:
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_Import,
                errorStr=str(ex))
            return True
        except AttributeError as ex:
            # Usually when the module has no attribute FooActor
            thesplog('Error: AttributeError: %s', str(ex), exc_info=True)
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
                errorStr=str(ex))
            return True
        except Exception as ex:
            import traceback
            thesplog('Exception "%s" handling PendingActor: %s', ex, traceback.format_exc(), level=logging.ERROR)
            self._sendPendingActorResponse(
                envelope, None,
                errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
                errorStr=str(ex))
            return True
        return super(ConventioneerAdmin, self).h_PendingActor(envelope)
Esempio n. 9
0
 def h_PendingActor(self, envelope):
     sourceHash = envelope.message.sourceHash
     childRequirements = envelope.message.targetActorReq
     thesplog('Pending Actor request for %s%s reqs %s from %s',
              envelope.message.actorClassName,
              ' (%s)' % sourceHash if sourceHash else '', childRequirements,
              envelope.sender)
     # If this request was forwarded by a remote Admin and the
     # sourceHash is not known locally, request it from the sending
     # remote Admin
     if sourceHash and \
        sourceHash not in self._sources and \
        self._sentByRemoteAdmin(envelope) and \
        self._acceptsRemoteLoadedSourcesFrom(envelope):
         requestedAlready = self._pendingSources.get(sourceHash, False)
         self._pendingSources.setdefault(sourceHash, []).append(envelope)
         if not requestedAlready:
             self._hysteresisSender.sendWithHysteresis(
                 TransmitIntent(envelope.sender,
                                SourceHashTransferRequest(sourceHash)))
             return False  # sent with hysteresis, so break out to local _run
         return True
     # If the requested ActorClass is compatible with this
     # ActorSystem, attempt to start it, otherwise forward the
     # request to any known compatible ActorSystem.
     try:
         childClass = actualActorClass(
             envelope.message.actorClassName,
             partial(loadModuleFromHashSource, sourceHash, self._sources)
             if sourceHash else None)
         acceptsCaps = lambda caps: checkActorCapabilities(
             childClass, caps, childRequirements)
         if not acceptsCaps(self.capabilities):
             if envelope.message.forActor is None:
                 # Request from external; use sender address
                 envelope.message.forActor = envelope.sender
             remoteCandidates = [
                 K for K in self._conventionMembers
                 if not self._conventionMembers[K].registryValid.expired()
                 and self._conventionMembers[K].remoteAddress !=
                 envelope.sender  # source Admin
                 and self._conventionMembers[K].remoteAddress not in
                 getattr(envelope.message, 'alreadyTried', []) and
                 acceptsCaps(self._conventionMembers[K].remoteCapabilities)
             ]
             if not remoteCandidates:
                 if self.isConventionLeader():
                     thesplog(
                         'No known ActorSystems can handle a %s for %s',
                         childClass,
                         envelope.message.forActor,
                         level=logging.WARNING,
                         primary=True)
                     self._sendPendingActorResponse(
                         envelope,
                         None,
                         errorCode=PendingActorResponse.
                         ERROR_No_Compatible_ActorSystem)
                     return True
                 # Let the Convention Leader try to find an appropriate ActorSystem
                 bestC = self._conventionAddress
             else:
                 # distribute equally amongst candidates
                 C = [(self._conventionMembers[K].remoteAddress,
                       len(self._conventionMembers[K].hasRemoteActors))
                      for K in remoteCandidates]
                 bestC = foldl(
                     lambda best, possible: best
                     if best[1] <= possible[1] else possible, C)[0]
                 thesplog('Requesting creation of %s%s on remote admin %s',
                          envelope.message.actorClassName,
                          ' (%s)' % sourceHash if sourceHash else '', bestC)
             envelope.message.alreadyTried.append(self.myAddress)
             self._send_intent(TransmitIntent(bestC, envelope.message))
             return True
     except InvalidActorSourceHash:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_SourceHash)
         return True
     except InvalidActorSpecification:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass)
         return True
     except ImportError as ex:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Import,
             errorStr=str(ex))
         return True
     except AttributeError as ex:
         # Usually when the module has no attribute FooActor
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
             errorStr=str(ex))
         return True
     except Exception as ex:
         import traceback
         thesplog('Exception "%s" handling PendingActor: %s', ex,
                  traceback.format_exc())
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
             errorStr=str(ex))
         return True
     return super(ConventioneerAdmin, self).h_PendingActor(envelope)
Esempio n. 10
0
 def h_PendingActor(self, envelope):
     sourceHash = envelope.message.sourceHash
     childRequirements = envelope.message.targetActorReq
     thesplog('Pending Actor request received for %s%s reqs %s from %s',
              envelope.message.actorClassName,
              ' (%s)' % sourceHash if sourceHash else '', childRequirements,
              envelope.sender)
     # If this request was forwarded by a remote Admin and the
     # sourceHash is not known locally, request it from the sending
     # remote Admin
     if sourceHash and \
        sourceHash not in self._sources and \
        self._cstate.sentByRemoteAdmin(envelope) and \
        self._acceptsRemoteLoadedSourcesFrom(envelope):
         requestedAlready = self._pendingSources.get(sourceHash, False)
         self._pendingSources.setdefault(sourceHash, []).append(envelope)
         if not requestedAlready:
             self._hysteresisSender.sendWithHysteresis(
                 TransmitIntent(envelope.sender,
                                SourceHashTransferRequest(sourceHash)))
             return False  # sent with hysteresis, so break out to local _run
         return True
     # If the requested ActorClass is compatible with this
     # ActorSystem, attempt to start it, otherwise forward the
     # request to any known compatible ActorSystem.
     childClass = envelope.message.actorClassName
     try:
         childClass = actualActorClass(
             envelope.message.actorClassName,
             partial(loadModuleFromHashSource, sourceHash, self._sources)
             if sourceHash else None)
         acceptsCaps = lambda caps: checkActorCapabilities(
             childClass, caps, childRequirements)
         if not acceptsCaps(self.capabilities):
             if envelope.message.forActor is None:
                 # Request from external; use sender address
                 envelope.message.forActor = envelope.sender
             iolist = self._cstate.forward_pending_to_remote_system(
                 childClass, envelope, sourceHash, acceptsCaps)
             for each in iolist:
                 # Expected to be only one; if the transmit fails,
                 # route it back here so that the next possible
                 # remote can be tried.
                 each.addCallback(onFailure=self._pending_send_failed)
             self._performIO(iolist)
             return True
     except NoCompatibleSystemForActor as ex:
         thesplog(str(ex), level=logging.WARNING, primary=True)
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_No_Compatible_ActorSystem)
         return True
     except InvalidActorSourceHash:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_SourceHash)
         return True
     except InvalidActorSpecification:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass)
         return True
     except ImportError as ex:
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Import,
             errorStr=str(ex))
         return True
     except AttributeError as ex:
         # Usually when the module has no attribute FooActor
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
             errorStr=str(ex))
         return True
     except Exception as ex:
         import traceback
         thesplog('Exception "%s" handling PendingActor: %s',
                  ex,
                  traceback.format_exc(),
                  level=logging.ERROR)
         self._sendPendingActorResponse(
             envelope,
             None,
             errorCode=PendingActorResponse.ERROR_Invalid_ActorClass,
             errorStr=str(ex))
         return True
     return super(ConventioneerAdmin, self).h_PendingActor(envelope)
Esempio n. 11
0
 def h_PendingActor(self, envelope):
     sourceHash = envelope.message.sourceHash
     childRequirements = envelope.message.targetActorReq
     # If this request was forwarded by a remote Admin and the
     # sourceHash is not known locally, request it from the sending
     # remote Admin
     if sourceHash and \
        sourceHash not in self._sources and \
        self._sentByRemoteAdmin(envelope) and \
        self._acceptsRemoteLoadedSourcesFrom(envelope):
         requestedAlready = self._pendingSources.get(sourceHash, False)
         self._pendingSources.setdefault(sourceHash, []).append(envelope)
         if not requestedAlready:
             self._hysteresisSender.sendWithHysteresis(
                 TransmitIntent(envelope.sender,
                                SourceHashTransferRequest(sourceHash)))
             return False  # sent with hysteresis, so break out to local _run
         return True
     # If the requested ActorClass is compatible with this
     # ActorSystem, attempt to start it, otherwise forward the
     # request to any known compatible ActorSystem.
     try:
         childClass = actualActorClass(envelope.message.actorClassName,
                                       partial(loadModuleFromHashSource,
                                               sourceHash,
                                               self._sources)
                                       if sourceHash else None)
         acceptsCaps = lambda caps: checkActorCapabilities(childClass, caps,
                                                           childRequirements)
         if not acceptsCaps(self.capabilities):
             if envelope.message.forActor is None:
                 # Request from external; use sender address
                 envelope.message.forActor = envelope.sender
             remoteCandidates = [
                 K
                 for K in self._conventionMembers
                 if not self._conventionMembers[K].registryValid.expired()
                 and self._conventionMembers[K].remoteAddress != envelope.sender # source Admin
                 and acceptsCaps(self._conventionMembers[K].remoteCapabilities)]
             if not remoteCandidates:
                 if self.isConventionLeader():
                     thesplog('No known ActorSystems can handle a %s for %s',
                              childClass, envelope.message.forActor,
                              level=logging.WARNING, primary=True)
                     self._sendPendingActorResponse(envelope, None,
                                                    errorCode = PendingActorResponse.ERROR_No_Compatible_ActorSystem)
                     return True
                 # Let the Convention Leader try to find an appropriate ActorSystem
                 bestC = self._conventionAddress
             else:
                 # distribute equally amongst candidates
                 C = [(self._conventionMembers[K].remoteAddress,
                       len(self._conventionMembers[K].hasRemoteActors))
                      for K in remoteCandidates]
                 bestC = foldl(lambda best,possible:
                               best if best[1] <= possible[1] else possible,
                               C)[0]
             self._send_intent(TransmitIntent(bestC, envelope.message))
             return True
     except InvalidActorSourceHash:
         self._sendPendingActorResponse(envelope, None,
                                        errorCode = PendingActorResponse.ERROR_Invalid_SourceHash)
         return True
     except InvalidActorSpecification:
         self._sendPendingActorResponse(envelope, None,
                                        errorCode = PendingActorResponse.ERROR_Invalid_ActorClass)
         return True
     except ImportError:
         self._sendPendingActorResponse(envelope, None,
                                        errorCode = PendingActorResponse.ERROR_Import)
         return True
     return super(ConventioneerAdmin, self).h_PendingActor(envelope)