Beispiel #1
0
   def mainBody(self):            
      while self.number_of_files > self.filenames_mailed:
               
         "create a list of all the files in the provided directory" 
         self.filelisting = os.listdir(self.directory)
      
         self.filelisting = self.find_files_of_type(self.filelisting, self.file_type) #remove files from list that are not of the right file type

         if len(self.filelisting) == 0:
            print "random_file_selector: No files of that type in the directory!", repr(self.file_type)
            self.send(producerFinished("Done"),"signal")
            return 0
          
         file_index = random.randrange(0, len(self.filelisting))  #index for a random file
         random_file = self.filelisting[file_index]               #get the name of random file
      
         print "random_file_selector: The randomly choosen file is", random_file
   
         fullfilename = os.path.join(self.directory, random_file) #"root\file"
         
         self.send(fullfilename,"outbox")
         self.filenames_mailed = self.filenames_mailed + 1
         return 1
         
      self.send(producerFinished("Done"),"signal")  
      return 0
Beispiel #2
0
 def cleanup(self):
     """Destroy child components and send producerFinished when we quit."""    
     self.debug("SimpleHTTPClient.cleanup()")
     self.send(producerFinished(self), "_carouselsignal") #shutdown() not currently supported by Carousel
     self.send(producerFinished(self), "signal")
     self.removeChild(self.carousel)        
     self.unpause()
Beispiel #3
0
    def main(self):
        while True:
            if self.dataReady("inbox"):
                data = self.recv("inbox")
                parseddata = feedparser.parse(data)
                parseddata.href = self.feedUrl
                if parseddata.has_key('bozo_exception'):
                    self.send(producerFinished(self), "signal")
                    stopped(self.feedUrl)
                    return
                else:
                    self.send(parseddata, "outbox")
                    self.send(producerFinished(self), "signal")
                    stopped(self.feedUrl)
                    return

            if self.dataReady("control"):
                data = self.recv("control")
                self.send(data, "signal")
                if not isinstance(data, producerFinished):
                    print data
                stopped(self.feedUrl)
                return

            if not self.anyReady():
                self.pause()
            yield 1
Beispiel #4
0
    def main(self):
        self.initiateInternalSplitter()
        yield 1

        while True:
            mustStop, providerFinished = self.checkControl()
            if mustStop:
                self.send(mustStop, "signal")
                return

            self.handleChildTerminations()

            while self.dataReady("inbox"):
                feed = self.recv("inbox")
                child = self.createChild(feed)
                self.addChildren(child)
                child.activate()

            while self.dataReady("_parsed-feeds"):
                parseddata = self.recv("_parsed-feeds")
                self.send(parseddata, "outbox")

            if providerFinished and len(self.childComponents()) == 1:
                # TODO: CHECK IF THIS IS THE PROBLEM
                # It's actually only waiting for the plugsplitter
                for _ in self.waitForChildren(producerFinished(self)):
                    yield 1
                pfinished = producerFinished(self)
                self.send(pfinished, "signal")
                return

            if not self.anyReady():
                self.pause()
            yield 1
Beispiel #5
0
 def main(self):
     while 1:
         yield 1
         while self.dataReady("inbox"):
             msg = self.recv("inbox")
             
             # add this string to our character queue
             self.forwardqueue.push(msg)
         
         # while there is enough data to send another chunk
         while len(self.forwardqueue) >= self.chunksize:
             self.sendChunk()
         
         # if nodelay then send any data not yet sent rather than waiting for more
         if self.nodelay:
             self.sendPartialChunk()
             
         while self.dataReady("control"):
             msg = self.recv("control")
             if isinstance(msg, producerFinished):
                 self.sendPartialChunk()
                 self.send(producerFinished(self), "signal")
                 return
             elif isinstance(msg, shutdown):
                 self.send(producerFinished(self), "signal")
                 return
         self.pause()
Beispiel #6
0
    def main(self):
        while 1:
            yield 1
            while self.dataReady("inbox"):
                msg = self.recv("inbox")

                # add this string to our character queue
                self.forwardqueue.push(msg)

            # while there is enough data to send another chunk
            while len(self.forwardqueue) >= self.chunksize:
                self.sendChunk()

            # if nodelay then send any data not yet sent rather than waiting for more
            if self.nodelay:
                self.sendPartialChunk()

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished):
                    self.sendPartialChunk()
                    self.send(producerFinished(self), "signal")
                    return
                elif isinstance(msg, shutdown):
                    self.send(producerFinished(self), "signal")
                    return
            self.pause()
Beispiel #7
0
 def main(self):
     self.timebomb.activate()
     self.child.activate()
     yield 1
     while not (self.child._isStopped() or (self.dataReady('_trigger') and self.recv('_trigger') is True)):
         self.pause()
         yield 1
     if not self.timebomb._isStopped():
         self.send(producerFinished(), '_disarm')
     
     shutdown_messages = [ producerFinished(), shutdownMicroprocess(), serverShutdown(), shutdown() ]
     for msg in shutdown_messages:
         if not self.child._isStopped():
             self.send( msg, "_sigkill")
             yield 1
             yield 1
         else:
             break
          
     self.removeChild(self.child)
     yield 1
     if not self.child._isStopped():
         self.child.stop()
         yield 1
         if 'signal' in self.Outboxes:
             self.send(shutdownMicroprocess(), 'signal')
             yield 1
Beispiel #8
0
    def mainBody(self):
        while self.number_of_files > self.filenames_mailed:

            "create a list of all the files in the provided directory"
            self.filelisting = os.listdir(self.directory)

            self.filelisting = self.find_files_of_type(
                self.filelisting, self.file_type
            )  #remove files from list that are not of the right file type

            if len(self.filelisting) == 0:
                print "random_file_selector: No files of that type in the directory!", repr(
                    self.file_type)
                self.send(producerFinished("Done"), "signal")
                return 0

            file_index = random.randrange(0, len(
                self.filelisting))  #index for a random file
            random_file = self.filelisting[
                file_index]  #get the name of random file

            print "random_file_selector: The randomly choosen file is", random_file

            fullfilename = os.path.join(self.directory,
                                        random_file)  #"root\file"

            self.send(fullfilename, "outbox")
            self.filenames_mailed = self.filenames_mailed + 1
            return 1

        self.send(producerFinished("Done"), "signal")
        return 0
Beispiel #9
0
    def main(self):
        p = DispatchParser()
        # The DispatchParser allows to register callbacks per local name
        # and namespaces. But here we simply register a default callback
        # for any XML element parsed successfully and drop it into the outbox
        # so that components that will be linked to it will have to make
        # the decision whether or not the element is relevant to them
        # or simply discard it.
        p.register_default(self._done)
        yield 1

        while 1:
            if self.dataReady("control"):
                mes = self.recv("control")

                if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished):
                    self.send(producerFinished(), "signal")
                    break

            if self.dataReady("reset"):
                command = self.recv("reset")
                if command == "RESET":
                    p.reset()

            if self.dataReady("inbox"):
                data = self.recv("inbox")
                try:
                    p.feed(data)
                except SAXParseException:
                    self.send(producerFinished(), "signal")

            if not self.anyReady():
                self.pause()

            yield 1
