def setUp(self): self.src = component() self.dst = component() self.dst2 = TestComponent() self.controller = component() self.split = Splitter() self.runner = self.split.main() self.linkin = linkage(self.src, self.split) self.linkcont = linkage(self.controller, self.split, sinkbox="configuration") self.links = [self.linkin, self.linkcont] # self.linkout1 = linkage(self.split,self.dst) # self.linkout2 = linkage(self.split,self.dst2, sourcebox="out2") # # -- NEW STUFF ------ # Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler() self.execute = Axon.Scheduler.scheduler.run.main() self.S = Splitter().activate() self.D = component().activate() self.D2 = TestComponent().activate() self.W = component().activate() self.W.link((self.W, "outbox"), (self.S, "configuration"))
def __init__(self, name): super(Backplane, self).__init__() assert name == str(name) self.name = name self.splitter = Splitter() splitter = self.splitter cat = CAT.getcat() try: cat.registerService("Backplane_I_" + self.name, splitter, "inbox") cat.registerService("Backplane_O_" + self.name, splitter, "configuration") except Axon.AxonExceptions.ServiceAlreadyExists: e = sys.exc_info()[1] print( "***************************** ERROR *****************************" ) print( "An attempt to make a second backplane with the same name happened." ) print("This is incorrect usage.") print("") traceback.print_exc(3) print( "***************************** ERROR *****************************" ) raise e
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)
def test_SplitterDelLinkBoth(self): """Sending an delSink message to splitter unlinks in the extra outbox and signal""" Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler() split = Splitter().activate() target1 = Axon.Component.component().activate() target2 = Axon.Component.component().activate() target1.link((split, "outbox"), (target1, "inbox")) target1.link((split, "signal"), (target1, "control")) addmsg = addsink(target2, "inbox", "control") split._deliver(addmsg, "configuration") execute = Axon.Scheduler.scheduler.run.main() for i in xrange(1, 10): execute.next() for i in xrange(1, 10): if i == 5: delmsg = removesink(target2, "inbox", "control") split._deliver(delmsg, "configuration") split._deliver(i, "inbox") split._deliver(10 + i, "control") for j in xrange(1, 10): execute.next() for i in xrange(1, 40): execute.next() # verify that the data has made it to the targets for i in xrange(1, 5): self.assert_(target1.dataReady("inbox")) self.assert_(target1.dataReady("control")) self.assert_(i == target1.recv("inbox")) self.assert_(10 + i == target1.recv("control")) self.assert_(target2.dataReady("inbox")) self.assert_(target2.dataReady("control")) self.assert_(i == target2.recv("inbox")) self.assert_(10 + i == target2.recv("control")) for i in xrange(5, 10): self.assert_(target1.dataReady("inbox")) self.assert_(target1.dataReady("control")) self.assert_(i == target1.recv("inbox")) self.assert_(10 + i == target1.recv("control")) self.assert_(not target2.dataReady("inbox")) self.assert_(not target2.dataReady("control")) # verify there is nothing left self.assert_(not target1.dataReady("inbox")) self.assert_(not target1.dataReady("control")) self.assert_(not target2.dataReady("inbox")) self.assert_(not target2.dataReady("control"))
def test_PluggingInAndTxfer(self): """Plug instantiated with splitter and component and passes data through to component.""" 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, 1000): execute.next() #pass some data in for i in xrange(1, 10): splitter._deliver(i, "inbox") splitter._deliver(10 + i, "control") for i in xrange(1, 100): execute.next() # verify it reached the target self.assert_(target.inboxlog == range(1, 10)) self.assert_(target.controllog == range(11, 20))
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)
def test_PassThroughControlSignal(self): """Data sent to the inbox is sent on to the outbox""" split = Splitter() Dummy = Axon.Component.component() split.link((split, "outbox"), (Dummy, "inbox")) split.link((split, "signal"), (Dummy, "control")) split.activate() for i in xrange(1, 10): split._deliver(i, "control") for _ in xrange(0, 100): split.next() for i in xrange(1, 10): self.assert_(len(split.outboxes["signal"])) self.assert_(0 == len(split.outboxes["outbox"])) # self.assert_( i == split._collect("signal") ) self.assert_(i == Dummy.recv("control")) for i in xrange(1, 10): split._deliver(i, "control") split.next() split.next() for _ in xrange(0, 10): split.next() for i in xrange(1, 10): self.assert_(len(split.outboxes["signal"])) self.assert_(0 == len(split.outboxes["outbox"])) # self.assert_( i == split._collect("signal") ) self.assert_(i == Dummy.recv("control"))
def test_SplitterAddLinkSignalOnly(self): """Sending an addSink message to splitter links in an extra signal""" Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler() split = Splitter().activate() target1 = Axon.Component.component().activate() target2 = Axon.Component.component().activate() target1.link((split, "outbox"), (target1, "inbox")) target1.link((split, "signal"), (target1, "control")) addmsg = addsink(target2, None, "control") split._deliver(addmsg, "configuration") execute = Axon.Scheduler.scheduler.run.main() for i in xrange(1, 10): execute.next() for i in xrange(1, 10): split._deliver(i, "inbox") split._deliver(10 + i, "control") for j in xrange(1, 10): execute.next() # verify that the data has made it to the targets for i in xrange(1, 10): self.assert_(target1.dataReady("inbox")) self.assert_(target1.dataReady("control")) self.assert_(i == target1.recv("inbox")) self.assert_(10 + i == target1.recv("control")) self.assert_(not target2.dataReady("inbox")) self.assert_(target2.dataReady("control")) self.assert_(10 + i == target2.recv("control")) # verify there is nothing left self.assert_(not target1.dataReady("inbox")) self.assert_(not target1.dataReady("control")) self.assert_(not target2.dataReady("inbox")) self.assert_(not target2.dataReady("control"))
def initialiseComponent(self): """Setting up all the components and activating them. Also registers the splitter with the CoordinatingAssistantTracker. Would be better to rewrite so that instead of activating directly the new components would be returned in a newComponents object. At the moment the returned values are just ignored.""" # testfile = "/usr/share/doc/packages/subversion/html/svn-book.html" # rfa = ReadFileAdaptor(filename = testfile, readsize = 5, steptime = 1.5).activate() # rfa = ReadFileAdaptor(command = "netcat -l -p 1400") splitter = Splitter().activate() # self.link((rfa,"outbox"),(splitter, "inbox")) str = SimpleServer(protocol=streamingTextReceiverProtocol, port=1400).activate() cat = coordinatingassistanttracker.getcat() cat.registerService("thesource", splitter, "configuration") cat.registerService("thesink", splitter, "inbox") ss = SimpleServer(protocol=streamingTextServerProtocol, port=1500).activate() # self.addChildren(rfa,splitter, ss) self.addChildren(str,splitter, ss) # return rfa, ss, splitter return str, ss, splitter
if __name__ == "__main__": from Axon.Scheduler import scheduler from Kamaelia.Util.PipelineComponent import pipeline from Kamaelia.Visualisation.PhysicsGraph.TopologyViewerComponent import TopologyViewerComponent from Kamaelia.Util.Splitter import PlugSplitter as Splitter from Kamaelia.Util.Splitter import Plug # from Filters import FilterSelectMsgs, FilterTopologyMsgs from PipeBuild import PipeBuild from PipelineWriter import PipelineWriter from BuildViewer import BuildViewer from GUI import BuilderControlsGUI, TextOutputGUI items = list(getAllClasses(COMPONENTS)) pipegen = Splitter(pipeline(BuilderControlsGUI(items), PipeBuild())) viewer = Splitter(BuildViewer()) Plug(viewer, pipegen).activate() # feedback loop for 'selected' msgs Plug(pipegen, viewer).activate() Plug(pipegen, pipeline(PipelineWriter(), TextOutputGUI("Pipeline code"))).activate() scheduler.run.runThreads()
def __init__(self, name): super(Backplane, self).__init__() assert name == str(name) self.name = name self.splitter = Splitter().activate()
def test_InstantiateNoArgs(self): """Splitter instantiated with no args is just passthrough""" split = Splitter() split.activate()
from BitRateExtractor import BitRateExtractor filepath = "/opt/kde3/share/apps/khangman/sounds/new_game.ogg" extn = filepath[-3:].lower() rateController = VariableRateControl(rate=4096, chunksize=1024) fileReader = ReadFileAdapter(filename=filepath, readmode="bytes") bitrateExtractor = BitRateExtractor() decoder = AudioDecoder(extn) output = SoundOutput() wiringoption = 2 if wiringoption == 1: #-------------------------------------------------------- audiosplitter = Splitter() decodedAudioSource = pipeline(rateController, fileReader, decoder, audiosplitter) # here we break the encapsulation provided by pipeline # - by directly referencing 'audiosplitter' bitrateSource = Plug(audiosplitter, bitrateExtractor) mainpipe = pipeline(bitrateSource, decodedAudioSource, output).activate() elif wiringoption == 2: #------------------------------------------------------ decodedAudioSource = Splitter(pipeline(rateController, fileReader, decoder))