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

Kamaelia.Util.Backplane

Publishing and Subscribing with Backplanes

Backplanes provide a way to 'publish' data under a name, enabling other parts of the system to 'subscribe' to it on the fly, without having to know about the actual component(s) the data is coming from.

It is a quick and easy way to distribute or share data. Think of them like backplane circuit boards - where other circuit boards can plug in to send or receive any signals they need.

Example usage

A system where several producers publish data, for consumers to pick up:

Pipeline( Producer1(),
          PublishTo("DATA")
        ).activate()

Pipeline( Producer2(),
          PublishTo("DATA")
        ).activate()

Pipeline( SubscribeTo("DATA"),
          Consumer1(),
        ).activate()

Pipeline( SubscribeTo("DATA"),
          Consumer2(),
        ).activate()

Backplane("DATA").run()

A server where multiple clients can connect and they all get sent the same data at the same time:

Pipeline( Producer(),
          PublishTo("DATA")
        ).activate()

SimpleServer(protocol=SubscribeTo("DATA"), port=1500).activate()

Backplane("DATA").run()

More detail

The Backplane component collects data from publishers and sends it out to subscribers.

You can have as many backplanes as you like in a running system - provided they all register under different names.

A backplane can have multiple subscribers and multiple publishers. Publishers and subscribers can be created and destroyed on the fly.

To shut down a PublishTo() component, send a producerFinished() or shutdownMicroprocess() message to its "control" inbox. This does not propagate and therefore does not cause the Backplane or any subscribers to terminate.

To shut down a SubscribeTo() component, send a producerFinished() or shutdownMicroprocess() message to its "control" inbox. It will then immediately forward the mesage on out of its "signal" outbox and terminate.

To shut down the Backplane itself, send a producerFinished() or shutdownMicroprocess() message to its "control" inbox. It will then immediately terminate and also propagate this message onto any subscribers (SubscribeTo components), causing them to also terminate.

Implementation details

Backplane is actually based on a Kamaelia.Util.Splitter.PlugSplitter component, and the SubscribeTo component is a wrapper around a Kamaelia.Util.Splitter.Plug.

The Backplane registers itself with the coordinating assistant tracker.

  • Its "inbox" inbox is registered under the name "Backplane_I_<name>"
  • Its "configuration" inbox is registered under the name "Backplane_O_<name>"

PublishTo components look up the "Backplane_I_<name>" service and simply forward data sent to their "inbox" inboxes direct to the "inbox" inbox of the PlugSplitter - causing it to be distributed to all subscribers.

SubscribeTo components look up the "Backplane_O_<name>" service and request to have their "inbox" and "control" inboxes connected to the PlugSplitter. SubscribeTo then forwards on any messages it receives out of its "outbox" and "signal" outboxes respectively.

The PlugSplitter component's "control" inbox and "signal" outbox are not advertised as services. To shut down a Backplane you must therefore send a shutdownMicroprocess() or producerFinished() message directly to its "control" inbox. When this happens, the shutdown message will be forwarded on to all subscribers - causing SubscribeTo components to also shut down.


Kamaelia.Util.Backplane.Backplane

class Backplane(Axon.Component.component)

Backplane(name) -> new Backplane component.

A named backplane to which data can be published for subscribers to pick up.

  • Use PublishTo components to publish data to a Backplane.
  • Use SubscribeTo components to receive data published to a Backplane.

Keyword arguments:

  • name -- The name for the backplane. publishers and subscribers connect to this by using the same name.

Inboxes

  • control : Shutdown signalling (shuts down the backplane and all subscribers
  • inbox : NOT USED

Outboxes

  • outbox : NOT USED
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, name)

childrenDone(self)

Unplugs any children that have terminated, and returns true if there are no running child components left (ie. their microproceses have finished)

main(self)

Main loop.

Kamaelia.Util.Backplane.PublishTo

class PublishTo(Axon.Component.component)

PublishTo(destination) -> new PublishTo component

Publishes data to a named Backplane. Any data sent to the "inbox" inbox is sent to all (any) subscribers to the same named Backplane.

Keyword arguments:

  • destination -- the name of the Backplane to publish data to

Inboxes

  • control : Shutdown signalling (doesn't shutdown the Backplane)
  • inbox : Send to here data to be published to the backplane

Outboxes

  • outbox : NOT USED
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, destination)

main(self)

Main loop.

Kamaelia.Util.Backplane.SubscribeTo

class SubscribeTo(Axon.Component.component)

SubscribeTo(source) -> new SubscribeTo component

Subscribes to a named Backplane. Receives any data published to that backplane and sends it on out of its "outbox" outbox.

Keyword arguments:

  • source -- the name of the Backplane to subscribe to for data

Inboxes

  • control : Shutdown signalling (doesn't shutdown the Backplane)
  • inbox : NOT USED

Outboxes

  • outbox : Data received from the backplane (that was published to it)
  • signal : Shutdown signalling

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, source)

childrenDone(self)

Unplugs any children that have terminated, and returns true if there are no running child components left (ie. their microproceses have finished)

main(self)

Main loop.

Feedback

Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT