コード例 #1
0
    def ScatterEventWithoutTheStars(self, eventid, args, keywords=None):
        if keywords is None:
            keywords = {}
        if not eventid.startswith('On'):
            self.LogError(
                'ScatterEvent called with event ', eventid,
                ".  All events sent via ScatterEvent should start with 'On'.")
            self.LogError(
                "Not only is the programmer responsible for this a 10z3r, but he wears his mother's underwear as well"
            )
            log.LogTraceback()
        shouldLogMethodCalls = self.ShouldLogMethodCalls()
        if shouldLogMethodCalls:
            if IsFullLogging():
                self.LogMethodCall('ScatterEvent(', eventid, ',*args=', args,
                                   ',**kw=', keywords, ')')
            else:
                self.LogMethodCall('ScatterEvent(', eventid, ')')
        prefix = blue.pyos.taskletTimer.GetCurrent(
        ) + '::ScatterEvent_' + eventid + '::'
        for srv in self.notify.get(eventid, []):
            try:
                logname = prefix + self.GetLogName(srv)
                if ObjectShouldReceiveMessages(srv):
                    if shouldLogMethodCalls:
                        self.LogMethodCall('Calling ', logname)
                    srvGuid = getattr(srv, '__guid__', logname)
                    uthread.worker(prefix + srvGuid,
                                   self.MollycoddledUthread, srvGuid, eventid,
                                   getattr(srv, eventid), args, keywords)
                elif shouldLogMethodCalls:
                    self.LogMethodCall('Skipping ', logname,
                                       ' (service not running)')
            except Exception:
                log.LogException()

        notifiedToRemove = []
        for weakObj in self.notifyObs.get(eventid, []):
            try:
                obj = weakObj()
                func = getattr(obj, eventid, None)
                if obj is None or func is None:
                    notifiedToRemove.append(weakObj)
                else:
                    if shouldLogMethodCalls:
                        logname = prefix + str(obj)
                        self.LogMethodCall('Calling ', logname)
                    uthread.workerWithoutTheStars('', func, args, keywords)
            except Exception:
                log.LogException()

        for toRemove in notifiedToRemove:
            if toRemove in self.notifyObs[eventid]:
                self.notifyObs[eventid].remove(toRemove)
コード例 #2
0
    def ScatterEventWithoutTheStars(self, eventid, args, keywords = None):
        if keywords is None:
            keywords = {}
        if not eventid.startswith('On'):
            self.LogError('ScatterEvent called with event ', eventid, ".  All events sent via ScatterEvent should start with 'On'.")
            self.LogError("Not only is the programmer responsible for this a 10z3r, but he wears his mother's underwear as well")
            log.LogTraceback()
        shouldLogMethodCalls = self.ShouldLogMethodCalls()
        if shouldLogMethodCalls:
            if IsFullLogging():
                self.LogMethodCall('ScatterEvent(', eventid, ',*args=', args, ',**kw=', keywords, ')')
            else:
                self.LogMethodCall('ScatterEvent(', eventid, ')')
        prefix = blue.pyos.taskletTimer.GetCurrent() + '::ScatterEvent_' + eventid + '::'
        for srv in self.notify.get(eventid, []):
            try:
                logname = prefix + self.GetLogName(srv)
                if ObjectShouldReceiveMessages(srv):
                    if shouldLogMethodCalls:
                        self.LogMethodCall('Calling ', logname)
                    srvGuid = getattr(srv, '__guid__', logname)
                    uthread.worker(prefix + srvGuid, self.MollycoddledUthread, srvGuid, eventid, getattr(srv, eventid), args, keywords)
                elif shouldLogMethodCalls:
                    self.LogMethodCall('Skipping ', logname, ' (service not running)')
            except Exception:
                log.LogException()

        notifiedToRemove = []
        for weakObj in self.notifyObs.get(eventid, []):
            try:
                obj = weakObj()
                func = getattr(obj, eventid, None)
                if obj is None or func is None:
                    notifiedToRemove.append(weakObj)
                else:
                    if shouldLogMethodCalls:
                        logname = prefix + str(obj)
                        self.LogMethodCall('Calling ', logname)
                    uthread.workerWithoutTheStars('', func, args, keywords)
            except Exception:
                log.LogException()

        for toRemove in notifiedToRemove:
            if toRemove in self.notifyObs[eventid]:
                self.notifyObs[eventid].remove(toRemove)
