Given we have outboxes and inboxes, it makes sense to have something that can handle deliveries between the two. For the purpose of this exercise, we'll create a microprocess that can look at a single outbox for a single component, take any messages deposited there and pass them the an inbox of another component. In terms of the component implementation so far we can use dataReady to check for availability of messages, recv to collect the message from the outbox, and send to deliver the message to the recipient inbox.
Exercise: Write a class called postman that subclasses microprocess with the following...
Given this, we can now start building interesting systems. We have mechanisms for enabling concurrency in a single process (microprocess & scheduler), a mechanism for adding communications (postboxes) to a microprocess (component) and a mechanism for enabling deliveries between components. Whilst we (the Kamaelia team) can see from an optimised version that the postman can actually be optimised out of the system, this simple mini-axon shows the core elements of Kamaelia quite nearly in a microcosm.
One full version of this mini-axon can be found here: Mini Axon Full, which should now be clear what it's doing how and why.
A simple example we can now create is a trivial system with one component creating some data and sending it to another one for display.
class Producer(component): def __init__(self, message): super(Producer,self).__init__() self.message = message def main(self): while 1: yield 1 self.send(self.message, "outbox") class Consumer(component): def main(self): count = 0 while 1: yield 1 count += 1 # This is to show our data is changing :-) if self.dataReady("inbox"): data = self.recv("inbox") print data, count p = Producer("Hello World") c = Consumer() postie = postman(p, "outbox", c, "inbox") myscheduler = scheduler() myscheduler.activateMicroprocess(p) myscheduler.activateMicroprocess(c) myscheduler.activateMicroprocess(postie) for _ in myscheduler.main(): pass
Running the above system then results in the following output:
Hello World 2
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.