Beispiel #10
0
 def main(self):
     self.initiateInternalSplitter()
     yield 1
     
     while True:
         mustStop, providerFinished = self.checkControl()
         if mustStop:
             self.send(mustStop,"signal")
             return
         
         self.handleChildTerminations()
         
         while self.dataReady("inbox"):
             feed = self.recv("inbox")
             child = self.createChild(feed)
             self.addChildren(child)
             child.activate()
             
         while self.dataReady("_parsed-feeds"):
             parseddata = self.recv("_parsed-feeds")
             self.send(parseddata,"outbox")
             
         if providerFinished and len(self.childComponents()) == 1:
             # TODO: CHECK IF THIS IS THE PROBLEM
             # It's actually only waiting for the plugsplitter
             for _ in self.waitForChildren(producerFinished(self)):
                 yield 1
             pfinished = producerFinished(self)
             self.send(pfinished,"signal")
             return
             
         if not self.anyReady():
             self.pause()
         yield 1
Beispiel #11
0
 def cleanup(self):
     """Destroy child components and send producerFinished when we quit."""    
     self.debug("SimpleHTTPClient.cleanup()")
     self.send(producerFinished(self), "_carouselsignal") #shutdown() not currently supported by Carousel
     self.send(producerFinished(self), "signal")
     self.removeChild(self.carousel)        
     self.unpause()
Beispiel #12
0
    def main(self):
        while True:
            if self.dataReady("inbox"):
                data = self.recv("inbox")
                parseddata = feedparser.parse(data)
                parseddata.href = self.feedUrl
                if parseddata.has_key('bozo_exception'):
                    self.send(producerFinished(self),"signal")
                    stopped(self.feedUrl)
                    return
                else:
                    self.send(parseddata, "outbox")
                    self.send(producerFinished(self),"signal")
                    stopped(self.feedUrl)
                    return
            
            if self.dataReady("control"):
                data = self.recv("control")
                self.send(data,"signal")
                if not isinstance(data, producerFinished):
                    print data
                stopped(self.feedUrl)
                return

            if not self.anyReady():
                self.pause()
            yield 1
Beispiel #13
0
    def main(self):
        resampler = None
        format = None
        shutdown = False
        while self.anyReady() or not shutdown:
            while self.dataReady("inbox"):
                data = self.recv("inbox")

                if data['type'] == "audio":
                    newformat = (data['sample_rate'], data['channels'],
                                 data['format'])
                    if newformat != format:
                        format = newformat
                        # need new audio playback component
                        # first remove any old one
                        if resampler:
                            self.removeChild(resampler)
                            self.send(producerFinished(), "_ctrl")
                            for l in linkages:
                                self.unlink(thelinkage=l)
                        # now make and wire in a new one
                        resampler = RawResampleTo(format[0], format[1],
                                                  *self.params).activate()
                        self.addChildren(resampler)
                        linkages = [
                            self.link((self, "_data"), (resampler, "inbox")),
                            self.link((self, "_ctrl"), (resampler, "control")),
                            self.link((resampler, "outbox"),
                                      (self, "_resampled")),
                        ]

                    self.send(data['audio'], "_data")

            while self.dataReady("_resampled"):
                audio = self.recv("_resampled")
                data = {}
                data['type'] = 'audio'
                data['sample_rate'] = self.params[0]
                data['channels'] = self.params[1]
                data['format'] = format[2]
                data['audio'] = audio
                self.send(data, "outbox")

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, (producerFinished, shutdownMicroprocess)):
                    shutdown = True
                self.send(msg, "signal")

            if not shutdown:
                self.pause()
            yield 1

        if resampler:
            self.send(producerFinished(), "_ctrl")
            for linkage in linkages:
                self.unlink(thelinkage=linkage)
Beispiel #14
0
    def main(self):
        # possible enhancements - support ESMTP and associated extensions
        self.send("220 " + self.hostname + " ESMTP KamaeliaRJL\r\n", "outbox")
        self.doRSET()

        self.theirhostname = ""

        self.state = self.stateGetHELO

        while 1:
            if self.state == self.stateQuit:
                self.doQuit()
                self.killInterface()
                self.send(producerFinished(self), "signal")
                return

            yield 1
            if self.shouldShutdown():
                self.killInterface()
                self.send(producerFinished(self), "signal")
                return

            while self.dataFetch():
                pass

            msg = self.nextLine()
            while msg != None:
                if self.state == self.stateQuit:
                    self.doQuit()
                    self.killInterface()
                    self.send(producerFinished(self), "signal")
                    return

                newstate = self.state(msg)

                if self.waitinguponqueueconfirm:
                    print "SENDING MESSAGE"
                    while self.waitinguponqueueconfirm:
                        if self.dataReady("queueconfirm"):
                            msgid = self.recv("queueconfirm")
                            self.waitinguponqueueconfirm = False
                            break

                        self.pause()
                        yield 1
                    print "SENT MESSAGE"
                    self.send(
                        "250 Written safely to disk #" + str(msgid) + "\r\n",
                        "outbox")

                if newstate:
                    self.state = newstate

                msg = self.nextLine()
            else:
                self.pause()
Beispiel #15
0
    def main(self):
        # possible enhancements - support ESMTP and associated extensions
        self.send("220 " + self.hostname + " ESMTP KamaeliaRJL\r\n", "outbox")
        self.doRSET()        

        self.theirhostname = ""

        self.state = self.stateGetHELO

        while 1:
            if self.state == self.stateQuit:
                self.doQuit()
                self.killInterface()
                self.send(producerFinished(self), "signal")                
                return
                
            yield 1
            if self.shouldShutdown():
                self.killInterface()
                self.send(producerFinished(self), "signal")                
                return
            
            while self.dataFetch():
                pass
            
            msg = self.nextLine()
            while msg != None:
                if self.state == self.stateQuit:
                    self.doQuit()
                    self.killInterface()
                    self.send(producerFinished(self), "signal")
                    return
                
                newstate = self.state(msg)
                
                if self.waitinguponqueueconfirm:
                    print "SENDING MESSAGE"                
                    while self.waitinguponqueueconfirm:
                        if self.dataReady("queueconfirm"):
                            msgid = self.recv("queueconfirm")
                            self.waitinguponqueueconfirm = False
                            break
                        
                        self.pause()
                        yield 1
                    print "SENT MESSAGE"
                    self.send("250 Written safely to disk #" + str(msgid) + "\r\n", "outbox")
                    
                if newstate:
                    self.state = newstate

                msg = self.nextLine()
            else:
                self.pause()
Beispiel #16
0
    def main(self):
        keepconnectionopen = True
        while keepconnectionopen:
            yield 1
            while not self.anyReady():
                self.pause()
                yield 1
            while self.dataReady(
                    "control"):  # Control messages from the socket
                temp = self.recv("control")
                if isinstance(
                        temp, producerFinished
                ):  # Socket has stopped sending us data (can still send data to it)
                    self.send(
                        temp, "Psignal"
                    )  # pass on to the HTTP Parser. (eg could be a POST request)