コード例 #3
0
    def NotifySessionChangeWithoutTheStars(self, eventid, args, keywords = None):
        if keywords is None:
            keywords = {}
        if eventid not in ('DoSessionChanging', 'ProcessSessionChange', 'OnSessionChanged'):
            raise RuntimeError('NotifySessionChange called with eventid ', eventid, '. Must be one of DoSessionChanging, ProcessSessionChange or OnSessionChanged')
        if eventid == 'ProcessSessionChange' and stackless.getcurrent().block_trap or stackless.getcurrent().is_main:
            raise RuntimeError("ChainEvent (NotifySessionChange) is blocking by design, but you're block trapped.")
        if eventid == 'DoSessionChanging':
            old_block_trap = stackless.getcurrent().block_trap
            stackless.getcurrent().block_trap = 1
        shouldLogMethodCalls = self.ShouldLogMethodCalls()
        if shouldLogMethodCalls:
            self.LogMethodCall('NotifySessionChange(', eventid, ',*args=', args, ',**kw=', keywords, ')')
        prefix = blue.pyos.taskletTimer.GetCurrent() + '::NotifySessionChange_' + eventid + '::'
        ret = []
        myNodeID = self.services['machoNet'].GetNodeID()
        isSessionRelevant = boot.role != 'server' or session.contextOnly
        try:
            for srv in self.notify.get(eventid, []):
                try:
                    logname = prefix + self.GetLogName(srv)
                    if ObjectShouldReceiveMessages(srv):
                        if shouldLogMethodCalls:
                            self.LogMethodCall('Calling ' + logname)
                        if eventid == 'OnSessionChanged':
                            if not isSessionRelevant and srv.MachoResolve(session.GetActualSession()) == myNodeID:
                                isSessionRelevant = True
                            srvGuid = getattr(srv, '__guid__', logname)
                            uthread.worker(prefix + srvGuid, self.MollycoddledUthread, srvGuid, eventid, getattr(srv, eventid), args, keywords)
                        else:
                            retval = ClockThisWithoutTheStars(logname, getattr(srv, eventid), args, keywords)
                            ret.append(retval)
                    elif shouldLogMethodCalls:
                        self.LogMethodCall('Skipping ', logname, ' (service not running)')
                except StandardError:
                    log.LogException('In %s.%s' % (getattr(srv, '__guid__', self.GetLogName(srv)), eventid))
                    sys.exc_clear()

            notifiedToRemove = []
            for weakObj in self.notifyObs.get(eventid, []):
                obj = weakObj()
                if obj is None or not getattr(obj, eventid, None):
                    notifiedToRemove.append(weakObj)
                else:
                    try:
                        if shouldLogMethodCalls:
                            logname = prefix + str(obj)
                            self.LogMethodCall('Calling ', logname)
                        if eventid == 'OnSessionChanged':
                            uthread.workerWithoutTheStars('', getattr(obj, eventid), args, keywords)
                        else:
                            ClockThisWithoutTheStars(prefix + self.GetLogName(weakObj), getattr(obj, eventid), args, keywords)
                    except StandardError:
                        self.LogError('In %s.%s' % (getattr(weakObj, '__guid__', self.GetLogName(srv)), eventid))
                        log.LogException()
                        sys.exc_clear()

            for toRemove in notifiedToRemove:
                if toRemove in self.notifyObs[eventid]:
                    self.notifyObs[eventid].remove(toRemove)

            if not session.contextOnly:
                if not isSessionRelevant:
                    if session.irrelevanceTime is None:
                        session.irrelevanceTime = blue.os.GetWallclockTime()
                        log.LogInfo('CTXSESS: session ', session.sid, ' = ', session, ' is no longer relevant to any service')
                elif session.irrelevanceTime is not None:
                    log.LogInfo('CTXSESS: session ', session.sid, ' became relevant again')
                    session.irrelevanceTime = None
        finally:
            if eventid == 'DoSessionChanging':
                bt = 0
                if old_block_trap:
                    bt = 1
                stackless.getcurrent().block_trap = bt

        return tuple(ret)
