/** * @inheritdoc */ public function handleMessage(AbstractMessage $message, ConnectionInterface $sender) { // Wrap database exceptions in the more generic RequestFailedException try { switch ($message->getType()) { case AbstractMessage::TYPE_POPULAR_CHANNELS_REQUEST: /* @var PopularChannelsRequest $message */ return new PopularChannelsResponse($message, $this->getPopularChannels($message->getInstanceName(), $message->getUserName(), $message->getLimit(), $message->getTimeFrame())); case AbstractMessage::TYPE_MOST_ACTIVE_WATCHERS_REQUEST: /* @var MostActiveWatchersRequest $message */ return new MostActiveWatchersResponse($message, $this->getMostActiveWatchers($message->getInstanceName(), $message->getLimit(), $message->getTimeFrame())); case AbstractMessage::TYPE_INSTANCES_REQUEST: /* @var InstancesRequest $message */ return new InstancesResponse($this->configuration->getInstances()); case AbstractMessage::TYPE_USERS_REQUEST: /* @var UsersRequest $message */ return new UsersResponse($this->getUsers($message->getInstanceName())); } } catch (PropelException $e) { throw new RequestFailedException('A database error occured: ' . $e->getMessage()); } return false; }