#                    print "PRODUCER SHUTDOWN"

                elif isinstance(
                        temp,
                        shutdown):  # Socket is telling us connection is dead
                    self.send(shutdown(), "Psignal")
                    self.send(shutdown(), "Hsignal")
                    keepconnectionopen = False
#                    print "SOCKET DEAD"

            while self.dataReady(
                    "Pcontrol"):  # Control messages from the HTTP Parser
                temp = self.recv("Pcontrol")
                if isinstance(
                        temp, producerFinished
                ):  # HTTP Parser is telling us they're done parsing
                    pass  # XXXX Handling of shutdown messages from parser ???
                    #                    print "PARSER FINISHED"
                    self.send(temp, "Hsignal")  # Pass on to the HTTP Handler

            while self.dataReady(
                    "Hcontrol"):  # Control messages from the HTTP Handler
                temp = self.recv("Hcontrol")
                if isinstance(temp, producerFinished
                              ):  # Have finished sending data to the client
                    sig = producerFinished(self)  #
                    self.send(
                        sig, "Psignal"
                    )  # Make sure HTTP Parser is shutting down - (should send a "shutdown" message)
                    self.send(sig, "signal")
                    keepconnectionopen = False


#                    print "HTTP HANDLER DEAD"

        self.send(producerFinished(),
                  "signal")  # We're done, close the connection.
        yield 1  # And quit
Beispiel #17
0
    def main(self):
        resampler = None
        format = None
        shutdown = False
        while self.anyReady() or not shutdown:
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                
                if data['type'] == "audio":
                    newformat = (data['sample_rate'], data['channels'], data['format'])
                    if newformat != format:
                        format=newformat
                        # need new audio playback component
                        # first remove any old one
                        if resampler:
                            self.removeChild(resampler)
                            self.send(producerFinished(), "_ctrl")
                            for l in linkages:
                                self.unlink(thelinkage=l)
                        # now make and wire in a new one
                        resampler = RawResampleTo(format[0],format[1], *self.params).activate()
                        self.addChildren(resampler)
                        linkages = [ self.link( (self,"_data"), (resampler, "inbox") ),
                                     self.link( (self,"_ctrl"), (resampler, "control") ),
                                     self.link( (resampler,"outbox"), (self, "_resampled") ),
                                   ]
                
                    self.send(data['audio'], "_data")
            
            while self.dataReady("_resampled"):
                audio = self.recv("_resampled")
                data = {}
                data['type'] = 'audio'
                data['sample_rate'] = self.params[0]
                data['channels'] = self.params[1]
                data['format'] =  format[2]
                data['audio'] = audio
                self.send(data,"outbox")
            
            while self.dataReady("control"):
                msg=self.recv("control")
                if isinstance(msg, (producerFinished,shutdownMicroprocess)):
                    shutdown=True
                self.send(msg,"signal")
                
            if not shutdown:
                self.pause()
            yield 1

        if resampler:
            self.send(producerFinished(), "_ctrl")
            for linkage in linkages:
                self.unlink(thelinkage=linkage)
Beispiel #18
0
    def main(self):
        self.shutdownMsg = None
        self.canStop = False
        self.mustStop = False

        try:
            while 1:

                while self.dataReady("inbox"):
                    canStop, mustStop = self.checkShutdown()
                    if mustStop:
                        raise UserWarning("STOP")

                    # ok, so there is data waiting to be emitted, so now we must wait for the 'next' signal
                    while not self.dataReady("next"):
                        canStop, mustStop = self.checkShutdown()
                        if mustStop:
                            raise UserWarning("STOP")
                        self.pause()
                        yield 1
                    self.recv("next")

                    data = self.recv("inbox")
                    while 1:
                        try:
                            self.send(data, "outbox")
                            break
                        except noSpaceInBox:
                            canStop, mustStop = self.checkShutdown()
                            if mustStop:
                                raise UserWarning("STOP")
                            self.pause()
                            yield 1

                canStop, mustStop = self.checkShutdown()
                if canStop:
                    raise UserWarning("STOP")

                if not self.dataReady("inbox") and not self.dataReady(
                        "control"):
                    self.pause()

                yield 1

        except UserWarning:
            if self.shutdownMsg:
                self.send(self.shutdownMsg, "signal")
            else:
                self.send(producerFinished(), "signal")
            return

        self.send(producerFinished(), "signal")
    def main(self):
        self.shutdownMsg = None
        self.canStop = False
        self.mustStop = False

        try:
            while 1:
    
                while self.dataReady("inbox"):
                    canStop, mustStop = self.checkShutdown()
                    if mustStop:
                        raise "STOP"

                    # ok, so there is data waiting to be emitted, so now we must wait for the 'next' signal
                    while not self.dataReady("next"):
                        canStop, mustStop = self.checkShutdown()
                        if mustStop:
                            raise "STOP"
                        self.pause()
                        yield 1
                    self.recv("next")
    
                    data = self.recv("inbox")
                    while 1:
                        try:
                            self.send(data,"outbox")
                            break
                        except noSpaceInBox:
                            canStop, mustStop = self.checkShutdown()
                            if mustStop:
                                raise "STOP"
                            self.pause()
                            yield 1
    
                canStop, mustStop = self.checkShutdown()
                if canStop:
                    raise "STOP"

                if not self.dataReady("inbox") and not self.dataReady("control"):
                    self.pause()
                    
                yield 1
            
        except "STOP":
            if self.shutdownMsg:
                self.send(self.shutdownMsg,"signal")
            else:
                self.send(producerFinished(),"signal")
            return
                        
        self.send(producerFinished(),"signal")
Beispiel #20
0
 def main(self):
     timer = Timer().activate()
     self.addChildren(timer)
     self.link((self,"_toTimer"),(timer,"inbox"))
     self.link((timer,"outbox"),(self,"_fromTimer"))
     self.link((self,"_timerSignal"),(timer,"control"))
     
     for i in range(0,10):
         for _ in self.waitUntil( self.scheduler.time + 1.0): yield _
         self.send( "Waited, then output "+str(i),"outbox")
         
     yield 1
     self.send(producerFinished(), "_timerSignal")
     self.send(producerFinished(), "signal")
Beispiel #21
0
    def main(self):
        try:
            self.send(self.getCurrentChoice(), "outbox")
        except IndexError:
            pass

        done = False
        while not done:
            yield 1

            while self.dataReady("inbox"):
                send = True
                msg = self.recv("inbox")

                if msg == "SAME":
                    pass
                elif msg == "NEXT":
                    send = self.gotoNext()
                    if not send:
                        done = True
                        self.send(producerFinished(self), "signal")
                else:
                    send = False

                if send:
                    try:
                        self.send(self.getCurrentChoice(), "outbox")
                    except IndexError:
                        pass

            done = done or self.shutdown()
Beispiel #22
0
    def test_Unplugging(self):
        """Plug will unplug and shutdown when child component dies."""
        Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler()

        splitter = Splitter()
        splitter.activate()

        target = DummyComponent()
        plug = Plug(splitter, target).activate()

        execute = Axon.Scheduler.scheduler.run.main()

        for i in xrange(1, 100):
            execute.next()

        #send shutdown msg
        msg = producerFinished()
        target._deliver(msg, "control")

        for i in xrange(1, 100):
            execute.next()

        # verify it reached the target
        self.assert_(target.controllog == [msg])

        # verify the plug has shutdown
        self.assert_(plug._isStopped())

        # verify the plug has no linkages
        self.assert_(not plug.postoffice.linkages)

        # verify that splitter only has outboxes "outbox" and "signal" now
        self.assert_(len(splitter.outboxes) == 2)
        self.assert_("outbox" in splitter.outboxes)
        self.assert_("signal" in splitter.outboxes)
Beispiel #23
0
 def main(self):
     self.initialiseComponent()
     loop = True
     while loop:
         yield 1
         while self.dataReady("control"):
             temp = self.recv("control")
             if isinstance(temp, producerFinished):
                 self.send(temp, "mime-control")
             elif isinstance(temp, shutdown):
                 self.send(shutdown(), "mime-control")
                 self.send(shutdown(), "http-control")
                 #print "HTTPServer received shutdown"
                 loop = False
                 break
         
         while self.dataReady("mime-signal"):
             temp = self.recv("mime-signal")
             if isinstance(temp, producerFinished):
                 pass
                 #we don't need to care yet - wait 'til the request handler finishes
         
         while self.dataReady("http-signal"):
             temp = self.recv("http-signal")
             if isinstance(temp, producerFinished):
                 sig = producerFinished(self)
                 self.send(sig, "mime-control")                
                 self.send(sig, "signal")
                 loop = False
                 #close the connection
         
         self.pause()
             
     self.closeDownComponent()
Beispiel #24
0
    def main(self):
        yield self.initComponents()

        while 1:
            if self.dataReady("control"):
                mes = self.recv("control")
                
                if isinstance(mes, shutdownMicroprocess) or \
                        isinstance(mes, producerFinished):
                    self.send(producerFinished(), "signal")
                    break

            if self.dataReady("monitor"):
                url, comp = self.recv("monitor")
                comp.activate()
                newOut = self.addOutbox("monitoredOut")
                self.link((self, newOut), (comp, 'inbox'))
                self.addChildren(comp)
                self.urls.append((url, newOut))
                
            if self.dataReady("inbox"):
                self.recv("inbox")
                for url, targetOutbox in self.urls:
                    self.send(url, targetOutbox)

            if not self.anyReady():
                self.pause()
  
            yield 1
Beispiel #25
0
 def mainBody(self):
     """We check whether it's time to perform a new read, if it is, we
   read some data. If we get some data, we put it in out outbox
   "outbox", and to stdout (if debugging).
   If we had an error state (eg EOF), we return 0, stopping this component, otherwise
   we return 1 to live for another line/block.
   """
     try:
         if ((time.time() - self.time) > self.steptime):
             self.time = time.time()
             data = ""
             data = self.getData()
             if data:
                 assert self.debugger.note("ReadFileAdapter.main", 7,
                                           "Read data, writing to outbox")
                 self.send(
                     data,
                     "outbox")  # We kinda assume people are listening...
                 if self.debug:
                     sys.stdout.write(data)
                     sys.stdout.flush()
         return 1  # Continue looping since there may be more data
     except:
         sig = producerFinished(self)
         self.send(sig, "signal")
         return 0  # Finish looping, we've stopped reading
Beispiel #26
0
    def main(self):
        counter = 0
        while 1:
            counter += 1
            torrentfile = fopen(str(counter) + ".torrent")
            metafile = fopen("meta.txt")
            metafile.write(str(counter))
            metafile.close()

            resource = {
                "statuscode": "200",
                "data": u"<html><body>%d</body></html>" % counter,
                "incomplete": False,
                "type": "text/html"
            }
            receivingpost = False
            while receivingpost:
                while self.dataReady("inbox"):
                    msg = self.recv("inbox")
                    torrentfile.write(msg)
                while self.dataReady("control"):
                    msg = self.recv("control")
                    if isinstance(msg, producerFinished):
                        receivingpost = False

                if receivingpost:
                    yield 1
                    self.pause()

            torrentfile.close()
            self.send(resource, "outbox")
            self.send(producerFinished(self), "signal")
            Sessions[self.sessionid]["busy"] = False
            self.pause()
            yield 1
Beispiel #27
0
   def main(self):
      """Main loop."""
      try:
         self.send( self.getCurrentChoice(), "outbox")
      except IndexError:
         pass

      done = False
      while not done:
         yield 1

         while self.dataReady("inbox"):
            send = True
            msg = self.recv("inbox")

            if msg == "SAME":
               pass
            elif msg == "NEXT":
               send = self.gotoNext()
               if not send:
                   done = True
                   self.send( producerFinished(self), "signal")
            else:
               send = False

            if send:
               try:
                  self.send( self.getCurrentChoice(), "outbox")
               except IndexError:
                  pass

         done = done or self.shutdown()
         
         if not done:
             self.pause()
Beispiel #28
0
 def main(self):
     while len(self.messages) > 0:
         yield 1
         self.send(self.messages.pop(0), "outbox")
     yield 1
     self.send(producerFinished(self), "signal")
     return
Beispiel #29
0
 def testFilterOrder(self):
     feeds = []
     the_date        = time.gmtime()
     cur_year        = the_date[0]
     # One year after
     the_future_date = (cur_year + 1, ) + the_date[1:]
     # One year before
     the_past_date   = (cur_year - 1, ) + the_date[1:]
     
     feeds.extend(self.generateFeeds(2, self.NO_DATE,    'notime'))
     feeds.extend(self.generateFeeds(2, the_future_date, 'future'))
     feeds.extend(self.generateFeeds(2, the_past_date,   'past'))
     feeds.extend(self.generateFeeds(2, the_date,        'present'))
     feeds.extend(self.generateFeeds(2, self.NO_DATE,    'notime'))
     
     configObject = self.createConfigObject(5)
     self.put(configObject, 'config-inbox')
     
     for feed in feeds:
         self.put(feed, 'inbox')
     self.put(producerFinished(), "control")
     for _ in range(2):
         msg = self.get('outbox')
         self.assertEquals(cur_year + 1, msg['entry']['updated_parsed'][0])
     for _ in range(2):
         msg = self.get('outbox')
         self.assertEquals(cur_year    , msg['entry']['updated_parsed'][0])
     for _ in range(1):
         msg = self.get('outbox')
         self.assertEquals(cur_year - 1, msg['entry']['updated_parsed'][0])
     self.assertOutboxEmpty('outbox')
