/** * Acquire an unused channel. * * @recoil-coroutine */ public function acquireChannel(Channel $channel = null) : Generator { // The connection is not open ... if ($this->state !== ConnectionState::OPEN) { throw SingleConnectionException::notOpen($this->options); } if ($channel !== null) { $channelId = $channel->id(); $channelManager = $this->channels[$channelId] ?? null; if ($channelManager === null) { throw ChannelException::notOpen($channelId); } return $channelManager; } // Check for previously released channels that can be used instead of // asking the broker for a new one ... foreach ($this->availableChannels as $channelId => $channelManager) { unset($this->availableChannels[$channelId], $this->availableChannelHeartbeats[$channelId]); return $channelManager; } $channelId = $this->findChannelId(); // Open a new channel ... $channelManager = new ChannelManager($channelId, $this, $this->transport, $this->tune->frameMax); $this->channels[$channelId] = $channelManager; (yield $channelManager->open()); return $channelManager; }
/** * @param ChannelManager $channelManager The channel used to communicate with the broker. * @param Features $features The broker's supported features. */ public function __construct(ChannelManager $channelManager, Features $features) { $this->channelId = $channelManager->id(); $this->channelManager = $channelManager; $this->features = $features; }