April 2024 - This site, and Kamaelia are being updated. There is significant work needed, and PRs are welcome.

5 Postman - A Microprocess that performs deliveries!

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...

Attributes:

Behaviour: (methods)

__init__(self, source, sourcebox, sink, sinkbox)
This should perform the following initialisation:

main(self)
This implements the behaviour described above:

In a loop

Answer Hidden

Show Answer

Answer:

Discussion:

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.

Running the above system then results in the following output: