Exemplo n.º 1
1
boost::shared_ptr<IHttpResponse> HttpClient::sendRequest(const IHttpRequest& request)
{
    KAA_MUTEX_LOCKING("guard_");
    boost::unique_lock<boost::mutex> lock(guard_);
    KAA_MUTEX_LOCKED("guard_");
    if (sock_.is_open()) {
        doSocketClose();
    }
    KAA_LOG_INFO(boost::format("Sending request to the server %1%:%2%") % request.getHost() % request.getPort());
    const auto& ep = HttpUtils::getEndpoint(request.getHost(), request.getPort());
    const auto& data = request.getRequestData();
    boost::system::error_code errorCode;
    sock_.open(ep.protocol(), errorCode);
    checkError(errorCode);
    sock_.connect(ep, errorCode);
    checkError(errorCode);
    boost::asio::write(sock_, boost::asio::buffer(data.data(), data.size()), errorCode);
    checkError(errorCode);
    std::ostringstream responseStream;
    boost::asio::streambuf responseBuf;
    while (boost::asio::read(sock_, responseBuf, boost::asio::transfer_at_least(1), errorCode)) {
        responseStream << &responseBuf;
    }
    checkError(errorCode);
    const std::string& responseStr = responseStream.str();
    KAA_LOG_INFO(boost::format("Response from server %1%:%2% successfully received") % request.getHost() % request.getPort());
    doSocketClose();
    return boost::shared_ptr<IHttpResponse>(new HttpResponse(responseStr));
}
Exemplo n.º 2
0
void KaaChannelManager::onTransportConnectionInfoUpdated(ITransportConnectionInfoPtr connectionInfo) {
    if (isShutdown_) {
        KAA_LOG_WARN("Can't update server. Channel manager is down");
        return;
    }
    if (!connectionInfo) {
        KAA_LOG_WARN("Failed to update connection info: bad input data")
        throw KaaException("empty connection info pointer");
    }

    connectionInfo->resetFailedState();

    TransportProtocolId protocolId = connectionInfo->getTransportId();
    if (connectionInfo->getServerType() == ServerType::OPERATIONS) {
        KAA_MUTEX_LOCKING("lastOpsServersGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(lastOpsServers_Lock, lastOpsServersGuard_);
        KAA_MUTEX_LOCKED("lastOpsServersGuard_");

        lastOpsServers_[protocolId] = connectionInfo;
    }

    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_R_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    for (auto& channel : channels_) {
        if (channel->getServerType() == connectionInfo->getServerType() && channel->getTransportProtocolId() == protocolId) {
            KAA_LOG_DEBUG(boost::format("Setting a new connection data for channel \"%1%\" %2%")
                        % channel->getId() % LoggingUtils::TransportProtocolIdToString(protocolId));
            channel->setServer(connectionInfo);
        }
    }
}
Exemplo n.º 3
0
void DefaultOperationTcpChannel::onPingTimeout(const boost::system::error_code& err)
{
    if (!err) {
        sendPingRequest();
    } else {
        KAA_MUTEX_LOCKING("channelGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
        KAA_MUTEX_LOCKED("channelGuard_");
        if (err != boost::asio::error::operation_aborted && isConnected_) {
            KAA_MUTEX_UNLOCKING("channelGuard_");
            KAA_UNLOCK(channelLock);
            KAA_MUTEX_UNLOCKED("channelGuard_")

            KAA_LOG_ERROR(boost::format("Channel [%1%] failed to process PING: %2%") % getId() % err.message());
            onServerFailed();
            return;
        } else {
            KAA_LOG_DEBUG(boost::format("Channel [%1%] PING timer aborted") % getId());
            return;
        }
    }

    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    if (isConnected_) {
        setPingTimer();
    }
}
Exemplo n.º 4
0
void EventManager::setTransport(EventTransport *transport)
{
    eventTransport_ = transport;

    if (eventTransport_) {
        bool needSync = false;
        {
            KAA_MUTEX_LOCKING("pendingEventsGuard_");
            KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
            KAA_MUTEX_LOCKED("pendingEventsGuard_");
            needSync = !pendingEvents_.empty();
            KAA_MUTEX_UNLOCKED("pendingEventsGuard_");
        }

        if (!needSync) {
            KAA_MUTEX_LOCKING("eventListenersGuard_");
            KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
            KAA_MUTEX_LOCKED("eventListenersGuard_");
            needSync = !eventListenersRequests_.empty();
            KAA_MUTEX_UNLOCKED("eventListenersGuard_");
        }

        if (needSync) {
            doSync();
        }
    }
}
Exemplo n.º 5
0
void KaaChannelManager::clearChannelList()
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_R_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    KAA_MUTEX_LOCKING("mappedChannelGuard_");
    KAA_R_MUTEX_UNIQUE_DECLARE(mappedChannelLock, mappedChannelGuard_);
    KAA_MUTEX_LOCKED("mappedChannelGuard_");

    channels_.clear();
    mappedChannels_.clear();
}
Exemplo n.º 6
0
void LogCollector::onLogUploadResponse(const LogSyncResponse& response)
{
    KAA_MUTEX_LOCKING("storageGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(storageGuardLock, storageGuard_);
    KAA_MUTEX_LOCKED("storageGuard_");

    if (!response.deliveryStatuses.is_null()) {
        const auto& deliveryStatuses = response.deliveryStatuses.get_array();
        for (const auto& status : deliveryStatuses) {
            if (!removeDeliveryTimeout(status.requestId)) {
                continue;
            }

            if (status.result == SyncResponseResultType::SUCCESS) {
                KAA_LOG_INFO(boost::format("Logs (requestId %ld) successfully delivered") % status.requestId);
                storage_->removeRecordBlock(status.requestId);
            } else {
                storage_->notifyUploadFailed(status.requestId);

                KAA_MUTEX_UNLOCKING("storageGuard_");
                KAA_UNLOCK(storageGuardLock);
                KAA_MUTEX_UNLOCKED("storageGuard_");

                if (!status.errorCode.is_null()) {
                    auto errocCode = status.errorCode.get_LogDeliveryErrorCode();
                    KAA_LOG_WARN(boost::format("Logs (requestId %ld) failed to deliver (error %d)")
                                            % status.requestId % (int)errocCode);

                    executorContext_.getCallbackExecutor().add([this, errocCode] ()
                            {
                                uploadStrategy_->onFailure(*this, errocCode);
                            });
                } else {
                    KAA_LOG_WARN("Log delivery failed, but no error code received");
                }

                KAA_MUTEX_LOCKING("storageGuard_");
                KAA_LOCK(storageGuardLock);
                KAA_MUTEX_LOCKED("storageGuard_");
            }
        }
    }

    KAA_MUTEX_UNLOCKING("storageGuard_");
    KAA_UNLOCK(storageGuardLock);
    KAA_MUTEX_UNLOCKED("storageGuard_");

    processLogUploadDecision(uploadStrategy_->isUploadNeeded(storage_->getStatus()));
}
Exemplo n.º 7
0
std::int32_t EventManager::findEventListeners(const std::list<std::string>& eventFQNs, IFetchEventListenersPtr listener)
{
    if (eventFQNs.empty() || !listener) {
        KAA_LOG_WARN("Failed to add event listeners request: bad input data");
        throw KaaException("Bad event listeners data");
    }

    std::int32_t requestId = UuidGenerator::generateRandomInt();

    std::shared_ptr<EventListenersInfo> info(new EventListenersInfo);
    info->eventFQNs_ = eventFQNs;
    info->listener_ = listener;

    {
        KAA_MUTEX_LOCKING("eventListenersGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
        KAA_MUTEX_LOCKED("eventListenersGuard_");

        eventListenersRequests_.insert(std::make_pair(requestId, info));
        KAA_MUTEX_UNLOCKED("eventListenersGuard_");
    }

    KAA_LOG_TRACE("Added event listeners resolving request");

    doSync();

    return requestId;
}
Exemplo n.º 8
0
void DefaultOperationTcpChannel::doShutdown()
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    KAA_LOG_DEBUG(boost::format("Channel [%1%] is shutting down: isShutdown '%2%'")
                                                    % getId()
                                                    % boost::io::group(std::boolalpha, isShutdown_));

    if (!isShutdown_) {
        isShutdown_ = true;
        KAA_MUTEX_UNLOCKING("channelGuard_");
        KAA_UNLOCK(lock);
        KAA_MUTEX_UNLOCKED("channelGuard_");

        closeConnection();

        KAA_LOG_TRACE(boost::format("Channel [%1%] stopping IO service: isStopped '%2%'")
                                                    % getId()
                                                    % boost::io::group(std::boolalpha, io_.stopped()));

        if (!io_.stopped()) {
            io_.stop();
        }

        stopThreads();
    }
}
Exemplo n.º 9
0
void DefaultOperationTcpChannel::setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");
    demultiplexer_ = demultiplexer;
}
Exemplo n.º 10
0
void AbstractHttpChannel::sync(TransportType type)
{
    const auto& supportedTypes = getSupportedTransportTypes();
    auto it = supportedTypes.find(type);
    if (it == supportedTypes.end() || it->second == ChannelDirection::DOWN) {
        KAA_LOG_ERROR(boost::format("Channel [%1%] unsupported transport type '%2%'")
                                                        % getId()
                                                        % LoggingUtils::toString(type));
        return;
    }

    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    if (!currentServer_) {
        KAA_LOG_WARN(boost::format("Channel [%1%] can't sync: server is null") % getId());
        return;
    }

    processTypes(std::map<TransportType, ChannelDirection>({ { type, it->second } })
#ifdef KAA_THREADSAFE
               , lock
#endif
                );

}
Exemplo n.º 11
0
void DefaultOperationTcpChannel::closeConnection()
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    bool wasConnected = isConnected_;

    KAA_LOG_TRACE(boost::format("Channel [%1%] closing connection: isConnected '%2%'")
                                                        % getId()
                                                        % boost::io::group(std::boolalpha, wasConnected));

    isFirstResponseReceived_ = false;
    isConnected_ = false;
    isPendingSyncRequest_ = false;

    KAA_MUTEX_UNLOCKING("channelGuard_");
    KAA_UNLOCK(lock);
    KAA_MUTEX_UNLOCKED("channelGuard_");

    if (wasConnected) {
        pingTimer_.cancel();
        connAckTimer_.cancel();
        sendDisconnect();
        boost::system::error_code errorCode;
        sock_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode);
        sock_->close(errorCode);
        responseProcessor.flush();
    }
}
Exemplo n.º 12
0
bool EventManager::hasPendingEvents() const
{
    KAA_MUTEX_LOCKING("pendingEventsGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
    KAA_MUTEX_LOCKED("pendingEventsGuard_");
    return !pendingEvents_.empty();
}
Exemplo n.º 13
0
std::shared_ptr<LogSyncRequest> LogCollector::getLogUploadRequest()
{
    ILogStorage::RecordPack recordPack;
    std::shared_ptr<LogSyncRequest> request;

    {
        KAA_MUTEX_LOCKING("storageGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(storageGuardLock, storageGuard_);
        KAA_MUTEX_LOCKED("storageGuard_");

        recordPack = storage_->getRecordBlock(uploadStrategy_->getBatchSize(), uploadStrategy_->getRecordsBatchCount());
    }

    if (!recordPack.second.empty()) {
        request.reset(new LogSyncRequest);
        request->requestId = recordPack.first;

        std::vector<LogEntry> logs;
        logs.reserve(recordPack.second.size());
        for (const auto& log : recordPack.second) {
            logs.push_back(log->getLogEntry());
        }

        request->logEntries.set_array(std::move(logs));
        addDeliveryTimeout(request->requestId);
    }

    return request;
}
Exemplo n.º 14
0
bool LogCollector::isDeliveryTimeout()
{

    KAA_MUTEX_LOCKING("timeoutsGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(timeoutsGuardLock, timeoutsGuard_);
    KAA_MUTEX_LOCKED("timeoutsGuard_");

    auto now = clock_t::now();

    IDataChannelPtr logChannel = channelManager_->getChannelByTransportType(TransportType::LOGGING);
    std::int32_t currentAccessPointId  = 0;
    if (logChannel && logChannel->getServer()) {
        currentAccessPointId = logChannel->getServer()->getAccessPointId();
    }

    bool isTimeout = false;
    timeoutAccessPointId_ = 0;

    for (const auto& request : timeouts_) {
        if (now >= request.second.getTimeoutTime()) {
            KAA_LOG_WARN(boost::format("Log delivery timeout detected, bucket id %li") % request.first);
            isTimeout = true;
            timeoutAccessPointId_ = request.second.getTransportAccessPointId();
            // Check if current access point already has timeout
            if (timeoutAccessPointId_ == currentAccessPointId) {
                break;
            }
        }
    }

    return isTimeout;
}
Exemplo n.º 15
0
void AbstractHttpChannel::setDemultiplexer(IKaaDataDemultiplexer *demultiplexer)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");
    demultiplexer_ = demultiplexer;
}
Exemplo n.º 16
0
void ConfigurationPersistenceManager::onConfigurationUpdated(const KaaRootConfiguration& configuration)
{
    if (ignoreConfigurationUpdate_) {
        ignoreConfigurationUpdate_ = false;
        return;
    }

    KAA_LOG_INFO("Configuration updated.");

    AvroByteArrayConverter<KaaRootConfiguration> converter;
    SharedDataBuffer buffer = converter.toByteArray(configuration);

    KAA_LOG_INFO(boost::format("Going to store configuration using configuration storage %1%") % storage_);

    KAA_MUTEX_LOCKING("confPersistenceGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(confPersistenceGuardLock, confPersistenceGuard_);
    KAA_MUTEX_LOCKED("confPersistenceGuard_");

    if (storage_) {
        storage_->saveConfiguration(std::vector<std::uint8_t>(buffer.first.get(), buffer.first.get() + buffer.second));
    }

    KAA_MUTEX_UNLOCKING("confPersistenceGuard_");
    KAA_UNLOCK(confPersistenceGuardLock);
    KAA_MUTEX_UNLOCKED("confPersistenceGuard_");

    configurationHash_ = EndpointObjectHash(buffer);

    KAA_LOG_INFO(boost::format("Calculated configuration hash: %1%") % LoggingUtils::ByteArrayToString(configurationHash_.getHashDigest()));
}
Exemplo n.º 17
0
void DefaultOperationTcpChannel::onReadEvent(const boost::system::error_code& err)
{
    if (!err) {
        std::ostringstream responseStream;
        responseStream << responseBuffer_.get();
        const auto& responseStr = responseStream.str();
        try {
            if (responseStr.empty()) {
                 KAA_LOG_ERROR(boost::format("Channel [%1%] no data read from socket") % getId());
            } else {
                responseProcessor.processResponseBuffer(responseStr.data(), responseStr.size());
            }
        } catch (const TransportRedirectException& exception) {
            KAA_LOG_INFO(boost::format("Channel [%1%] received REDIRECT response") % getId());
            return;
        } catch (const KaaException& exception) {
            KAA_LOG_ERROR(boost::format("Channel [%1%] failed to process data: %2%") % getId() % exception.what());
            onServerFailed();
        }
    } else {
        KAA_LOG_WARN(boost::format("Channel [%1%] socket error: %2%") % getId() % err.message());

        KAA_MUTEX_LOCKING("channelGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
        KAA_MUTEX_LOCKED("channelGuard_");

        if (err != boost::asio::error::operation_aborted && isConnected_) {
            KAA_MUTEX_UNLOCKING("channelGuard_");
            KAA_UNLOCK(channelLock);
            KAA_MUTEX_UNLOCKED("channelGuard_")

            onServerFailed();
            return;
        } else {
            KAA_LOG_DEBUG(boost::format("Channel [%1%] socket operations aborted") % getId());
            return;
        }
    }

    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    if (isConnected_) {
        readFromSocket();
    }
}
Exemplo n.º 18
0
void LogCollector::setTransport(LoggingTransport* transport)
{
    KAA_MUTEX_LOCKING("transportGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(transportGuardLock, transportGuard_);
    KAA_MUTEX_LOCKED("transportGuard_");

    transport_ = transport;
}
Exemplo n.º 19
0
bool LogCollector::removeDeliveryTimeout(std::int32_t requestId)
{
    KAA_MUTEX_LOCKING("timeoutsGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(timeoutsGuardLock, timeoutsGuard_);
    KAA_MUTEX_LOCKED("timeoutsGuard_");

    return timeouts_.erase(requestId);
}
Exemplo n.º 20
0
bool EventManager::hasPendingListenerRequests() const
{
    KAA_MUTEX_LOCKING("eventListenersGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
    KAA_MUTEX_LOCKED("eventListenersGuard_");

    return !eventListenersRequests_.empty();
}
Exemplo n.º 21
0
void ConfigurationManager::setConfigurationStorage(IConfigurationStoragePtr storage)
{
    KAA_MUTEX_LOCKING("configurationGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(configurationGuardLock, configurationGuard_);
    KAA_MUTEX_LOCKED("configurationGuard_");

    storage_ = storage;
}
Exemplo n.º 22
0
bool KaaChannelManager::addChannelToList(IDataChannelPtr channel)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_R_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    auto res = channels_.insert(channel);

    if (res.second) {
    	channel->setFailoverStrategy(failoverStrategy_);
        channel->setConnectivityChecker(connectivityChecker_);

        ITransportConnectionInfoPtr connectionInfo;

        TransportProtocolId protocolId = channel->getTransportProtocolId();
        if (channel->getServerType() == ServerType::BOOTSTRAP) {
            connectionInfo = getCurrentBootstrapServer(protocolId);
        } else {
            KAA_MUTEX_LOCKING("lastOpsServersGuard_");
            KAA_MUTEX_UNIQUE_DECLARE(lastOpsServers_Lock, lastOpsServersGuard_);
            KAA_MUTEX_LOCKED("lastOpsServersGuard_");

            auto it = lastOpsServers_.find(channel->getTransportProtocolId());
            if (it != lastOpsServers_.end()) {
                connectionInfo = it->second;
            }
        }

        if (connectionInfo) {
            KAA_LOG_DEBUG(boost::format("Setting a new server for channel \"%1%\" %2%")
                        % channel->getId() % LoggingUtils::TransportProtocolIdToString(protocolId));
            channel->setServer(connectionInfo);
        } else {
            if (channel->getServerType() == ServerType::BOOTSTRAP) {
                KAA_LOG_WARN(boost::format("Failed to find bootstrap server for channel \"%1%\" %2%")
                            % channel->getId() % LoggingUtils::TransportProtocolIdToString(protocolId));
            } else {
                KAA_LOG_INFO(boost::format("Failed to find operations server for channel \"%1%\" %2%")
                            % channel->getId() % LoggingUtils::TransportProtocolIdToString(protocolId));
            }
        }
    }

    return res.second;
}
Exemplo n.º 23
0
std::list<IDataChannelPtr> KaaChannelManager::getChannels()
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_R_MUTEX_UNIQUE_DECLARE(channelLock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    std::list<IDataChannelPtr> channels(channels_.begin(), channels_.end());
    return channels;
}
Exemplo n.º 24
0
boost::system::error_code DefaultOperationTcpChannel::sendKaaSync(const std::map<TransportType, ChannelDirection>& transportTypes)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");
    KAA_LOG_DEBUG(boost::format("Channel [%1%] sending KAASYNC") % getId());
    const auto& requestBody = multiplexer_->compileRequest(transportTypes);
    const auto& requestEncoded = encDec_->encodeData(requestBody.data(), requestBody.size());
    return sendData(KaaSyncRequest(false, true, 0, requestEncoded, KaaSyncMessageType::SYNC));
}
Exemplo n.º 25
0
void DefaultOperationTcpChannel::sync(TransportType type)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    if (isShutdown_) {
        KAA_LOG_WARN(boost::format("Channel [%1%] can't sync: channel is shut down") % getId());
        return;
    }

    if (isPaused_) {
        KAA_LOG_WARN(boost::format("Channel [%1%] can't sync: channel is paused") % getId());
        return;
    }

    const auto& suppportedTypes = getSupportedTransportTypes();
    auto it = suppportedTypes.find(type);
    if (it == suppportedTypes.end() || it->second == ChannelDirection::DOWN) {
        KAA_LOG_ERROR(boost::format("Channel [%1%] ignore sync: unsupported transport type %2%")
                                                                        % getId()
                                                                        % LoggingUtils::toString(type));
        return;
    }

    if (!currentServer_) {
        KAA_LOG_DEBUG(boost::format("Channel [%1%] can't sync: server is null") % getId());
        return;
    }

    if (isFirstResponseReceived_) {
        KAA_MUTEX_UNLOCKING("channelGuard_");
        KAA_UNLOCK(lock);
        KAA_MUTEX_UNLOCKED("channelGuard_");

        std::map<TransportType, ChannelDirection> syncTypes;
        syncTypes.insert(std::make_pair(type, it->second));
        for (const auto& typeIt : suppportedTypes) {
            if (typeIt.first != type) {
                syncTypes.insert(std::make_pair(typeIt.first, ChannelDirection::DOWN));
            }
        }

        boost::system::error_code errorCode = sendKaaSync(syncTypes);
        if (errorCode) {
            KAA_LOG_ERROR(boost::format("Channel [%1%] failed to sync: %2%")
                                                                % getId()
                                                                % errorCode.message());
            onServerFailed();
        }
    } else {
        KAA_LOG_DEBUG(boost::format("Channel [%1%] can't sync: waiting for CONNACK + KAASYNC") % getId());
        isPendingSyncRequest_ = true;
    }
}
Exemplo n.º 26
0
void ConfigurationPersistenceManager::setConfigurationStorage(IConfigurationStoragePtr storage)
{
    if (storage) {
        KAA_MUTEX_LOCKING("confPersistenceGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(lock, confPersistenceGuard_);
        KAA_MUTEX_LOCKED("confPersistenceGuard_");

        storage_ = storage;
        readStoredConfiguration();
    }
}
Exemplo n.º 27
0
void DefaultOperationTcpChannel::syncAck(TransportType type)
{
    KAA_MUTEX_LOCKING("channelGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(lock, channelGuard_);
    KAA_MUTEX_LOCKED("channelGuard_");

    KAA_LOG_DEBUG(boost::format("Channel [%1%] adding ACK for transport '%2%'")
                                                        % getId()
                                                        % LoggingUtils::toString(type));
    ackTypes_.push_back(type);
}
Exemplo n.º 28
0
std::map<std::int32_t, Event> EventManager::releasePendingEvents()
{
    KAA_MUTEX_LOCKING("pendingEventsGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
    KAA_MUTEX_LOCKED("pendingEventsGuard_");

    std::map<std::int32_t, Event> result(std::move(pendingEvents_));
    pendingEvents_ = std::map<std::int32_t, Event>();
    currentEventIndex_ = 0;
    return result;
}
Exemplo n.º 29
0
const KaaRootConfiguration& ConfigurationManager::getConfiguration()
{
    KAA_MUTEX_LOCKING("configurationGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(configurationGuardLock, configurationGuard_);
    KAA_MUTEX_LOCKED("configurationGuard_");

    if (!isConfigurationLoaded_) {
        loadConfiguration();
    }

    return configuration_;
}
Exemplo n.º 30
0
void ConfigurationManager::init()
{
    KAA_MUTEX_LOCKING("configurationGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(configurationGuardLock, configurationGuard_);
    KAA_MUTEX_LOCKED("configurationGuard_");

    if (!isConfigurationLoaded_) {
        loadConfiguration();
    }

    notifySubscribers(configuration_);
}