コード例 #4
0
    def NotifySessionChangeWithoutTheStars(self, eventid, args, keywords=None):
        if keywords is None:
            keywords = {}
        if eventid not in ('DoSessionChanging', 'ProcessSessionChange',
                           'OnSessionChanged'):
            raise RuntimeError(
                'NotifySessionChange called with eventid ', eventid,
                '. Must be one of DoSessionChanging, ProcessSessionChange or OnSessionChanged'
            )
        if eventid == 'ProcessSessionChange' and stackless.getcurrent(
        ).block_trap or stackless.getcurrent().is_main:
            raise RuntimeError(
                "ChainEvent (NotifySessionChange) is blocking by design, but you're block trapped."
            )
        if eventid == 'DoSessionChanging':
            old_block_trap = stackless.getcurrent().block_trap
            stackless.getcurrent().block_trap = 1
        shouldLogMethodCalls = self.ShouldLogMethodCalls()
        if shouldLogMethodCalls:
            self.LogMethodCall('NotifySessionChange(', eventid, ',*args=',
                               args, ',**kw=', keywords, ')')
        prefix = blue.pyos.taskletTimer.GetCurrent(
        ) + '::NotifySessionChange_' + eventid + '::'
        ret = []
        myNodeID = self.services['machoNet'].GetNodeID()
        isSessionRelevant = boot.role != 'server' or session.contextOnly
        try:
            for srv in self.notify.get(eventid, []):
                try:
                    logname = prefix + self.GetLogName(srv)
                    if ObjectShouldReceiveMessages(srv):
                        if shouldLogMethodCalls:
                            self.LogMethodCall('Calling ' + logname)
                        if eventid == 'OnSessionChanged':
                            if not isSessionRelevant and srv.MachoResolve(
                                    session.GetActualSession()) == myNodeID:
                                isSessionRelevant = True
                            srvGuid = getattr(srv, '__guid__', logname)
                            uthread.worker(prefix + srvGuid,
                                           self.MollycoddledUthread,
                                           srvGuid, eventid,
                                           getattr(srv,
                                                   eventid), args, keywords)
                        else:
                            retval = ClockThisWithoutTheStars(
                                logname, getattr(srv, eventid), args, keywords)
                            ret.append(retval)
                    elif shouldLogMethodCalls:
                        self.LogMethodCall('Skipping ', logname,
                                           ' (service not running)')
                except StandardError:
                    log.LogException('In %s.%s' % (getattr(
                        srv, '__guid__', self.GetLogName(srv)), eventid))
                    sys.exc_clear()

            notifiedToRemove = []
            for weakObj in self.notifyObs.get(eventid, []):
                obj = weakObj()
                if obj is None or not getattr(obj, eventid, None):
                    notifiedToRemove.append(weakObj)
                else:
                    try:
                        if shouldLogMethodCalls:
                            logname = prefix + str(obj)
                            self.LogMethodCall('Calling ', logname)
                        if eventid == 'OnSessionChanged':
                            uthread.workerWithoutTheStars(
                                '', getattr(obj, eventid), args, keywords)
                        else:
                            ClockThisWithoutTheStars(
                                prefix + self.GetLogName(weakObj),
                                getattr(obj, eventid), args, keywords)
                    except StandardError:
                        self.LogError('In %s.%s' %
                                      (getattr(weakObj, '__guid__',
                                               self.GetLogName(srv)), eventid))
                        log.LogException()
                        sys.exc_clear()

            for toRemove in notifiedToRemove:
                if toRemove in self.notifyObs[eventid]:
                    self.notifyObs[eventid].remove(toRemove)

            if not session.contextOnly:
                if not isSessionRelevant:
                    if session.irrelevanceTime is None:
                        session.irrelevanceTime = blue.os.GetWallclockTime()
                        log.LogInfo('CTXSESS: session ', session.sid, ' = ',
                                    session,
                                    ' is no longer relevant to any service')
                elif session.irrelevanceTime is not None:
                    log.LogInfo('CTXSESS: session ', session.sid,
                                ' became relevant again')
                    session.irrelevanceTime = None
        finally:
            if eventid == 'DoSessionChanging':
                bt = 0
                if old_block_trap:
                    bt = 1
                stackless.getcurrent().block_trap = bt

        return tuple(ret)