/** * Notify handlers about exception * * @param RequestDescriptor $requestDescriptor Socket operation object * @param SocketException $exception Thrown exception * * @return void * @throws \Exception */ protected function callExceptionSubscribers(RequestDescriptor $requestDescriptor, SocketException $exception) { try { $this->eventCaller->setCurrentOperation($requestDescriptor); $this->eventCaller->callExceptionSubscribers($requestDescriptor, $exception); $this->eventCaller->clearCurrentOperation(); } catch (\Exception $e) { $this->eventCaller->clearCurrentOperation(); throw $e; } }
/** {@inheritdoc} */ public function executeRequest() { if ($this->isExecuting()) { throw new \BadMethodCallException('Request is already in progress'); } $this->isRequestStopped = false; $this->solver = $this->solver ?: new NoLimitationSolver(); $this->isExecuting = true; $eventCaller = new EventCaller($this); try { foreach ($this->eventHandlers as $handler) { $eventCaller->addHandler($handler); } if ($this->solver instanceof EventHandlerInterface) { $eventCaller->addHandler($this->solver); } $this->initializeRequest($eventCaller); $eventCaller->addHandler($this); $this->solver->initialize($this); $this->doExecuteRequest($eventCaller); $this->solver->finalize($this); $this->terminateRequest(); } catch (StopRequestExecuteException $e) { $this->isRequestStopInProgress = true; $this->disconnectItems($this->socketBag->getItems()); } catch (SocketException $e) { foreach ($this->socketBag->getItems() as $item) { $eventCaller->setCurrentOperation($item); $eventCaller->callExceptionSubscribers($item, $e); } $this->disconnectItems($this->socketBag->getItems()); } catch (\Exception $e) { $this->isExecuting = false; $this->emergencyShutdown(); $this->solver->finalize($this); $this->terminateRequest(); throw $e; } $this->solver->finalize($this); $this->terminateRequest(); $this->isExecuting = false; }