def Logger(channel, formatter=TimedOutformat, name=None, logdir="", **irc_args): """\ Logger(channel, **kwargs) -> Prefab that links the IRC components to BasicLogger and two Carousel-encapsulated AppendingFileWriters Keyword arguments: - formatter -- formatter to run incoming messages from IRC_Client through before writing to the log. Default TimedOutformat. - name -- nickname of the loggerbot. Default is the default name defined in BasicLogger. - logdir -- directory logs are to be put into. Default is the directory this module is in. - **irc_args -- pointer to a dictionary containing arguments for SimpleIRCClientPrefab """ return Graphline(irc=SimpleIRCClientPrefab(**irc_args), logger=BasicLogger(channel, formatter=formatter, name=name, logdir=logdir), log=Carousel(AppendingFileWriter), info=Carousel(AppendingFileWriter), linkages={ ("logger", "irc"): ("irc", "inbox"), ("irc", "outbox"): ("logger", "inbox"), ("logger", "log_next"): ("log", "next"), ("logger", "outbox"): ("log", "inbox"), ("logger", "info_next"): ("info", "next"), ("logger", "system"): ("info", "inbox"), })
def setup_test(self, **args): self.children = [] self.scheduler = scheduler() scheduler.run = self.scheduler if "componentFactory" not in args: def defaultFactory(arg, parent=self): child = MockChild(self.children, arg) return child args["componentFactory"] = defaultFactory self.carousel = Carousel(**args) self.inSrc = Dummy() self.inSrc.link((self.inSrc, "outbox"), (self.carousel, "inbox")) self.inSrc.link((self.inSrc, "signal"), (self.carousel, "control")) self.outDest = Dummy() self.outDest.link((self.carousel, "outbox"), (self.outDest, "inbox")) self.outDest.link((self.carousel, "signal"), (self.outDest, "control")) self.nextFbk = Dummy() self.nextFbk.link((self.carousel, "requestNext"), (self.nextFbk, "inbox")) self.nextFbk.link((self.nextFbk, "outbox"), (self.carousel, "next")) self.carousel.activate(Scheduler=self.scheduler) self.inSrc.activate(Scheduler=self.scheduler) self.outDest.activate(Scheduler=self.scheduler) self.nextFbk.activate(Scheduler=self.scheduler) self.run = self.scheduler.main()
def Logger(channel, formatter=None, name=None, logdir=None, **irc_args): return Graphline(irc = SimpleIRCClientPrefab(**irc_args), logger = BasicLogger(channel), log = Carousel(SimpleFileWriter), info = Carousel(SimpleFileWriter), linkages = {("logger", "irc") : ("irc", "inbox"), ("irc", "outbox") : ("logger", "inbox"), ("logger", "log_next") : ("log", "next"), ("logger", "outbox") : ("log", "inbox"), ("logger", "info_next") : ("info", "next"), ("logger", "system") : ("info", "inbox"), } )
def __init__(self): """Create and link to a carousel object""" super(SimpleHTTPClient, self).__init__() #AttachConsoleToDebug(self) self.debug("SimpleHTTPClient.__init__()") # now create our Carousel subcomponent self.carousel = Carousel(componentFactory=makeSSHTTPClient) self.addChildren(self.carousel) self.link((self, "_carouselnext"), (self.carousel, "next")) self.link((self, "_carouselsignal"), (self.carousel, "control")) self.link((self.carousel, "outbox"), (self, "_carouselinbox")) self.link((self.carousel, "requestNext"), (self, "_carouselready"))
def createPosts2fileManager(self, channels_plugsplitter, feeds_plugsplitter, posts_plugsplitter, config_plugsplitter, templateField, outputFileField): return Graphline( CHANNELS_SUBSCRIBER=self.subscribeToPlugsplitter( channels_plugsplitter), FEEDS_SUBSCRIBER=self.subscribeToPlugsplitter(feeds_plugsplitter), POSTS_SUBSCRIBER=self.subscribeToPlugsplitter(posts_plugsplitter), CONFIG_SUBSCRIBER=self.subscribeToPlugsplitter( config_plugsplitter), POSTS2FILE=KamTemplateProcessor(templateField, outputFileField), FILE_WRITER=Carousel(SimpleFileWriter), linkages={ ('FEEDS_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'feeds-inbox'), ('POSTS_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'posts-inbox'), ('CONFIG_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'config-inbox'), ('CHANNELS_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'channels-inbox'), ('POSTS2FILE', 'outbox'): ('FILE_WRITER', 'inbox'), ('POSTS2FILE', 'create-output'): ('FILE_WRITER', 'next'), # Signals ('POSTS_SUBSCRIBER', 'signal'): ('POSTS2FILE', 'control'), ('POSTS2FILE', 'signal'): ('FILE_WRITER', 'control'), })
def setup_test(self, **args): self.children=[] self.scheduler = scheduler() scheduler.run = self.scheduler if "componentFactory" not in args: def defaultFactory(arg,parent=self): child = MockChild(self.children, arg) return child args["componentFactory"]=defaultFactory self.carousel = Carousel(**args) self.inSrc = Dummy() self.inSrc.link((self.inSrc,"outbox"), (self.carousel,"inbox")) self.inSrc.link((self.inSrc,"signal"), (self.carousel,"control")) self.outDest = Dummy() self.outDest.link((self.carousel,"outbox"), (self.outDest,"inbox")) self.outDest.link((self.carousel,"signal"), (self.outDest,"control")) self.nextFbk = Dummy() self.nextFbk.link((self.carousel,"requestNext"), (self.nextFbk,"inbox")) self.nextFbk.link((self.nextFbk,"outbox"), (self.carousel,"next")) self.carousel.activate(Scheduler=self.scheduler) self.inSrc.activate(Scheduler=self.scheduler) self.outDest.activate(Scheduler=self.scheduler) self.nextFbk.activate(Scheduler=self.scheduler) self.run = self.scheduler.main()
def __init__(self, channel, formatter=outformat, name="jinnaslogbot", logdir=""): super(BasicLogger, self).__init__() self.channel = channel self.format = formatter self.name = name self.logdir = logdir.rstrip('/') or os.getcwd() self.logdir = self.logdir + '/' self.logname = "" self.infoname = "" Graphline(log = Carousel(SimpleFileWriter), info = Carousel(SimpleFileWriter), logger = self, linkages = {("logger", "log_next") : ("log", "next"), ("logger", "info_next") : ("info", "next"), ("logger", "outbox") : ("log", "inbox"), ("logger", "system") : ("info", "inbox"), }).activate()
def repeatingFile(): def rfa_factory(_): return RateControlledFileReader("junction.ts",readmode="bytes",rate=18000000/8,chunksize=2048) return Graphline(CAROUSEL=Carousel(rfa_factory, make1stRequest=True), linkages = { ("CAROUSEL","requestNext") : ("CAROUSEL","next"), ("CAROUSEL","outbox") : ("self", "outbox"), ("CAROUSEL","signal") : ("self", "signal"), }, )
def __ReusableFileReader(readmode): # File name here is passed to the this file reader factory every time # the file reader is started. The /reason/ for this is due to the carousel # can potentially pass different file names through each time. In essence, # this allows the readfile adaptor to be /reusable/ print "Wibble" def PromptedFileReaderFactory(filename): return PromptedFileReader(filename=filename, readmode=readmode) return Carousel(PromptedFileReaderFactory)
def __init__(self, channel, formatter=outformat, name="jinnaslogbot", logdir=""): """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" super(BasicLogger, self).__init__() self.channel = channel self.format = formatter or outformat #in case we get passed in None self.name = name or "jinnaslogbot" #" self.logdir = logdir.rstrip('/') or os.getcwd() self.logdir = self.logdir + '/' self.logname = "" self.infoname = "" Graphline(log=Carousel(SimpleFileWriter), info=Carousel(SimpleFileWriter), logger=self, linkages={ ("logger", "log_next"): ("log", "next"), ("logger", "info_next"): ("info", "next"), ("logger", "outbox"): ("log", "inbox"), ("logger", "system"): ("info", "inbox"), }).activate()
def TunablePublisher(initial_publishto=None): def makePublisher(meta): return PublishTo(meta) structure = { "TUNER": Carousel(makePublisher), "linkages": { ("self", "inbox"): ("TUNER", "inbox"), # To publish! ("self", "next"): ("TUNER", "next"), } } if initial_publishto != None: structure["INITIAL"] = OneShot(initial_publishto) structure["linkages"]["INITIAL", "outbox"] = ("TUNER", "next") return Graphline(**structure)
def TunableSubscriber(initial_subscription=None): def makeSubscriber(meta): return SubscribeTo(meta) structure = { "TUNER": Carousel(makeSubscriber), "linkages": { ("self", "inbox"): ("TUNER", "next"), ("TUNER", "outbox"): ("self", "outbox"), } } if initial_subscription != None: structure["INITIAL"] = OneShot(initial_subscription) structure["linkages"]["INITIAL", "outbox"] = ("TUNER", "next") return Graphline(**structure)
def makePlayer(mp3filename): print mp3filename return Graphline(READ=RateControlledFileReader(mp3filename, readmode="bytes", rate=256000 / 8), DECODE=Decoder("mp3"), OUTPUT=Carousel(makeAudioOutput), linkages={ ("READ", "outbox"): ("DECODE", "inbox"), ("DECODE", "outbox"): ("OUTPUT", "inbox"), ("DECODE", "format"): ("OUTPUT", "next"), ("", "control"): ("READ", "control"), ("READ", "signal"): ("DECODE", "control"), ("DECODE", "signal"): ("OUTPUT", "control"), ("OUTPUT", "signal"): ("", "signal"), })
def ChannelTranscoder(service_id, mencoder_options, dir_prefix): # BBC ONE def transcoder_factory(eit): print "transcoder factory called with eit:\n"+str(eit)+"\n" return ProgrammeTranscoder(eit, mencoder_options, dir_prefix) return Graphline( PROG_CODER = Carousel( transcoder_factory ), EIT_PARSE = EITParsing(service_id), DEMUX = EITDemux(), linkages = { ("self","inbox") : ("DEMUX","inbox"), ("DEMUX","outbox") : ("PROG_CODER","inbox"), # forward video and audio packets to coder ("DEMUX","_eit_") : ("EIT_PARSE", "inbox"), # forward eit packets to eit parsing ("EIT_PARSE", "outbox") : ("PROG_CODER", "next"), # eit programme junction events cause new transcoding to start } )
def ReusableFileReader(readmode): """\ ReusableFileReader(readmode) -> reusable file reader component. A file reading component that can be reused. Based on a Carousel - send a filename to the "next" inbox to start reading from that file. Must be prompted by another component - send the number of bytes/lines to read to the "inbox" inbox. Keyword arguments: - readmode = "bytes" or "lines" """ def PromptedFileReaderFactory(filename): """PromptedFileReaderFactory(filename) -> new PromptedFileReader component""" return PromptedFileReader(filename=filename, readmode=readmode) return Carousel(PromptedFileReaderFactory)
def RateControlledReusableFileReader(readmode): """\ RateControlledReusableFileReader(readmode) -> rate controlled reusable file reader component. A file reading component that can be reused. Based on a Carousel - send (filename, rateargs) to the "next" inbox to start reading from that file at the specified rate. - rateargs are the arguments for a ByteRate_RequestControl component. Keyword arguments: - readmode = "bytes" or "lines" """ def RateControlledFileReaderFactory(args): """RateControlledFileReaderFactory((filename,rateargs)) -> new RateControlledFileReader component""" filename, rateargs = args return RateControlledFileReader(filename, readmode, **rateargs) return Carousel( RateControlledFileReaderFactory )
## Copyright (C) 2007 British Broadcasting Corporation and Kamaelia Contributors(1) ## All Rights Reserved. ## from Kamaelia.Chassis.Carousel import Carousel from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.Util.Chooser import Chooser from Kamaelia.UI.Pygame.Button import Button from Kamaelia.UI.Pygame.Text import TextDisplayer from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor files = ["1.txt", "2.txt", "3.txt", "4.txt"] def makeFileReader(filename): return ReadFileAdaptor(filename=filename) Graphline(NEXT=Button(caption="Next", msg="NEXT", position=(72, 8)), PREVIOUS=Button(caption="Previous", msg="PREV", position=(8, 8)), CHOOSER=Chooser(items=files), READER=Carousel(componentFactory=makeFileReader), DISPLAY=TextDisplayer(position=(20, 90), screen_width=800, screen_height=600), linkages={ ("NEXT", "outbox"): ("CHOOSER", "inbox"), ("PREVIOUS", "outbox"): ("CHOOSER", "inbox"), ("CHOOSER", "outbox"): ("READER", "next"), ("READER", "outbox"): ("DISPLAY", "inbox"), }).run()
class Test_Carousel(unittest.TestCase): def setup_test(self, **args): self.children = [] self.scheduler = scheduler() scheduler.run = self.scheduler if "componentFactory" not in args: def defaultFactory(arg, parent=self): child = MockChild(self.children, arg) return child args["componentFactory"] = defaultFactory self.carousel = Carousel(**args) self.inSrc = Dummy() self.inSrc.link((self.inSrc, "outbox"), (self.carousel, "inbox")) self.inSrc.link((self.inSrc, "signal"), (self.carousel, "control")) self.outDest = Dummy() self.outDest.link((self.carousel, "outbox"), (self.outDest, "inbox")) self.outDest.link((self.carousel, "signal"), (self.outDest, "control")) self.nextFbk = Dummy() self.nextFbk.link((self.carousel, "requestNext"), (self.nextFbk, "inbox")) self.nextFbk.link((self.nextFbk, "outbox"), (self.carousel, "next")) self.carousel.activate(Scheduler=self.scheduler) self.inSrc.activate(Scheduler=self.scheduler) self.outDest.activate(Scheduler=self.scheduler) self.nextFbk.activate(Scheduler=self.scheduler) self.run = self.scheduler.main() def sendToInbox(self, data): self.inSrc.send(data, "outbox") def sendToControl(self, data): self.inSrc.send(data, "signal") def sendToNext(self, data): self.nextFbk.send(data, "outbox") def dataReadyOutbox(self): return self.outDest.dataReady("inbox") def dataReadySignal(self): return self.outDest.dataReady("control") def dataReadyRequestNext(self): return self.nextFbk.dataReady("inbox") def recvOutbox(self): return self.outDest.recv("inbox") def recvSignal(self): return self.outDest.recv("control") def recvRequestNext(self): return self.nextFbk.recv("inbox") def collectOutbox(self): out = [] while self.dataReadyOutbox(): out.append(self.recvOutbox()) return out def collectSignal(self): out = [] while self.dataReadySignal(): out.append(self.recvSignal()) return out def collectRequestNext(self): out = [] while self.dataReadyRequestNext(): out.append(self.recvRequestNext()) return out def runFor(self, cycles): numcycles = cycles * 5 # approx this many components in the system for i in range(0, numcycles): self.run.next() def test_byDefaultDoesNothing(self): """Carousel initialises. By default it does nothing.""" self.setup_test() self.runFor(cycles=100) self.assert_(self.children == [], "Carousel should create no children") self.assert_( not self.dataReadyOutbox(), "Carousel should have sent nothing to its 'outbox' outbox") self.assert_( not self.dataReadySignal(), "Carousel should have sent nothing to its 'signal' outbox") self.assert_( not self.dataReadyRequestNext(), "Carousel should have sent nothing to its 'requestNext' outbox") self.assert_(not self.carousel._isStopped(), "Carousel should still be running") def test_canAskToMake1stRequest(self): """If the make1stRequest argument is set to True at initialisation, Carousel sends a "NEXT" message out of its "requestNext" outbox after it has started up.""" self.setup_test(make1stRequest=True) self.runFor(cycles=5) self.assert_(self.children == [], "Carousel should create no children") self.assert_( not self.dataReadyOutbox(), "Carousel should have sent nothing to its 'outbox' outbox") self.assert_( not self.dataReadySignal(), "Carousel should have sent nothing to its 'signal' outbox") self.assert_( self.collectRequestNext() == ["NEXT"], "Carousel should have sent a single 'NEXT' to its 'requestNext' outbox" ) self.assert_(not self.carousel._isStopped(), "Carousel should still be running") def test_shutsDownWhenToldToAndIdle(self): """When idle, with no child; a shutdownMicroprocess or producerFinished message will cause Carousel to terminate.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() self.runFor(cycles=100) self.sendToControl(IPC()) self.assert_(not self.carousel._isStopped(), "Carousel should still be running") self.runFor(cycles=100) got = self.collectSignal() self.assert_( len(got) == 1 and isinstance(got[0], IPC), "Carousel should send a " + IPC.__class__.__name__ + " message out its 'signal' outbox") self.assert_(self.carousel._isStopped(), "Carousel should have terminated") def test_messageToNextRunsFactoryFunction(self): """When a message is sent to the "next" inbox, the supplied factory function is run with that argument.""" self.factoryRun = None def factory(arg): self.factoryRun = arg return Dummy() self.setup_test(componentFactory=factory) self.runFor(cycles=5) self.assert_(self.factoryRun == None) self.sendToNext("BLAH") self.runFor(cycles=5) self.assert_(self.factoryRun == "BLAH") def test_messageToNextSpawnsChild(self): """Messages sent to the "next" inbox trigger the factory function, leading to the creation and activation of a child component.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.assert_( len(self.children) == 1, "Carousel should have spawned a child in response to the 'next' request" ) self.assert_( self.children[-1].arg == "BLAH", "Carousel should have spawned child with the 'next' message as the argument" ) self.assert_(self.children[-1].wasActivated, "The child should have been activated") def test_childTerminationTriggersRequestNext(self): """When a child terminates; the Carousel sends a "NEXT" message out of its "requestNext" outbox.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.children[-1].stopNow = True self.runFor(cycles=5) self.assert_( self.collectRequestNext() == ["NEXT"], "Carousel should have sent a single 'NEXT' to its 'requestNext' outbox" ) def test_childShutdownSignalDoesntTriggerRequest(self): """If the child sends out a producerFinished or shutdownMicroprocess message out of its "signal" outbox; the Carousel does not send out a message from its "requestNext" outbox in response.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.children[-1].send(IPC(), "signal") self.runFor(cycles=50) self.assert_( self.collectRequestNext() == [], "Carousel should have not sent anything 'requestNext' outbox") def test_ChildReceivesShutdownSignal(self): """A shutdownMicroprocess or producerFinished message sent to the "control" inbox of the Carousel gets passed onto the "control" inbox of the child.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.sendToControl(IPC()) self.runFor(cycles=50) self.assert_( self.children[-1].dataReady("control"), "Child should have received something on its 'control' inbox") msg = self.children[-1].recv("control") self.assert_( isinstance(msg, IPC), "Child should have received a " + IPC.__class__.__name__ + " message out its 'control' inbox") def test_nextRequestStartsNewchildOnceCurrentHasTerminated(self): """A message sent to the "next" inbox starts a new child; but only once the current child has terminated.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) for i in range(0, 5): self.sendToNext("BLAH") self.runFor(cycles=50) self.assert_( len(self.children) == i + 1, "The new child should not be created until the previous has terminated" ) self.children[-1].stopNow = True self.runFor(cycles=5) self.assert_( len(self.children) == i + 2, "The 'next' message should have resulted in a new child") self.assert_(self.children[-2]._isStopped(), "The older child should by now be terminated") self.assert_( self.children[-1].wasActivated and not self.children[-1]._isStopped(), "The new child should be active and running") def test_dataReachesChildInbox(self): """Any messages sent to the "inbox" inbox of the Carousel gets sent on tot the "inbox" inbox of the child component.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=1) for i in range(0, 5): MSG = "HELLO" + str(i) self.sendToInbox(MSG) self.runFor(cycles=1) self.assert_(self.children[-1].dataReady("inbox"), "Something should have arrived at the inbox") self.assert_( self.children[-1].recv("inbox") == MSG, "The message sent to the Carousel's 'inbox' inbox should have reached the child's 'inbox' inbox" ) self.runFor(cycles=10) def test_dataReachesCarouselOutbox(self): """Any mesasges sent out of the "outbox" outbox of a child emerges from the "outbox" outbox of the Carousel.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=2) for i in range(0, 5): MSG = "HELLO" + str(i) self.children[-1].send(MSG, "outbox") self.runFor(cycles=1) self.assert_( self.collectOutbox() == [MSG], "The message sent to the child's 'outbox' outbox should have reached the Carousel's 'outbox' outbox" ) self.runFor(cycles=10) def test_childSignalIgnored(self): """Messages coming out of the child's "signal" outbox are ignored. They do not emerge from the "signal" outbox of the Carousel.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=2) for MSG in (producerFinished, shutdownMicroprocess, "HELLO!"): self.children[-1].send(MSG, "signal") self.runFor(cycles=1) self.assert_( self.collectSignal() == [], "Any message sent to the child's 'signal' outbox should not have reached the Carousel's 'signal' outbox" ) self.runFor(cycles=10) def test_terminatingCarouselWithChildPassesSignalToChildToo(self): """If a producerFinshed or shutdownMicroprocess is sent to a Carousel's "control" inbox, it is passed onto the child's "control" inbox.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() # create new child self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) # send shutdown to Carousel self.sendToControl(IPC()) self.runFor(cycles=5) # did the child get it msg = self.children[-1].recv("control") self.assert_( isinstance(msg, IPC), "Child should also receive a " + IPC.__class__.__name__ + " request") self.children[-1].stopNow = True self.runFor(cycles=5) def test_carouselDoesntTerminateUntilChildHas(self): """Carousel doesn't terminate (in response to producerFinished or shutdownMicroprocess) until the child has terminated.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() # create new child self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) # send shutdown to Carousel self.sendToControl(IPC()) self.runFor(cycles=50) # did the child get it msg = self.children[-1].recv("control") self.assert_( isinstance(msg, IPC), "Child should also receive a " + IPC.__class__.__name__ + " request") # carousel and child should still be running self.assert_(not self.carousel._isStopped()) self.assert_(not self.children[-1]._isStopped()) self.children[-1].stopNow = True self.runFor(cycles=5) self.assert_(self.carousel._isStopped()) self.assert_(self.children[-1]._isStopped()) 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) def test_queuedNextsAbortedIfShutdownMicroprocess(self): """If a shutdownMicroprocess() is received, any messages queued on the 'next' inbox are discarded; and Carousel shuts down as soon as any current child has terminated.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) self.sendToControl(shutdownMicroprocess()) for i in range(1, 10): self.sendToNext("BLAH") self.runFor(cycles=50) self.assert_(len(self.children) == 1, "Should only be the one child") self.assert_(not self.carousel._isStopped(), "Carousel shouldn't have stopped until the child has") msg = self.children[-1].recv("control") self.assert_(isinstance(msg, (shutdownMicroprocess, producerFinished))) self.children[-1].stopNow = True self.runFor(cycles=2) self.assert_(len(self.children) == 1, "Should only be the one child") self.assert_(self.carousel._isStopped(), "Carousel should have terminated") self.assert_(self.children[0]._isStopped(), "Child should have terminated")
class SimpleHTTPClient(component): Inboxes = { "inbox": "URLs to download", "control": "Shut me down", "_carouselready": "Receive NEXT when carousel has completed a request", "_carouselinbox": "Data from SingleShotHTTPClient via Carousel" } Outboxes = { "outbox": "Requested file's data string", "signal": "Signal I have shutdown", "_carouselnext": "Create a new SingleShotHTTPClient", "_carouselsignal": "Shutdown the carousel", "debug": "Information to aid debugging" } def __init__(self): """Create and link to a carousel object""" super(SimpleHTTPClient, self).__init__() #AttachConsoleToDebug(self) self.debug("SimpleHTTPClient.__init__()") self.carousel = Carousel(componentFactory=makeSSHTTPClient) self.addChildren(self.carousel) self.link((self, "_carouselnext"), (self.carousel, "next")) self.link((self, "_carouselsignal"), (self.carousel, "control")) self.link((self.carousel, "outbox"), (self, "_carouselinbox")) self.link((self.carousel, "requestNext"), (self, "_carouselready")) self.carousel.activate() 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() def debug(self, msg): self.send(msg, "debug") def main(self): """Main loop.""" self.debug("SimpleHTTPClient.main()\n") finished = False while not finished: yield 1 self.debug("SimpleHTTPClient.main1") while self.dataReady("inbox"): paramdict = self.recv("inbox") if isinstance(paramdict, str): paramdict = {"url": paramdict} self.debug("SimpleHTTPClient received url " + paramdict.get("url", "") + "\n") self.send(paramdict, "_carouselnext") filebody = "" carouselbusy = True while carouselbusy: yield 1 #print "SimpleHTTPClient.main2" while self.dataReady("_carouselinbox"): msg = self.recv("_carouselinbox") if isinstance(msg, ParsedHTTPBodyChunk): filebody += msg.bodychunk while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return while self.dataReady("_carouselready"): msg = self.recv("_carouselready") carouselbusy = False self.pause() self.send(filebody, "outbox") filebody = "" while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return self.pause() self.debug("eoml in SimpleHTTPClient") self.cleanup() yield 1 return
from Kamaelia.Audio.PyMedia.Output import Output from Kamaelia.Chassis.Carousel import Carousel from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.File.Reading import RateControlledFileReader from Kamaelia.File.Writing import SimpleFileWriter print( "Reading in WAV file, parsing it, then writing it out as test.wav ...") Graphline( READ=RateControlledFileReader( "/usr/share/sounds/alsa/Front_Center.wav", readmode="bytes", rate=1000000), PARSE=WAVParser(), ENC=Carousel(lambda meta: WAVWriter(**meta)), WRITE=SimpleFileWriter("test.wav"), linkages={ ("READ", "outbox"): ("PARSE", "inbox"), ("PARSE", "outbox"): ("ENC", "inbox"), ("PARSE", "all_meta"): ("ENC", "next"), ("ENC", "outbox"): ("WRITE", "inbox"), ("READ", "signal"): ("PARSE", "control"), ("PARSE", "signal"): ("ENC", "control"), ("ENC", "signal"): ("WRITE", "control"), }, ).run() print("Reading in test.wav and playing it back ...") Graphline(SRC=RateControlledFileReader("test.wav", readmode="bytes",
class SimpleHTTPClient(component): Inboxes = { "inbox": "URLs to download - a dict {'url':'x', 'postbody':'y'} or a just the URL as a string ", "control": "Shut me down", "_carouselready": "Receive NEXT when carousel has completed a request", "_carouselinbox": "Data from SingleShotHTTPClient via Carousel" } Outboxes = { "outbox": "Requested file's data string", "signal": "Signal I have shutdown", "_carouselnext": "Create a new SingleShotHTTPClient", "_carouselsignal": "Shutdown the carousel", "debug": "Information to aid debugging" } def __init__(self): """Create and link to a carousel object""" super(SimpleHTTPClient, self).__init__() #AttachConsoleToDebug(self) self.debug("SimpleHTTPClient.__init__()") # now create our Carousel subcomponent self.carousel = Carousel(componentFactory=makeSSHTTPClient) self.addChildren(self.carousel) self.link((self, "_carouselnext"), (self.carousel, "next")) self.link((self, "_carouselsignal"), (self.carousel, "control")) self.link((self.carousel, "outbox"), (self, "_carouselinbox")) self.link((self.carousel, "requestNext"), (self, "_carouselready")) 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() def debug(self, msg): self.send(msg, "debug") def main(self): """Main loop.""" self.debug("SimpleHTTPClient.main()\n") self.carousel.activate() finished = False while not finished: yield 1 self.debug("SimpleHTTPClient.main1\n") while self.dataReady("inbox"): paramdict = self.recv("inbox") # we accept either string or dict messages - if it's a string then # we assume you mean that's the URL you want fecthed if isinstance(paramdict, str): paramdict = {"url": paramdict} self.debug("SimpleHTTPClient received url " + paramdict.get("url", "") + "\n") # request creation of a new SingleShotHTTPClient by Carousel self.send(paramdict, "_carouselnext") # store as a list of strnigs then join at the # end to avoid O(n^2) time string cat'ing behaviour filebody = [] carouselbusy = True while carouselbusy: yield 1 while self.dataReady("_carouselinbox"): msg = self.recv("_carouselinbox") if isinstance(msg, ParsedHTTPBodyChunk): filebody.append(msg.bodychunk) while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return while self.dataReady("_carouselready"): msg = self.recv("_carouselready") carouselbusy = False self.pause() self.send(string.join(filebody, ""), "outbox") filebody = [ ] # free up some memory used by the now unneeded list while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return self.pause() self.debug("eoml in SimpleHTTPClient\n") self.cleanup() yield 1 return
from Kamaelia.Audio.Codec.PyMedia.Decoder import Decoder from Kamaelia.Audio.PyMedia.Output import Output from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.Chassis.Carousel import Carousel import sys if len(sys.argv) != 2: sys.stderr.write("Usage:\n\n PlayMP3.py <filename>\n\n") sys.exit(1) filename = sys.argv[1] def makeAudioOutput(metadata): return Output(metadata["sample_rate"], metadata["channels"], metadata["format"]) Graphline(READ=RateControlledFileReader(filename, readmode="bytes", rate=256000 / 8), DECODE=Decoder("mp3"), OUTPUT=Carousel(makeAudioOutput), linkages={ ("READ", "outbox"): ("DECODE", "inbox"), ("DECODE", "outbox"): ("OUTPUT", "inbox"), ("DECODE", "format"): ("OUTPUT", "next"), ("READ", "signal"): ("DECODE", "control"), ("DECODE", "signal"): ("OUTPUT", "control"), }).run()
class SimpleHTTPClient(component): Inboxes = { "inbox" : "URLs to download", "control" : "Shut me down", "_carouselready" : "Receive NEXT when carousel has completed a request", "_carouselinbox" : "Data from SingleShotHTTPClient via Carousel" } Outboxes = { "outbox" : "Requested file's data string", "signal" : "Signal I have shutdown", "_carouselnext" : "Create a new SingleShotHTTPClient", "_carouselsignal" : "Shutdown the carousel", "debug" : "Information to aid debugging" } def __init__(self): """Create and link to a carousel object""" super(SimpleHTTPClient, self).__init__() #AttachConsoleToDebug(self) self.debug("SimpleHTTPClient.__init__()") self.carousel = Carousel(componentFactory=makeSSHTTPClient) self.addChildren(self.carousel) self.link((self, "_carouselnext"), (self.carousel, "next")) self.link((self, "_carouselsignal"), (self.carousel, "control")) self.link((self.carousel, "outbox"), (self, "_carouselinbox")) self.link((self.carousel, "requestNext"), (self, "_carouselready")) self.carousel.activate() 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() def debug(self, msg): self.send(msg, "debug") def main(self): """Main loop.""" self.debug("SimpleHTTPClient.main()\n") finished = False while not finished: yield 1 self.debug("SimpleHTTPClient.main1") while self.dataReady("inbox"): paramdict = self.recv("inbox") if isinstance(paramdict, str): paramdict = { "url": paramdict } self.debug("SimpleHTTPClient received url " + paramdict.get("url","") + "\n") self.send(paramdict, "_carouselnext") filebody = "" carouselbusy = True while carouselbusy: yield 1 #print "SimpleHTTPClient.main2" while self.dataReady("_carouselinbox"): msg = self.recv("_carouselinbox") if isinstance(msg, ParsedHTTPBodyChunk): filebody += msg.bodychunk while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return while self.dataReady("_carouselready"): msg = self.recv("_carouselready") carouselbusy = False self.pause() self.send(filebody, "outbox") filebody = "" while self.dataReady("control"): msg = self.recv("control") if isinstance(msg, producerFinished): finished = True elif isinstance(msg, shutdown): self.cleanup() return self.pause() self.debug("eoml in SimpleHTTPClient") self.cleanup() yield 1 return
class Test_Carousel(unittest.TestCase): def setup_test(self, **args): self.children=[] self.scheduler = scheduler() scheduler.run = self.scheduler if "componentFactory" not in args: def defaultFactory(arg,parent=self): child = MockChild(self.children, arg) return child args["componentFactory"]=defaultFactory self.carousel = Carousel(**args) self.inSrc = Dummy() self.inSrc.link((self.inSrc,"outbox"), (self.carousel,"inbox")) self.inSrc.link((self.inSrc,"signal"), (self.carousel,"control")) self.outDest = Dummy() self.outDest.link((self.carousel,"outbox"), (self.outDest,"inbox")) self.outDest.link((self.carousel,"signal"), (self.outDest,"control")) self.nextFbk = Dummy() self.nextFbk.link((self.carousel,"requestNext"), (self.nextFbk,"inbox")) self.nextFbk.link((self.nextFbk,"outbox"), (self.carousel,"next")) self.carousel.activate(Scheduler=self.scheduler) self.inSrc.activate(Scheduler=self.scheduler) self.outDest.activate(Scheduler=self.scheduler) self.nextFbk.activate(Scheduler=self.scheduler) self.run = self.scheduler.main() def sendToInbox(self,data): self.inSrc.send(data,"outbox") def sendToControl(self,data): self.inSrc.send(data,"signal") def sendToNext(self,data): self.nextFbk.send(data,"outbox") def dataReadyOutbox(self): return self.outDest.dataReady("inbox") def dataReadySignal(self): return self.outDest.dataReady("control") def dataReadyRequestNext(self): return self.nextFbk.dataReady("inbox") def recvOutbox(self): return self.outDest.recv("inbox") def recvSignal(self): return self.outDest.recv("control") def recvRequestNext(self): return self.nextFbk.recv("inbox") def collectOutbox(self): out=[] while self.dataReadyOutbox(): out.append(self.recvOutbox()) return out def collectSignal(self): out=[] while self.dataReadySignal(): out.append(self.recvSignal()) return out def collectRequestNext(self): out=[] while self.dataReadyRequestNext(): out.append(self.recvRequestNext()) return out def runFor(self, cycles): numcycles=cycles*5 # approx this many components in the system for i in range(0,numcycles): self.run.next() def test_byDefaultDoesNothing(self): """Carousel initialises. By default it does nothing.""" self.setup_test() self.runFor(cycles=100) self.assert_(self.children==[], "Carousel should create no children") self.assert_(not self.dataReadyOutbox(), "Carousel should have sent nothing to its 'outbox' outbox") self.assert_(not self.dataReadySignal(), "Carousel should have sent nothing to its 'signal' outbox") self.assert_(not self.dataReadyRequestNext(), "Carousel should have sent nothing to its 'requestNext' outbox") self.assert_(not self.carousel._isStopped(), "Carousel should still be running") def test_canAskToMake1stRequest(self): """If the make1stRequest argument is set to True at initialisation, Carousel sends a "NEXT" message out of its "requestNext" outbox after it has started up.""" self.setup_test(make1stRequest=True) self.runFor(cycles=5) self.assert_(self.children==[], "Carousel should create no children") self.assert_(not self.dataReadyOutbox(), "Carousel should have sent nothing to its 'outbox' outbox") self.assert_(not self.dataReadySignal(), "Carousel should have sent nothing to its 'signal' outbox") self.assert_(self.collectRequestNext()==["NEXT"], "Carousel should have sent a single 'NEXT' to its 'requestNext' outbox") self.assert_(not self.carousel._isStopped(), "Carousel should still be running") def test_shutsDownWhenToldToAndIdle(self): """When idle, with no child; a shutdownMicroprocess or producerFinished message will cause Carousel to terminate.""" for IPC in (producerFinished, shutdownMicroprocess): self.setup_test() self.runFor(cycles=100) self.sendToControl(IPC()) self.assert_(not self.carousel._isStopped(), "Carousel should still be running") self.runFor(cycles=100) got=self.collectSignal() self.assert_(len(got)==1 and isinstance(got[0],IPC), "Carousel should send a "+IPC.__class__.__name__+" message out its 'signal' outbox") self.assert_(self.carousel._isStopped(), "Carousel should have terminated") def test_messageToNextRunsFactoryFunction(self): """When a message is sent to the "next" inbox, the supplied factory function is run with that argument.""" self.factoryRun=None def factory(arg): self.factoryRun=arg return Dummy() self.setup_test(componentFactory=factory) self.runFor(cycles=5) self.assert_(self.factoryRun==None) self.sendToNext("BLAH") self.runFor(cycles=5) self.assert_(self.factoryRun=="BLAH") def test_messageToNextSpawnsChild(self): """Messages sent to the "next" inbox trigger the factory function, leading to the creation and activation of a child component.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.assert_(len(self.children)==1, "Carousel should have spawned a child in response to the 'next' request") self.assert_(self.children[-1].arg=="BLAH", "Carousel should have spawned child with the 'next' message as the argument") self.assert_(self.children[-1].wasActivated, "The child should have been activated") def test_childTerminationTriggersRequestNext(self): """When a child terminates; the Carousel sends a "NEXT" message out of its "requestNext" outbox.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.children[-1].stopNow=True self.runFor(cycles=5) self.assert_(self.collectRequestNext()==["NEXT"], "Carousel should have sent a single 'NEXT' to its 'requestNext' outbox") def test_childShutdownSignalDoesntTriggerRequest(self): """If the child sends out a producerFinished or shutdownMicroprocess message out of its "signal" outbox; the Carousel does not send out a message from its "requestNext" outbox in response.""" for IPC in (producerFinished,shutdownMicroprocess): self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.children[-1].send(IPC(),"signal") self.runFor(cycles=50) self.assert_(self.collectRequestNext()==[], "Carousel should have not sent anything 'requestNext' outbox") def test_ChildReceivesShutdownSignal(self): """A shutdownMicroprocess or producerFinished message sent to the "control" inbox of the Carousel gets passed onto the "control" inbox of the child.""" for IPC in (producerFinished,shutdownMicroprocess): self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) self.sendToControl(IPC()) self.runFor(cycles=50) self.assert_(self.children[-1].dataReady("control"), "Child should have received something on its 'control' inbox") msg=self.children[-1].recv("control") self.assert_(isinstance(msg,IPC), "Child should have received a "+IPC.__class__.__name__+" message out its 'control' inbox") def test_nextRequestStartsNewchildOnceCurrentHasTerminated(self): """A message sent to the "next" inbox starts a new child; but only once the current child has terminated.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=5) for i in range(0,5): self.sendToNext("BLAH") self.runFor(cycles=50) self.assert_(len(self.children)==i+1, "The new child should not be created until the previous has terminated") self.children[-1].stopNow=True self.runFor(cycles=5) self.assert_(len(self.children)==i+2, "The 'next' message should have resulted in a new child") self.assert_(self.children[-2]._isStopped(), "The older child should by now be terminated") self.assert_(self.children[-1].wasActivated and not self.children[-1]._isStopped(), "The new child should be active and running") def test_dataReachesChildInbox(self): """Any messages sent to the "inbox" inbox of the Carousel gets sent on tot the "inbox" inbox of the child component.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=1) for i in range(0,5): MSG = "HELLO"+str(i) self.sendToInbox(MSG) self.runFor(cycles=1) self.assert_(self.children[-1].dataReady("inbox"), "Something should have arrived at the inbox") self.assert_(self.children[-1].recv("inbox")==MSG, "The message sent to the Carousel's 'inbox' inbox should have reached the child's 'inbox' inbox") self.runFor(cycles=10) def test_dataReachesCarouselOutbox(self): """Any mesasges sent out of the "outbox" outbox of a child emerges from the "outbox" outbox of the Carousel.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=2) for i in range(0,5): MSG = "HELLO"+str(i) self.children[-1].send(MSG,"outbox") self.runFor(cycles=1) self.assert_(self.collectOutbox()==[MSG], "The message sent to the child's 'outbox' outbox should have reached the Carousel's 'outbox' outbox") self.runFor(cycles=10) def test_childSignalIgnored(self): """Messages coming out of the child's "signal" outbox are ignored. They do not emerge from the "signal" outbox of the Carousel.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=2) for MSG in (producerFinished,shutdownMicroprocess,"HELLO!"): self.children[-1].send(MSG,"signal") self.runFor(cycles=1) self.assert_(self.collectSignal()==[], "Any message sent to the child's 'signal' outbox should not have reached the Carousel's 'signal' outbox") self.runFor(cycles=10) def test_terminatingCarouselWithChildPassesSignalToChildToo(self): """If a producerFinshed or shutdownMicroprocess is sent to a Carousel's "control" inbox, it is passed onto the child's "control" inbox.""" for IPC in (producerFinished,shutdownMicroprocess): self.setup_test() # create new child self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) # send shutdown to Carousel self.sendToControl(IPC()) self.runFor(cycles=5) # did the child get it msg = self.children[-1].recv("control") self.assert_(isinstance(msg,IPC), "Child should also receive a "+IPC.__class__.__name__+" request") self.children[-1].stopNow=True self.runFor(cycles=5) def test_carouselDoesntTerminateUntilChildHas(self): """Carousel doesn't terminate (in response to producerFinished or shutdownMicroprocess) until the child has terminated.""" for IPC in (producerFinished,shutdownMicroprocess): self.setup_test() # create new child self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) # send shutdown to Carousel self.sendToControl(IPC()) self.runFor(cycles=50) # did the child get it msg = self.children[-1].recv("control") self.assert_(isinstance(msg,IPC), "Child should also receive a "+IPC.__class__.__name__+" request") # carousel and child should still be running self.assert_(not self.carousel._isStopped()) self.assert_(not self.children[-1]._isStopped()) self.children[-1].stopNow=True self.runFor(cycles=5) self.assert_(self.carousel._isStopped()) self.assert_(self.children[-1]._isStopped()) 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) def test_queuedNextsAbortedIfShutdownMicroprocess(self): """If a shutdownMicroprocess() is received, any messages queued on the 'next' inbox are discarded; and Carousel shuts down as soon as any current child has terminated.""" self.setup_test() self.runFor(cycles=5) self.sendToNext("BLAH") self.runFor(cycles=50) self.sendToControl(shutdownMicroprocess()) for i in range(1,10): self.sendToNext("BLAH") self.runFor(cycles=50) self.assert_(len(self.children)==1, "Should only be the one child") self.assert_(not self.carousel._isStopped(), "Carousel shouldn't have stopped until the child has") msg=self.children[-1].recv("control") self.assert_(isinstance(msg,(shutdownMicroprocess,producerFinished))) self.children[-1].stopNow=True self.runFor(cycles=2) self.assert_(len(self.children)==1, "Should only be the one child") self.assert_(self.carousel._isStopped(), "Carousel should have terminated") self.assert_(self.children[0]._isStopped(), "Child should have terminated")
# #\----------------------------------------------------------------- #/----------------------------------------------------------------- # Mechanism to allow the audio data to be shared to all clients # Backplane("RADIO").activate() # #\----------------------------------------------------------------- #/----------------------------------------------------------------- # The client portion of the P2P swarm # Graphline( CONFIGURE=ConnectToSwarm(rootip, rootcontrolport, myip, mycontrolport), CLIENT=Carousel(mkTCPClient), # configured using an ip/dataport from above PUBLISHTO=PublishTo("RADIO"), linkages={ ("CONFIGURE", "outbox"): ("CLIENT", "next"), ("CLIENT", "outbox"): ("PUBLISHTO", "inbox"), }).activate() # #\----------------------------------------------------------------- #/----------------------------------------------------------------- # Handle clients connecting to us: def ServeRadio(): return SubscribeTo("RADIO")
metadata["format"]) def makePlayer(mp3filename): print mp3filename return Graphline(READ=RateControlledFileReader(mp3filename, readmode="bytes", rate=256000 / 8), DECODE=Decoder("mp3"), OUTPUT=Carousel(makeAudioOutput), linkages={ ("READ", "outbox"): ("DECODE", "inbox"), ("DECODE", "outbox"): ("OUTPUT", "inbox"), ("DECODE", "format"): ("OUTPUT", "next"), ("", "control"): ("READ", "control"), ("READ", "signal"): ("DECODE", "control"), ("DECODE", "signal"): ("OUTPUT", "control"), ("OUTPUT", "signal"): ("", "signal"), }) from Kamaelia.Util.Chooser import ForwardIteratingChooser Graphline(PLAYLIST=ForwardIteratingChooser(filenames), PLAYER=Carousel(makePlayer, make1stRequest=False), linkages={ ("PLAYER", "requestNext"): ("PLAYLIST", "inbox"), ("PLAYLIST", "outbox"): ("PLAYER", "next"), ("PLAYLIST", "signal"): ("PLAYER", "control"), }).run()
self.send(("hello2", "world2"), "outbox") yield 1 self.send(("hello3", "world3"), "outbox") yield 1 self.send(("hello4", "world4"), "outbox") yield 1 print "XXX" def mkMyComponent(args): return MyComponent(*args) class MyComponent(Axon.Component.component): Outboxes = ["outbox", "signal", "requestNext"] def __init__(self, *args): print "XXX" super(MyComponent, self).__init__() print "ARGS", args def main(self): self.send(Axon.Ipc.producerFinished, "requestNext") yield 1 Graphline(SOURCE=Source(), SPECIALISE=Carousel(mkMyComponent), linkages={ ("SOURCE", "outbox"): ("SPECIALISE", "next"), }).run()