Beispiel #30
0
    def main(self):
        brokenClient = False
        self.handleConnect()
        self.gettingdata = False
        self.client_connected = True
        self.breakConnection = False

        while (not self.gettingdata) and (not self.breakConnection):
            yield WaitComplete(self.getline(), tag="_getline1")
            try:
                command = self.line.split()
            except AttributeError:
                brokenClient = True
                break
            self.handleCommand(command)
        if not brokenClient:
            if (not self.breakConnection):
                EndOfMessage = False
                self.netPrint('354 Enter message, ending with "." on a line by itself')
                while not EndOfMessage:
                    yield WaitComplete(self.getline(), tag="getline2")
                    if self.lastline():
                        EndOfMessage = True
                self.netPrint("250 OK id-deferred")

        self.send(producerFinished(),"signal")
        if not brokenClient:
            yield WaitComplete(self.handleDisconnect(),tag="_handleDisconnect")
        self.logResult()
Beispiel #31
0
   def main(self):
      """\
      This contains no user serviceable parts :-)

      Theory of operation is simple. It simply repeatedly asks the decoder
      object for audio. That decoded audio is sent to the component's outbox.
      If the decoder object responds with RETRY, the component retries.
      If the decoder object responds with NEEDDATA, the component waits
      for data on any inbox until some is available (from an inbox)
      """
      decoding = True
      producerDone = False
      while decoding:
         try:
            data = self.decoder._getAudio()
            self.send(data, "outbox")
         except "RETRY":
            pass
         except "NEEDDATA":
            while not (self.dataReady("inbox") > 0) and not (self.dataReady("control") >0):
               if not producerDone:
                  self.pause()
                  yield 1

            if self.dataReady("inbox"):
               dataToSend = self.recv("inbox")
               self.decoder.sendBytesForDecode(dataToSend)
            
            if self.dataReady("control"):
               shutdownMessage = self.recv("control")
               sig = producerFinished(self)
               self.send(sig, "signal")
               producerDone = True # Necessary given next?
               decoding = False
Beispiel #32
0
    def testFilterOrder(self):
        feeds = []
        the_date = time.gmtime()
        cur_year = the_date[0]
        # One year after
        the_future_date = (cur_year + 1, ) + the_date[1:]
        # One year before
        the_past_date = (cur_year - 1, ) + the_date[1:]

        feeds.extend(self.generateFeeds(2, self.NO_DATE, 'notime'))
        feeds.extend(self.generateFeeds(2, the_future_date, 'future'))
        feeds.extend(self.generateFeeds(2, the_past_date, 'past'))
        feeds.extend(self.generateFeeds(2, the_date, 'present'))
        feeds.extend(self.generateFeeds(2, self.NO_DATE, 'notime'))

        configObject = self.createConfigObject(5)
        self.put(configObject, 'config-inbox')

        for feed in feeds:
            self.put(feed, 'inbox')
        self.put(producerFinished(), "control")
        for _ in range(2):
            msg = self.get('outbox')
            self.assertEquals(cur_year + 1, msg['entry']['updated_parsed'][0])
        for _ in range(2):
            msg = self.get('outbox')
            self.assertEquals(cur_year, msg['entry']['updated_parsed'][0])
        for _ in range(1):
            msg = self.get('outbox')
            self.assertEquals(cur_year - 1, msg['entry']['updated_parsed'][0])
        self.assertOutboxEmpty('outbox')
Beispiel #33
0
    def test_doesNotPropagateShutdownMsg(self):
        """If a graphline's "signal" outbox is specified to be wired to a child component, the graphline will send any messages itself out of its "signal" outbox, before or after all children have terminated, even if a shutdownMicroprocess or producerFinished message was sent to its "control" inbox."""

        A = MockChild()
        B = MockChild()
        C = MockChild()
        self.setup_initialise(A=A,
                              B=B,
                              C=C,
                              linkages={
                                  ("A", "signal"): ("", "signal"),
                                  ("A", "outbox"): ("B", "control"),
                              })

        self.setup_activate()
        self.runFor(cycles=100)

        self.sendTo(producerFinished(), "control")
        self.sendTo(shutdownMicroprocess(), "control")

        self.runFor(cycles=100)
        self.assert_(self.graphline in self.scheduler.listAllThreads())

        self.assert_(not (self.dataReadyAt("signal")))

        for child in self.children.values():
            child.stopNow()

        self.runFor(cycles=100)

        self.assert_(not (self.dataReadyAt("signal")))
Beispiel #34
0
    def test_receivesShutdownAndPropagates2(self):
        """If a graphline's "control" inbox and "signal" outbox are not specified to be wired to a child component in the graphline then, if a any non shutdownMicroprocess message is sent to the "control" inbox, a producerFinished message will be sent on out of the "signal" outbox once all children have terminated."""

        A = MockChild()
        B = MockChild()
        C = MockChild()
        self.setup_initialise(A=A,
                              B=B,
                              C=C,
                              linkages={
                                  ("A", "outbox"): ("B", "control"),
                              })

        self.setup_activate()
        self.runFor(cycles=100)

        msg = producerFinished()
        self.sendTo(msg, "control")

        self.runFor(cycles=100)
        self.assert_(self.graphline in self.scheduler.listAllThreads())

        for child in self.children.values():
            child.stopNow()

        self.runFor(cycles=10)
        self.assert_(self.graphline not in self.scheduler.listAllThreads())

        self.assert_(self.dataReadyAt("signal"))
        recvd = self.recvFrom("signal")
        self.assert_(recvd != msg)
        self.assert_(isinstance(recvd, producerFinished))
Beispiel #35
0
def InactivityChassis(somecomponent, timeout=2, debug=False):
    """
    This convenience function will link a component up to an ActivityMonitor and
    a ResettableSender that will emit a producerFinished signal within timeout
    seconds if the component does not send any messages on its outbox or
    CreatorFeedback boxes.  To link the specified component to an external component
    simply link it to the returned chassis's outbox or CreatorFeedback outboxes.
    """
    linkages = {
        ("SHUTTERDOWNER", "outbox"): ("OBJ", "control"),
        ("self", "inbox"): ("OBJ", "inbox"),
        ("self", "control"): ("OBJ", "control"),
        ("self", "ReadReady"): ("OBJ", "ReadReady"),
        ("self", "SendReady"): ("OBJ", "SendReady"),
        ("OBJ", "outbox"): ("ACT", "inbox"),
        ("OBJ", "CreatorFeedback"): ("ACT", "inbox2"),
        #        ("OBJ","_selectorSignal"):("ACT","inbox3"),
        ("OBJ", "signal"): ("ACT", "control"),
        ("ACT", "observed"): ("SHUTTERDOWNER", "inbox"),
        ("ACT", "outbox"): ("self", "outbox"),
        ("ACT", "outbox2"): ("self", "CreatorFeedback"),
        #        ("ACT","outbox3"):("self","_selectorSignal"),
        ("ACT", "signal"): ("self", "signal"),
    }
    return Graphline(OBJ=somecomponent,
                     ACT=ActivityMonitor(),
                     SHUTTERDOWNER=ResettableSender(debug=debug,
                                                    message=producerFinished(),
                                                    timeout=timeout),
                     linkages=linkages)
