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
=== modified file 'src/txamqp/protocol.py'
--- src/txamqp/protocol.py 2010-04-14 20:07:01 +0000
+++ src/txamqp/protocol.py 2010-08-20 12:41:05 +0000
@@ -258,13 +258,23 @@
258 def check_0_8(self):258 def check_0_8(self):
259 return (self.spec.minor, self.spec.major) == (0, 8)259 return (self.spec.minor, self.spec.major) == (0, 8)
260260
261 def _alloc_channel_id(self):
262 for i in xrange(1, 65536):
263 if i not in self.channels:
264 return i
265 raise RuntimeError('No unused channel id available')
266
261 @defer.inlineCallbacks267 @defer.inlineCallbacks
262 def channel(self, id):268 def channel(self, id=None):
263 yield self.channelLock.acquire()269 yield self.channelLock.acquire()
264 try:270 try:
265 try:271 ch = None
266 ch = self.channels[id]272 if id is not None:
267 except KeyError:273 if id in self.channels:
274 ch = self.channels[id]
275 else:
276 id = self._alloc_channel_id()
277 if not ch:
268 ch = self.channelFactory(id, self.outgoing)278 ch = self.channelFactory(id, self.outgoing)
269 self.channels[id] = ch279 self.channels[id] = ch
270 finally:280 finally:

Subscribers

People subscribed via source and target branches

to status/vote changes: