void Channel::fastReconnect() { qDebug() << "fast reconnecting"; /* if (LPrep != NULL) { LPrep->close(); delete LPrep; } */ QTimer::singleShot(500, this, SLOT(longPollRequest())); }
void Channel::checkChannel() { qDebug() << "Checking chnl"; if (lastPushReceived.secsTo(QDateTime::currentDateTime()) > 30) { qDebug() << "Dead, here I should sync al evts from last ts and notify QML that we're offline"; qDebug() << "start new lpconn"; channelError = true; emit(channelLost()); /* if (LPrep != NULL) { LPrep->close(); delete LPrep; } */ QTimer::singleShot(500, this, SLOT(longPollRequest())); } }
void LongPollingMessageReceiver::run() { checkServerTime(); std::string createChannelUrl = bounceProxyUrl.getCreateChannelUrl(channelId).toString(); JOYNR_LOG_INFO(logger, "Running lpmr with channelId {}", channelId); std::shared_ptr<IHttpPostBuilder> createChannelRequestBuilder( HttpNetworking::getInstance()->createHttpPostBuilder(createChannelUrl)); std::shared_ptr<HttpRequest> createChannelRequest( createChannelRequestBuilder->addHeader("X-Atmosphere-tracking-id", receiverId) ->withContentType("application/json") ->withTimeout(settings.bounceProxyTimeout) ->build()); std::string channelUrl; while (channelUrl.empty() && !isInterrupted()) { JOYNR_LOG_DEBUG(logger, "sending create channel request"); HttpResult createChannelResult = createChannelRequest->execute(); if (createChannelResult.getStatusCode() == 201) { channelUrl = *createChannelResult.getHeaders().find("Location"); JOYNR_LOG_INFO(logger, "channel creation successfull; channel url: {}", channelUrl); channelCreatedSemaphore->notify(); } else { JOYNR_LOG_INFO(logger, "channel creation failed); status code: {}", createChannelResult.getStatusCode()); std::unique_lock<std::mutex> lock(interruptedMutex); interruptedWait.wait_for(lock, settings.createChannelRetryInterval); } } /** * register the channelUrl with the ChannelUrlDirectory (asynchronously) */ assert(channelUrlDirectory != nullptr); types::ChannelUrlInformation urlInformation; std::vector<std::string> urls = {channelUrl}; urlInformation.setUrls(urls); JOYNR_LOG_INFO( logger, "Adding channelId and Url of cluster controller to remote ChannelUrlDirectory {}", channelUrl); channelUrlDirectory->registerChannelUrlsAsync(channelId, urlInformation); while (!isInterrupted()) { std::shared_ptr<IHttpGetBuilder> longPollRequestBuilder( HttpNetworking::getInstance()->createHttpGetBuilder(channelUrl)); std::shared_ptr<HttpRequest> longPollRequest( longPollRequestBuilder->acceptGzip() ->addHeader("Accept", "application/json") ->addHeader("X-Atmosphere-tracking-id", receiverId) ->withTimeout(settings.longPollTimeout) ->build()); JOYNR_LOG_DEBUG(logger, "sending long polling request; url: {}", channelUrl); HttpResult longPollingResult = longPollRequest->execute(); if (!isInterrupted()) { // TODO: remove HttpErrorCodes and use constants. // there is a bug in atmosphere, which currently gives back 503 instead of 200 as a // result to longpolling. // Accepting 503 is a temporary workaround for this bug. As soon as atmosphere is fixed, // this should be removed // 200 does nott refect the state of the message body! It could be empty. if (longPollingResult.getStatusCode() == 200 || longPollingResult.getStatusCode() == 503) { Util::logSerializedMessage(logger, "long polling successful; contents: ", longPollingResult.getBody().data()); processReceivedInput(longPollingResult.getBody()); // Atmosphere currently cannot return 204 when a long poll times out, so this code // is currently never executed (2.2.2012) } else if (longPollingResult.getStatusCode() == 204) { JOYNR_LOG_DEBUG(logger, "long polling successfull);full; no data"); } else { std::string body("NULL"); if (!longPollingResult.getBody().isNull()) { body = QString(longPollingResult.getBody().data()).toStdString(); } JOYNR_LOG_ERROR(logger, "long polling failed; error message: {}; contents: {}", longPollingResult.getErrorMessage(), body); std::unique_lock<std::mutex> lock(interruptedMutex); interruptedWait.wait_for(lock, settings.createChannelRetryInterval); } } } }