6 Interlude 2

If you've come this far, you may be wondering the worth of what you've acheived. Essentially you've managed to implement the core of a working Axon system, specifically on the most used aspects of the system. Sure, there is some syntactic sugar relating to creation and managing of links, but that's what it is - sugar.

One of the longer examples on the Kamaelia website, specifically in the blog area, is how to build new components. That's probably the next logical place to start looking. However, taking one of the components on that page, we find that the core implementation of them matches the same core API as the component system you've implemented.

For example, let's take a look at the multicast sender.

    class Multicast_sender(component):

This has an initialiser for grabbing some initial values, and ensuring the super class's initialiser is called:

       def __init__(self, local_addr, local_port, remote_addr, remote_port):
    super(Multicast_sender, self).__init__()
    self.local_addr = local_addr
    self.local_port = local_port
    self.remote_addr = remote_addr
    self.remote_port = remote_port

The main function/generator then is relatively simple - set up the socket, wait for data and send it out:

       def main(self):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 10)
    while 1:
    if self.dataReady("inbox"):
    data = self.recv()
    l = sock.sendto(data, (self.remote_addr,self.remote_port) );
    yield 1

From this, it should be clear that this will work inside the mini-axon system you've created.

Similarly, we can create a simple file reading component thus:

    class FileReader(component):
    def __init__(self, filename):
    super(ReadFileAdapter, self).__init__()
    self.file = open(filename, "rb",0)
    def main(self):
    yield 1
    for line in self.file.xreadlines():
    self.send(line, "outbox")
    yield 1

This can then also be used using the component system you've just created to build a simplistic system for sending data to a multicast group:

    reader = FileReader("fortune.txt")
    sender = Multicast_sender("", 0, "", 1600)
    postie = Postman(reader, "outbox", sender, "inbox")

That can then be activated and run in the usual way:

    myscheduler = scheduler()

    for _ in myscheduler.main():

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

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.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)