def __init__(self, connection, **kwargs): self.connection = connection self._consumers = set() self._cycle = None self._tag_to_queue = {} self._active_queues = [] self._qos = None self.closed = False # instantiate exchange types self.exchange_types = dict( (typ, cls(self)) for typ, cls in items(self.exchange_types)) try: self.channel_id = self.connection._avail_channel_ids.pop() except IndexError: raise ResourceError( 'No free channel ids, current={0}, channel_max={1}'.format( len(self.connection.channels), self.connection.channel_max), (20, 10), ) topts = self.connection.client.transport_options for opt_name in self.from_transport_options: try: setattr(self, opt_name, topts[opt_name]) except KeyError: pass
def _get_free_channel_id(self): # Cast to a set for fast lookups, and keep stored as an array # for lower memory usage. used_channel_ids = set(self.connection._used_channel_ids) for channel_id in range(1, self.connection.channel_max + 1): if channel_id not in used_channel_ids: self.connection._used_channel_ids.append(channel_id) return channel_id raise ResourceError( 'No free channel ids, current={}, channel_max={}'.format( len(self.connection.channels), self.connection.channel_max), (20, 10), )