Beispiel #36
0
    def main(self):
        for item in self.sequence:
            
            if isinstance(item,str):
                print item
                continue
            
            comp = item

            self.addChildren(comp)
            comp.activate()

            linkages = [
                self.link((comp,"outbox"),(self,"outbox"),passthrough=2),
                self.link((self,"inbox"),(comp,"inbox"),passthrough=1),
                # not linking signal-control, since we don't want downstream
                # component to terminate prematurely
            ]

            while not self.childrenDone():
                self.pause()
                yield 1

            for linkage in linkages:
                self.unlink(thelinkage=linkage)

        self.send(producerFinished(self),"signal")
Beispiel #37
0
 def testLinearShutdown(self):
     """A producerFinished() shutdown signal will be handled properly."""
     self.setup_tests()
     self.sendToControl(producerFinished())
     self.runUntil()
     self.failUnless(isinstance(self.recvSignal(), producerFinished))
     self.checkStop(stopped=True)
Beispiel #38
0
 def main(self):
     counter = 0
     while 1:
         counter += 1
         torrentfile = fopen(str(counter) + ".torrent")
         metafile = fopen("meta.txt")
         metafile.write(str(counter))
         metafile.close()
         
         resource = {
             "statuscode" : "200",
             "data" : u"<html><body>%d</body></html>" % counter,
             "incomplete" : False,
             "type"       : "text/html"
         }
         receivingpost = False
         while receivingpost:
             while self.dataReady("inbox"):
                 msg = self.recv("inbox")
                 torrentfile.write(msg)
             while self.dataReady("control"):
                 msg = self.recv("control")
                 if isinstance(msg, producerFinished):
                     receivingpost = False
             
             if receivingpost:
                 yield 1
                 self.pause()
         
         torrentfile.close()
         self.send(resource, "outbox")
         self.send(producerFinished(self), "signal")
         Sessions[self.sessionid]["busy"] = False
         self.pause()
         yield 1
Beispiel #39
0
    def test_SplitterShutdown(self):
        """If producerFinished or shutdownMicroprocess is received on the 'control' inbox they are passed on and the component shuts down"""
        for msg in [producerFinished(self), shutdownMicroprocess(self)]:
            split = Splitter()
            Dummy = Axon.Component.component()
            split.link((split, "outbox"), (Dummy, "inbox"))
            split.link((split, "signal"), (Dummy, "control"))
            split.activate()

            for _ in xrange(0,10):
                split.next()
            self.assert_(0==len(split.outboxes["outbox"]))
            self.assert_(0==len(split.outboxes["signal"]))

            split._deliver( msg, "control" )
            try:
                for _ in xrange(0,10):
                    split.next()
                self.fail()
            except StopIteration:
                pass
            self.assert_(0==len(split.outboxes["outbox"]))
            self.assert_(1==len(split.outboxes["signal"]))
#            received = split._collect("signal")
            received = Dummy.recv("control")
            self.assert_( msg == received )
Beispiel #40
0
    def _processMainInbox(self, msg):
        protocol_component = self.Protocol(peer=msg.from_jid)
        protocol_component.activate()
        out_boxname = self.addOutbox("out_%s" % (protocol_component.name))
        #print 'added ' + out_boxname
        sig_boxname = self.addOutbox("sig_%s" % (protocol_component.name))
        #print 'added ' + sig_boxname
        in_boxname = self.addInbox("in_%s" % (protocol_component.name))
        #print 'added ' + in_boxname
        ctl_boxname = self.addInbox("ctl_%s" % (protocol_component.name))
        #print 'added ' + ctl_boxname

        tracked_data = {
            'in': in_boxname,
            'ctl': ctl_boxname,
            'out': out_boxname,
            'sig': sig_boxname,
            'msg': msg,
        }

        self.tracked_components[protocol_component.name] = tracked_data

        self.link((self, out_boxname), (protocol_component, 'inbox'))
        self.link((protocol_component, 'outbox'), (self, in_boxname))
        self.link((protocol_component, 'signal'), (self, ctl_boxname))

        request = self.normalizeMsgBodies(msg)
        #printable_request = request
        #print 'received ' + printable_request

        self.send(request, out_boxname)
        self.send(producerFinished(self), sig_boxname)
Beispiel #41
0
    def test_doesNotPropagateShutdownMsg(self):
        """If a graphline's "signal" outbox is specified to be wired to a child component, the graphline will send any messages itself out of its "signal" outbox, before or after all children have terminated, even if a shutdownMicroprocess or producerFinished message was sent to its "control" inbox."""
        
        A=MockChild()
        B=MockChild()
        C=MockChild()
        self.setup_initialise(
            A=A, B=B, C=C,
            linkages={ 
                ("A","signal"):("","signal"),
                ("A","outbox"):("B","control"), 
            })

        self.setup_activate()
        self.runFor(cycles=100)
        
        self.sendTo(producerFinished(), "control")
        self.sendTo(shutdownMicroprocess(), "control")
        
        self.runFor(cycles=100)
        self.assert_(self.graphline in self.scheduler.listAllThreads())
        
        self.assert_(not(self.dataReadyAt("signal")))
        
        for child in self.children.values():
            child.stopNow()

        self.runFor(cycles=100)
        
        self.assert_(not(self.dataReadyAt("signal")))
Beispiel #42
0
    def main(self):
        while 1:
            if self.dataReady("control"):
                mes = self.recv("control")
                
                if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished):
                    self.send(producerFinished(), "signal")
                    break

            if self.dataReady("inbox"):
                r = self.recv('inbox')
                if r.registered:
                    print "'%s' is already a registered username." % self.username
                elif self.registration_id == r.stanza_id:
                    print "'%s' is now a registered user."\
                        "Please restart the client without the register flag." % self.username
                else:
                    if 'username' in r.infos and 'password' in r.infos:
                        self.registration_id = generate_unique()
                        r = Registration(type=u'set', stanza_id=self.registration_id)
                        r.infos[u'username'] = self.username
                        r.infos[u'password'] = self.password
                        self.send(r, 'outbox')
                
            if self.dataReady("error"):
                r = self.recv('error')
                print r.error

            if not self.anyReady():
                self.pause()
  
            yield 1
Beispiel #43
0
    def test_receivesShutdownAndPropagates23(self):
        """If a graphline's "control" inbox is specified to be wired to a child component, but its "signal" outbox is not then, irrespective of what message (eg. shutdownMicroprocess) is sent to the "control" inbox, a producerFinished message will be sent on out of the "signal" outbox once all children have terminated."""

        possibleMessages = [ producerFinished(), shutdownMicroprocess(), "flurble" ]
        
        for msg in possibleMessages:
            A=MockChild()
            B=MockChild()
            C=MockChild()
            self.setup_initialise(
                A=A, B=B, C=C,
                linkages={
                    ("","control"):("A","control"),
                    ("A","outbox"):("B","control"), 
                })

            self.setup_activate()
            self.runFor(cycles=100)
            
            self.sendTo(msg,"control")
            
            self.runFor(cycles=100)
            self.assert_(self.graphline in self.scheduler.listAllThreads())
            
            for child in self.children.values():
                child.stopNow()

            self.runFor(cycles=10)
            self.assert_(self.graphline not in self.scheduler.listAllThreads())
            
            self.assert_(self.dataReadyAt("signal"))
            recvd=self.recvFrom("signal")
            self.assert_(recvd != msg)
            self.assert_(isinstance(recvd,producerFinished))
Beispiel #44
0
    def test_queuedNextsFinishedIfProducerFinished(self):
        """If a producerFinished() is received, but there are still messages queued on the 'next' inbox, those messages are processed (and children created) first. *Then* the Carousel terminates."""

        self.setup_test()

        self.runFor(cycles=5)
        self.sendToNext("BLAH")
        self.runFor(cycles=50)

        self.sendToControl(producerFinished())
        for i in range(1, 10):
            self.sendToNext("BLAH")

        self.runFor(cycles=1000)
        self.assert_(len(self.children) == 1)
        self.assert_(not self.carousel._isStopped())

        for i in range(0, 9):
            self.assert_(self.children[i].wasActivated)
            self.assert_(not self.children[i]._isStopped())
            msg = self.children[i].recv("control")
            self.assert_(
                isinstance(msg, (shutdownMicroprocess, producerFinished)))
            self.children[i].stopNow = True

            while len(self.children) <= i + 1:
                self.runFor(cycles=1)

            while not self.children[-1].wasActivated:
                self.runFor(cycles=1)
Beispiel #45
0
    def test_receivesShutdownAndPropagates2(self):
        """If a graphline's "control" inbox and "signal" outbox are not specified to be wired to a child component in the graphline then, if a any non shutdownMicroprocess message is sent to the "control" inbox, a producerFinished message will be sent on out of the "signal" outbox once all children have terminated."""

        A=MockChild()
        B=MockChild()
        C=MockChild()
        self.setup_initialise(
            A=A, B=B, C=C,
            linkages={ ("A","outbox"):("B","control"), 
            })

        self.setup_activate()
        self.runFor(cycles=100)
        
        msg=producerFinished()
        self.sendTo(msg,"control")
        
        self.runFor(cycles=100)
        self.assert_(self.graphline in self.scheduler.listAllThreads())
        
        for child in self.children.values():
            child.stopNow()

        self.runFor(cycles=10)
        self.assert_(self.graphline not in self.scheduler.listAllThreads())
        
        self.assert_(self.dataReadyAt("signal"))
        recvd=self.recvFrom("signal")
        self.assert_(recvd != msg)
        self.assert_(isinstance(recvd,producerFinished))
Beispiel #46
0
        def test_smokeTest5(self):
            import random
            X = klass()

            Dummy = Axon.Component.component()
            X.link((X, "outbox"),(Dummy, "inbox"))
            X.link((X, "signal"),(Dummy, "control"))

            X.activate()
            shutdown_message = producerFinished()
            X._deliver(shutdown_message,"control")

            componentExit = False
            for i in xrange(random.randrange(0,2000)):
                try:
                    X.next()
                except StopIteration:
                    componentExit = True
                    break
            try:
#                Y = X._collect("signal")
                Y = Dummy.recv("control")

                self.assertEqual(shutdown_message, Y)
            except IndexError:
                self.fail("Shutdown Message should be passed on")
Beispiel #47
0
 def main(self):
     while True:            
         while self.dataReady("inbox"):
             data = self.recv("inbox")
             self.ordered_entries.extend([
                                     {
                                         'feed'     : data.feed,
                                         'entry'    : x,
                                         'encoding' : data.encoding
                                     } for x in data.entries
                     ])
             self.ordered_entries.sort(_cmp_entries)
             
             self.checkConfig()
             if self.config is not None:
                 self.ordered_entries = self.ordered_entries[:self.config.maxPostNumber]
             
         mustStop, providerFinished = self.checkControl()
         if mustStop:
             self.send(mustStop,"signal")
             return
             
         if providerFinished is not None:
                 for entry in self.ordered_entries:
                     self.send(entry, 'outbox')
                 yield 1
                 self.send(producerFinished(self), 'signal')
                 return
             
         if not self.anyReady():
             self.pause()
             
         yield 1
Beispiel #48
0
    def main(self):
        for item in self.sequence:
            
            if isinstance(item,str):
                print (item)
                continue
            
            comp = item

            self.addChildren(comp)
            comp.activate()

            linkages = [
                self.link((comp,"outbox"),(self,"outbox"),passthrough=2),
                self.link((self,"inbox"),(comp,"inbox"),passthrough=1),
                # not linking signal-control, since we don't want downstream
                # component to terminate prematurely
            ]

            while not self.childrenDone():
                self.pause()
                yield 1

            for linkage in linkages:
                self.unlink(thelinkage=linkage)

        self.send(producerFinished(self),"signal")
Beispiel #49
0
 def mainBody(self):
     """All the interesting work has been done by linking the file reader's output
   to our output"""
     if self.dataReady("_fromfile"):
         temp = self.recv("_fromfile")
         self.send(temp)
         return 1
     if self.dataReady("_sigfromfile"):
         temp = self.recv("_sigfromfile")
         self.send(temp, "signal")
     if self.dataReady("inbox"):
         temp = self.recv("inbox")
         self.send(temp, "_pass")
     if self.dataReady("_frommime"):
         filename = self.recv("_frommime")
         try:
             file = open(filename, 'r')
             close(file)
         except Exception, e:
             msg = 'HTTP/1.0 404 "Not Found\n\n"'
             self.send(msg)
             self.send(producerFinished(self), "signal")
             if crashAndBurn["error404"]:
                 raise e
             return 0
         msg = 'HTTP/1.0 200 "OK\n\n"'
         self.send(msg)
         self.rfa = ReadFileAdapter(filename=filename, readmode="bitrate")
         self.link(source=(self.rfa, "outbox"), sink=(self, "_fromfile"))
         self.link(source=(self.rfa, "signal"), sink=(self, "_sigfromfile"))
         self.addChildren(self.rfa)
         #         self.send(str(theData), "outbox")
         #         sig = producerFinished(self)
         #         self.send(sig, "signal")
         return [self.rfa]
Beispiel #50
0
    def main(self):
        while True:
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                self.ordered_entries.extend([{
                    'feed': data.feed,
                    'entry': x,
                    'encoding': data.encoding
                } for x in data.entries])
                self.ordered_entries.sort(_cmp_entries)

                self.checkConfig()
                if self.config is not None:
                    self.ordered_entries = self.ordered_entries[:self.config.
                                                                maxPostNumber]

            mustStop, providerFinished = self.checkControl()
            if mustStop:
                self.send(mustStop, "signal")
                return

            if providerFinished is not None:
                for entry in self.ordered_entries:
                    self.send(entry, 'outbox')
                yield 1
                self.send(producerFinished(self), 'signal')
                return

            if not self.anyReady():
                self.pause()

            yield 1
