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

Kamaelia.Util.Sync

Wait for 'n' items before sending one of them on

For every 'n' items received, one is sent out (the first one received in the latest batch).

Example Usage

Wait for two tasks to finish, before propagating the shutdown message:

Graphline( A    = TaskA(),
           B    = TaskB(),
           SYNC = Sync(2),
           linkages = {
               ("A", "signal") : ("SYNC", "inbox"),
               ("B", "signal") : ("SYNC", "inbox"),

               ("SYNC", "outbox") : ("SYNC", "control"),
               ("SYNC", "signal") : ("", "signal"),
           }

The slightly strange wiring is to make sure the Sync component is also shut down. The shutdown message is used to shutdown Sync itself. The shutdown message it emits is then the one that propogates out of the graphline.

Behaviour

At initialisation, specify the number of items Sync should wait for.

Once that number of items have arrived at Sync's "inbox" inbox; the first that arrived is sent on out of its "outbox" outbox. This process is repeated until Sync is shut down.

If more han the specified number of items arrive in one go; the excess items roll over to the next cycle. They are not ignored or lost.

If a producerFinished or shutdownMicroprocess message is received on the "control" inbox. It is immediately sent on out of the "signal" outbox and the component then immediately terminates.


Kamaelia.Util.Sync.Sync

class Sync(Axon.Component.component)

Sync([n]) -> new Sync component.

After ever 'n' items received, the first in each batch received is sent on.

Keyword arguments:

- n  -- The number of items to expect (default=2)

Inboxes

  • control : Shutdown signalling
  • inbox : Data items

Outboxes

  • outbox : First data item from last batch
  • 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[, n])

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

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