Hi Matt,
On 08/10/2009 13:45, Matt Hammond wrote:
>
> Ignoring threaded component behaviour for a moment. Axon delivers messages
> to the destination component immediately. So if you send a message(s) to
> the "inbox" inbox of a component, then a message to the "control" inbox of
> the same component; then if that component notices the message in its
> "control" inbox, then it is guaranteed that the messages sent, earlier, to
> its "inbox" inbox will already be there. Ie. (in the current
> implementation at least) message delivery is guaranteed in-order.
Good. I, for one, would like this to be made part of the "specification"
so future implementations preserve this aspect.
> It does cause queues to be flushed. And the documentation (I wrote) is
> poor in that it does not explicitly state what actually happens (or what
> is guaranteed from the perspective of a component writer). Yes, its
> purpose when I coded it was to ensure queues are flushed.
That's reassuring. I'd sort of worked out from the code what it was up
to, but it's nice to have confirmation from the author.
> However, even inserting self.sync() calls doesn't eliminate all race
> conditions: a fresh message could arrive at the "control" inbox just after
> sync() returns, and be delivered first (before any other messages pending
> at the "inbox" inbox) meaning the thread might still miss them. Hmm.
I'd not given much thought to inboxes when I wrote my original, being
more concerned with the producer's outboxes. However, testing my
threaded consumer with the unthreaded producer revealed that inboxes are
also a problem.
> I guess something like this might be a hacky inelegant work around (not
> tested):
[snip]
Here's my solution (tested) which I think achieves the same thing:
class ConsumerT(Axon.ThreadedComponent.threadedcomponent):
def main(self):
count = 0
while 1:
if self.dataReady('inbox'):
msg = self.recv('inbox')
count += 1
elif self.dataReady('control'):
self.sync()
if not self.dataReady('inbox'):
msg = self.recv('control')
if isinstance(msg, producerFinished):
break
else:
self.pause(0.1)
print "%d messages received" % count
This just does a sync() any time there is data in 'control', and defers
dealing with the control input until there is no inbox input.
Note that in neither case am I considering inbox messages sent after the
control message. My components do not send anything after a control message.
--
Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"kamaelia" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/kamaelia?hl=en
-~----------~----~----~----~------~----~------~--~---