Beispiel #51
0
 def test_queuedNextsFinishedIfProducerFinished(self):
     """If a producerFinished() is received, but there are still messages queued on the 'next' inbox, those messages are processed (and children created) first. *Then* the Carousel terminates."""
     
     self.setup_test()
     
     self.runFor(cycles=5)
     self.sendToNext("BLAH")
     self.runFor(cycles=50)
     
     self.sendToControl(producerFinished())
     for i in range(1,10):
         self.sendToNext("BLAH")
         
     self.runFor(cycles=1000)
     self.assert_(len(self.children)==1)
     self.assert_(not self.carousel._isStopped())
     
     for i in range(0,9):
         self.assert_(self.children[i].wasActivated)
         self.assert_(not self.children[i]._isStopped())
         msg=self.children[i].recv("control")
         self.assert_(isinstance(msg,(shutdownMicroprocess,producerFinished)))
         self.children[i].stopNow=True
         
         while len(self.children)<=i+1:
             self.runFor(cycles=1)
             
         while not self.children[-1].wasActivated:
             self.runFor(cycles=1)
Beispiel #52
0
def InactivityChassis(somecomponent, timeout=2, debug=False):
    """
    This convenience function will link a component up to an ActivityMonitor and
    a ResettableSender that will emit a producerFinished signal within timeout
    seconds if the component does not send any messages on its outbox or
    CreatorFeedback boxes.  To link the specified component to an external component
    simply link it to the returned chassis's outbox or CreatorFeedback outboxes.
    """
    linkages = {
        ("SHUTTERDOWNER","outbox"):("OBJ","control"),

        ("self","inbox")    :("OBJ","inbox"),
        ("self","control")  :("OBJ","control"),
        ("self","ReadReady"):("OBJ","ReadReady"),
        ("self","SendReady"):("OBJ","SendReady"),

        ("OBJ","outbox"):("ACT","inbox"),
        ("OBJ","CreatorFeedback"):("ACT","inbox2"),
#        ("OBJ","_selectorSignal"):("ACT","inbox3"),
        ("OBJ","signal"):("ACT","control"),

        ("ACT","observed"):("SHUTTERDOWNER","inbox"),

        ("ACT","outbox") :("self","outbox"),
        ("ACT","outbox2"):("self","CreatorFeedback"),
#        ("ACT","outbox3"):("self","_selectorSignal"),
        ("ACT","signal") :("self","signal"),
    }
    return Graphline(
        OBJ=somecomponent,
        ACT=ActivityMonitor(),
        SHUTTERDOWNER=ResettableSender(debug=debug, message=producerFinished(), timeout=timeout),
        linkages = linkages
    )
Beispiel #53
0
    def main(self):
        """ Initialize the connection, and send the start-up message
        """
        self.readbuffer = self.Buffer()
        connection = self.Client(self.host, self.port, delay=self.delay)
        self.addChildren(connection)
        self.link((self, "request"), (connection, "inbox"))
        self.link((connection, "outbox"), (self, "response"))
        self.link((self, "connectionsignal"), (connection, "control"))
        self.link((connection, "signal"), (self, "connectioncontrol"))
        connection.activate()
        # send start-up
        self.request(SednaRequest(code=se.SEDNA_START_UP))
        self.pause()
        yield 1
        #yield 1
        # Now we loop.
        while not self.shutdown():
            self.pause()
            yield 1
            if self.dataReady("response"):
                self.handleresponses()
            # don't handle anything from the inbox until we are authenticated.
            while self.authenticated and self.dataReady("inbox"):
                self.handleinputs()

        # we are in shutdown.
        self.removeChild(self.children[0])
        self.send(producerFinished(self), "signal")
Beispiel #54
0
    def mainBody(self):
        #      print "ClientProtocolHandler: Checking mail..."

        if self.dataReady("_displayFinished"):
            print "ClientProtocolHandler: Message received! (_displayFinished)"
            self.message = self.recv("_displayFinished")

            if isinstance(self.message, producerFinished):
                self.send(producerFinished("Done"), "signal")
                return 0
            else:
                print "ClientProtocolHandler: Message from _displayFinished is..."
                print self.message

        if self.dataReady("control"):
            print "ClientProtocolHandler: Message received! (control)"
            self.controlMessage = self.recv("control")

            if isinstance(self.controlMessage,
                          Kamaelia.KamaeliaIPC.socketShutdown
                          ) or self.controlMessage == "StoppedThread":
                self.send(self.controlMessage, "_filteredControlMessages")
            else:
                print "ClientProtocolHandler: Message from control is..."
                print self.controlMessage
        return 1
Beispiel #55
0
 def main(self):
     theCat = coordinatingassistanttracker.getcat()
     service, inboxname = theCat.retrieveService(self.service)
     self.link((self, "todb"), (service, inboxname))
     # send self and my inbox name to the cursor server
     self.send((self, "inbox"), "todb")
     while 1:
         self.pause()
         yield 1
         while self.dataReady("control"):
             msg = self.recv("control")
             if isinstance(msg, shutdownMicroprocess):
                 self.send(msg, "signal")
                 return
             else:
                 self.send(msg, "signal")
         if self.dataReady("inbox"):
             conn = self.recv()
             if isinstance(conn, self.cursortype):
                 self.send(conn)
             else:
                 raise ValueError("Expected %s, got %s" %
                                  (self.cursortype, conn))
             self.send(producerFinished(), "signal")
             self.unlink()
             return
Beispiel #56
0
    def test_Unplugging(self):
        """Plug will unplug and shutdown when child component dies."""
        Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler()

        splitter = Splitter()
        splitter.activate()

        target = DummyComponent()
        plug = Plug(splitter, target).activate()

        execute = Axon.Scheduler.scheduler.run.main()

        for i in xrange(1,100):
            execute.next()

        #send shutdown msg
        msg = producerFinished()
        target._deliver(msg, "control")

        for i in xrange(1,100):
            execute.next()

        # verify it reached the target
        self.assert_(target.controllog == [msg])

        # verify the plug has shutdown
        self.assert_(plug._isStopped())

        # verify the plug has no linkages
        self.assert_(not plug.postoffice.linkages)

        # verify that splitter only has outboxes "outbox" and "signal" now
        self.assert_( len(splitter.outboxes) == 2)
        self.assert_( "outbox" in splitter.outboxes)
        self.assert_( "signal" in splitter.outboxes)
Beispiel #57
0
    def main(self):
        while True:
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                self.parsingXml(data)

            # If the general config has been parsed, send it
            if self.config is not None:
                self.send(self.config, 'config-outbox')
                self.config = None

            # Send the parsed feeds
            while len(self.feeds) > 0:
                for feed in self.feeds:
                    self.send(feed, "feeds-outbox")
                self.feeds = []

            # If we're done, finish
            if self.finished:
                self.send(producerFinished(self), "signal")
                return

            if self.dataReady("control"):
                data = self.recv("control")
                self.send(data, "signal")
                return

            if not self.anyReady():
                self.pause()

            yield 1