Exemplo n.º 1
0
bool GroupTagSubscription::includes (Subscription *pSubscription)
{
    if (pSubscription->getSubscriptionType() == GROUP_TAG_SUBSCRIPTION) {
        GroupTagSubscription *pGTS = (GroupTagSubscription*) pSubscription;
        LList<uint16> *pTags = pGTS->getTags();
        uint16 ui16Tag;
        pTags->getFirst (ui16Tag);
        for (int i = 0; i < pTags->length; i++) {
            if (!_ui16Tags.contains (ui16Tag)) {
                return false;
            }
            pTags->getNext (ui16Tag);
        }
        return true;
    }
    return false;
}
Exemplo n.º 2
0
void PositionUpdater::doMetadataArrived (StringHashtable<MsgIdList > *pMsgToNotifyByQueryId)
{
    if (pMsgToNotifyByQueryId == nullptr) {
        return;
    }
    const char *pszMethodName = "PositionUpdater::doMetadataArrived";

    String msgId;
    StringHashtable<LList<String> >::Iterator iter = pMsgToNotifyByQueryId->getAllElements();
    for (; !iter.end(); iter.nextElement()) {
        const char *pszQueryId = iter.getKey();
        LList<String> *pMsgToNotify = iter.getValue();

        for (int rc = pMsgToNotify->getFirst (msgId); rc == 1; rc = pMsgToNotify->getNext (msgId)) {

            MessageHeaders::MsgType type;
            Message *pMessage = getCompleteMessageAndRemoveDSProMetadata (_pDSPro->_pDataStore, msgId.c_str(), type);
            if (pMessage == nullptr || (type != MessageHeaders::Data && type != MessageHeaders::Metadata)) {
                // The message to be notified to the application was not found at
                // this time. Re-add it to the list of messages to notify so it can
                // be tried again later.
                static const char * messageIds[2];
                messageIds[0] = msgId.c_str();
                messageIds[1] = nullptr;
                addMetadataToNotify (pszQueryId, messageIds);
            }
            else {
                MessageInfo *pMI = pMessage->getMessageInfo();
                char *pszId = convertFieldToKey (pMI->getGroupName(), pMI->getPublisherNodeId(), pMI->getMsgSeqId());
                const String currMsgId (pszId);
                if (pszId == nullptr) {
                    checkAndLogMsg (pszMethodName, memoryExhausted);
                }
                else {
                    free (pszId);
                    pszId = nullptr;
                }
                String sGrpName (MessageIdGenerator::extractSubgroupFromMsgGroup (pMI->getGroupName()));
                if (sGrpName.length() <= 0) {
                    checkAndLogMsg (pszMethodName, Logger::L_MildError, "could not extract group message id\n");
                    sGrpName = pMI->getGroupName();
                }

                if (type == MessageHeaders::Metadata) {
                    MetaData *pMetadata = toMetadata (pMessage->getData(), pMI->getTotalMessageLength());
                    if (pMetadata != nullptr) {
                        String sReferredObjectId, sReferredInstanceId, sRefersTo;
                        getReferredObjectAndInstanceIds (pMetadata, sReferredObjectId, sReferredInstanceId, sRefersTo);
                        int rc = _pDSPro->metadataArrived (currMsgId, sGrpName, sReferredObjectId,
                                                           sReferredInstanceId, pMetadata, sRefersTo,
                                                           pszQueryId);
                        checkAndLogMsg (pszMethodName, Logger::L_Info, "notified clients "
                                        "with message %s matching query request %s\n/",
                                        currMsgId.c_str(), pszQueryId);
                        delete pMetadata;
                        pMetadata = nullptr;
                        if (rc != 0) {
                            checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not notify message "
                                            "with id = <%s> failed. Returned %d\n", currMsgId.c_str(), rc);
                        }
                        else {
                            checkAndLogMsg (pszMethodName, Logger::L_Info, "client applications "
                                            "notified message with id: <%s>.\n", currMsgId.c_str());
                        }
                    }
                }
                else {
                    // Data or chunked data
                    uint8 ui8ChunkIndex = pMI->getTotalNumberOfChunks() == 0 ? (uint8) 0 : 1; // HACK: For the general case I need to figure out the current number of chunks from the database
                    rc = _pDSPro->dataArrived (currMsgId, sGrpName, pMI->getObjectId(), pMI->getInstanceId(),
                                               pMI->getAnnotates(), pMI->getMimeType(), pMessage->getData(),
                                               pMI->getTotalMessageLength(), ui8ChunkIndex, pMI->getTotalNumberOfChunks(),
                                               pszQueryId);
                }

                free ((void*) pMessage->getData());
                delete pMessage->getMessageHeader();
                delete pMessage;
            }
        }
    }
}
Exemplo n.º 3
0
void PositionUpdater::run (void)
{
    const char *pszMethodName = "PositionUpdater::run";
    setName (pszMethodName);

    started();

    BufferWriter bw;
    do {
        _m.lock();
        if (!_bMessageRequested) {
            _cv.wait (DSPro::DEFAULT_UPDATE_TIMEOUT);
        }

        if (pTopoLog != nullptr) {
            if ((_pDSPro != nullptr) && (_pDSPro->_pTopology != nullptr)) {
                logTopology (pszMethodName, Logger::L_Info, "\n==== TOPOLOGY ===\n");
                _pDSPro->_pTopology->display (pTopoLog->getLogFileHandle());
                logTopology (pszMethodName, Logger::L_Info, "\n=================\n");
            }
        }

        LList<MsgIdWrapper> msgToRequestCpy;
        int64 i64Now = getTimeInMilliseconds();
        for (MsgIdWrapper *pMsgIdWr = _msgToRequest.getFirst(); pMsgIdWr != nullptr; pMsgIdWr = _msgToRequest.getNext()) {
            msgToRequestCpy.add (*pMsgIdWr); // copy the IDs of the message to request
            pMsgIdWr->ui64LatestRequestTime = i64Now;
        }
        _msgToRequest.removeAll();

        StringHashtable<LList<String> > *pMsgToNotify = _pMsgToNotify;
        _pMsgToNotify = new StringHashtable<LList<String> >(true, true, true, true);

        _m.unlock();

        MsgIdWrapper msgIdWr;
        for (int rc = msgToRequestCpy.getFirst (msgIdWr); rc == 1; rc = msgToRequestCpy.getNext (msgIdWr)) {
            int64 i64Elapsed = i64Now - msgIdWr.ui64LatestRequestTime;
            if (msgIdWr.ui64LatestRequestTime == 0U || (i64Elapsed > DSPro::DEFAULT_UPDATE_TIMEOUT)) {
                Targets **ppTargets;
                if (msgIdWr.senderId.length() <= 0) {
                    ppTargets = _pDSPro->_pTopology->getNeighborsAsTargets();
                }
                else {
                    ppTargets = _pDSPro->_pTopology->getForwardingTargets (_pDSPro->getNodeId(), msgIdWr.senderId);
                }
                if ((ppTargets != nullptr) && (ppTargets[0] != nullptr)) {
                    int rc = 0;
                    String publisher (msgIdWr.publisherId.length() <= 0 ? _pDSPro->getNodeId() : msgIdWr.publisherId.c_str());
                    if (isOnDemandDataID (msgIdWr.msgId)) {
                        rc = _pDSPro->_adaptMgr.sendChunkRequestMessage (msgIdWr.msgId, &(msgIdWr.locallyCachedChunkIds),
                                                                         publisher, ppTargets);
                    }
                    else {
                        rc = _pDSPro->_adaptMgr.sendMessageRequestMessage (msgIdWr.msgId, publisher, ppTargets);
                    }
                    if (rc == 0) {
                        checkAndLogMsg (pszMethodName, Logger::L_Info, "Requested request "
                                        "message with id: <%s>.\n", msgIdWr.msgId.c_str());
                    }
                    else {
                        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not request message with "
                                        "id = <%s> failed. Returned %d\n", msgIdWr.msgId.c_str(), rc);
                    }
                }
                Targets::deallocateTargets (ppTargets);
            }
        }

        doMetadataArrived (pMsgToNotify);
        delete pMsgToNotify;

        _m.lock();
        _bMessageRequested = false;
        int64 i64Tmp = _i64TimeStamp;
        _m.unlock();

        if ((getTimeInMilliseconds() - i64Tmp) > DSPro::DEFAULT_UPDATE_TIMEOUT) {

            if (_pNodeContexMgr->getActivePeerNumber() == 0) {
                continue;
            }

            bw.reset();
            int rc = _pNodeContexMgr->updatePosition (&bw);
            if (rc < 0) {
                checkAndLogMsg (pszMethodName, Logger::L_MildError, "Could not write "
                                "the way point message. Error code %d.\n", rc);
                continue;
            }

            _m.lock();
            _i64TimeStamp = getTimeInMilliseconds();
            _m.unlock();

            _pDSPro->sendWaypointMessage (bw.getBuffer(), bw.getBufferLength());
        }

        if (_pDSPro->_bEnableTopologyExchange && _bTopologyHasChanged) {
            _bTopologyHasChanged = false;
            BufferWriter bw (1024, 1024);
            if (_pDSPro->_pTopology->write (&bw, 0) == 0) {
                Targets **ppTargets = _pDSPro->_pTopology->getNeighborsAsTargets();
                if ((ppTargets != nullptr) && (ppTargets[0] != nullptr)) {
                    int rc = _pDSPro->_adaptMgr.sendTopologyReplyMessage (bw.getBuffer(), bw.getBufferLength(), ppTargets);
                    if (rc != 0) {
                        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not send "
                                        "topology reply message. Returned %d\n", rc);
                    }
                    else {
                        checkAndLogMsg (pszMethodName, Logger::L_Info,
                                        "sent topology reply.\n");
                    }
                }
                Targets::deallocateTargets (ppTargets);
            }
        }

    } while (!terminationRequested());

    terminating();
}