Merge lp:~dne/txamqp/auto-channel-id-alloc into lp:txamqp

Proposed by Daniel Néri
Status: Needs review
Proposed branch: lp:~dne/txamqp/auto-channel-id-alloc
Merge into: lp:txamqp
Diff against target: 31 lines (+14/-4)
1 file modified
src/txamqp/protocol.py (+14/-4)
To merge this branch: bzr merge lp:~dne/txamqp/auto-channel-id-alloc
Reviewer Review Type Date Requested Status
Thomas Herve Needs Fixing
Review via email: mp+33204@code.launchpad.net

Description of the change

Adds support for automatic allocation of an unused channel ID to AMQPClient#channel.

To post a comment you must log in.
Revision history for this message
Thomas Herve (therve) wrote :

It would be nice to add at least one test for the new functionality. A couple of docstrings would be welcome too.

And sorry for taking so long to look at it...

review: Needs Fixing
Revision history for this message
Daniel Néri (dne) wrote :

Thanks; I'll have a look at adding tests and docstrings.

I've also realised that IDs of closed channels should be reused, to avoid that self.channels fills up with "closed" AMQPChannel instances.

Unmerged revisions

52. By Daniel Néri

Merge w/ lp:txamqp

51. By Daniel Néri

Add support for automatic allocation of unused channel ID

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/txamqp/protocol.py'
2--- src/txamqp/protocol.py 2010-04-14 20:07:01 +0000
3+++ src/txamqp/protocol.py 2010-08-20 12:41:05 +0000
4@@ -258,13 +258,23 @@
5 def check_0_8(self):
6 return (self.spec.minor, self.spec.major) == (0, 8)
7
8+ def _alloc_channel_id(self):
9+ for i in xrange(1, 65536):
10+ if i not in self.channels:
11+ return i
12+ raise RuntimeError('No unused channel id available')
13+
14 @defer.inlineCallbacks
15- def channel(self, id):
16+ def channel(self, id=None):
17 yield self.channelLock.acquire()
18 try:
19- try:
20- ch = self.channels[id]
21- except KeyError:
22+ ch = None
23+ if id is not None:
24+ if id in self.channels:
25+ ch = self.channels[id]
26+ else:
27+ id = self._alloc_channel_id()
28+ if not ch:
29 ch = self.channelFactory(id, self.outgoing)
30 self.channels[id] = ch
31 finally:

Subscribers

People subscribed via source and target branches

to status/vote changes: